| 1 | /* |
|---|
| 2 | ----------------------------------------------------------------------------- |
|---|
| 3 | This source file is part of OGRE |
|---|
| 4 | (Object-oriented Graphics Rendering Engine) |
|---|
| 5 | For the latest info, see http://www.ogre3d.org/ |
|---|
| 6 | |
|---|
| 7 | Copyright (c) 2000-2013 Torus Knot Software Ltd |
|---|
| 8 | |
|---|
| 9 | Permission is hereby granted, free of charge, to any person obtaining a copy |
|---|
| 10 | of this software and associated documentation files (the "Software"), to deal |
|---|
| 11 | in the Software without restriction, including without limitation the rights |
|---|
| 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|---|
| 13 | copies of the Software, and to permit persons to whom the Software is |
|---|
| 14 | furnished to do so, subject to the following conditions: |
|---|
| 15 | |
|---|
| 16 | The above copyright notice and this permission notice shall be included in |
|---|
| 17 | all copies or substantial portions of the Software. |
|---|
| 18 | |
|---|
| 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|---|
| 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|---|
| 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|---|
| 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|---|
| 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|---|
| 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|---|
| 25 | THE SOFTWARE. |
|---|
| 26 | ----------------------------------------------------------------------------- |
|---|
| 27 | */ |
|---|
| 28 | |
|---|
| 29 | #ifndef __SimpleSpline_H__ |
|---|
| 30 | #define __SimpleSpline_H__ |
|---|
| 31 | |
|---|
| 32 | #include "OgrePrerequisites.h" |
|---|
| 33 | #include "OgreVector3.h" |
|---|
| 34 | #include "OgreMatrix4.h" |
|---|
| 35 | #include "OgreHeaderPrefix.h" |
|---|
| 36 | |
|---|
| 37 | namespace Ogre { |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | /** \addtogroup Core |
|---|
| 41 | * @{ |
|---|
| 42 | */ |
|---|
| 43 | /** \addtogroup Math |
|---|
| 44 | * @{ |
|---|
| 45 | */ |
|---|
| 46 | /** A very simple spline class which implements the Catmull-Rom class of splines. |
|---|
| 47 | @remarks |
|---|
| 48 | Splines are bendy lines. You define a series of points, and the spline forms |
|---|
| 49 | a smoother line between the points to eliminate the sharp angles. |
|---|
| 50 | @par |
|---|
| 51 | Catmull-Rom splines are a specialisation of the general Hermite spline. With |
|---|
| 52 | a Hermite spline, you define the start and end point of the line, and 2 tangents, |
|---|
| 53 | one at the start of the line and one at the end. The Catmull-Rom spline simplifies |
|---|
| 54 | this by just asking you to define a series of points, and the tangents are |
|---|
| 55 | created for you. |
|---|
| 56 | */ |
|---|
| 57 | class _OgreExport SimpleSpline |
|---|
| 58 | { |
|---|
| 59 | public: |
|---|
| 60 | SimpleSpline(); |
|---|
| 61 | ~SimpleSpline(); |
|---|
| 62 | |
|---|
| 63 | /** Adds a control point to the end of the spline. */ |
|---|
| 64 | void addPoint(const Vector3& p); |
|---|
| 65 | |
|---|
| 66 | /** Gets the detail of one of the control points of the spline. */ |
|---|
| 67 | const Vector3& getPoint(unsigned short index) const; |
|---|
| 68 | |
|---|
| 69 | /** Gets the number of control points in the spline. */ |
|---|
| 70 | unsigned short getNumPoints(void) const; |
|---|
| 71 | |
|---|
| 72 | /** Clears all the points in the spline. */ |
|---|
| 73 | void clear(void); |
|---|
| 74 | |
|---|
| 75 | /** Updates a single point in the spline. |
|---|
| 76 | @remarks |
|---|
| 77 | This point must already exist in the spline. |
|---|
| 78 | */ |
|---|
| 79 | void updatePoint(unsigned short index, const Vector3& value); |
|---|
| 80 | |
|---|
| 81 | /** Returns an interpolated point based on a parametric value over the whole series. |
|---|
| 82 | @remarks |
|---|
| 83 | Given a t value between 0 and 1 representing the parametric distance along the |
|---|
| 84 | whole length of the spline, this method returns an interpolated point. |
|---|
| 85 | @param t Parametric value. |
|---|
| 86 | */ |
|---|
| 87 | Vector3 interpolate(Real t) const; |
|---|
| 88 | |
|---|
| 89 | /** Interpolates a single segment of the spline given a parametric value. |
|---|
| 90 | @param fromIndex The point index to treat as t=0. fromIndex + 1 is deemed to be t=1 |
|---|
| 91 | @param t Parametric value |
|---|
| 92 | */ |
|---|
| 93 | Vector3 interpolate(unsigned int fromIndex, Real t) const; |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | /** Tells the spline whether it should automatically calculate tangents on demand |
|---|
| 97 | as points are added. |
|---|
| 98 | @remarks |
|---|
| 99 | The spline calculates tangents at each point automatically based on the input points. |
|---|
| 100 | Normally it does this every time a point changes. However, if you have a lot of points |
|---|
| 101 | to add in one go, you probably don't want to incur this overhead and would prefer to |
|---|
| 102 | defer the calculation until you are finished setting all the points. You can do this |
|---|
| 103 | by calling this method with a parameter of 'false'. Just remember to manually call |
|---|
| 104 | the recalcTangents method when you are done. |
|---|
| 105 | @param autoCalc If true, tangents are calculated for you whenever a point changes. If false, |
|---|
| 106 | you must call reclacTangents to recalculate them when it best suits. |
|---|
| 107 | */ |
|---|
| 108 | void setAutoCalculate(bool autoCalc); |
|---|
| 109 | |
|---|
| 110 | /** Recalculates the tangents associated with this spline. |
|---|
| 111 | @remarks |
|---|
| 112 | If you tell the spline not to update on demand by calling setAutoCalculate(false) |
|---|
| 113 | then you must call this after completing your updates to the spline points. |
|---|
| 114 | */ |
|---|
| 115 | void recalcTangents(void); |
|---|
| 116 | |
|---|
| 117 | protected: |
|---|
| 118 | |
|---|
| 119 | bool mAutoCalc; |
|---|
| 120 | |
|---|
| 121 | vector<Vector3>::type mPoints; |
|---|
| 122 | vector<Vector3>::type mTangents; |
|---|
| 123 | |
|---|
| 124 | /// Matrix of coefficients |
|---|
| 125 | Matrix4 mCoeffs; |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | }; |
|---|
| 130 | |
|---|
| 131 | /** @} */ |
|---|
| 132 | /** @} */ |
|---|
| 133 | |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | #include "OgreHeaderSuffix.h" |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | #endif |
|---|
| 140 | |
|---|