[1] | 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-2006 Torus Knot Software Ltd |
---|
| 8 | Also see acknowledgements in Readme.html |
---|
| 9 | |
---|
| 10 | This program is free software; you can redistribute it and/or modify it under |
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
| 13 | version. |
---|
| 14 | |
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
| 18 | |
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
| 23 | |
---|
| 24 | You may alternatively use this source under the terms of a specific version of |
---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
| 26 | Torus Knot Software Ltd. |
---|
| 27 | ----------------------------------------------------------------------------- |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | #ifndef __SimpleSpline_H__ |
---|
| 31 | #define __SimpleSpline_H__ |
---|
| 32 | |
---|
| 33 | #include "OgrePrerequisites.h" |
---|
| 34 | #include "OgreVector3.h" |
---|
| 35 | #include "OgreMatrix4.h" |
---|
| 36 | |
---|
| 37 | namespace Ogre { |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | /** A very simple spline class which implements the Catmull-Rom class of splines. |
---|
| 41 | @remarks |
---|
| 42 | Splines are bendy lines. You define a series of points, and the spline forms |
---|
| 43 | a smoother line between the points to eliminate the sharp angles. |
---|
| 44 | @par |
---|
| 45 | Catmull-Rom splines are a specialisation of the general Hermite spline. With |
---|
| 46 | a Hermite spline, you define the start and end point of the line, and 2 tangents, |
---|
| 47 | one at the start of the line and one at the end. The Catmull-Rom spline simplifies |
---|
| 48 | this by just asking you to define a series of points, and the tangents are |
---|
| 49 | created for you. |
---|
| 50 | */ |
---|
| 51 | class _OgreExport SimpleSpline |
---|
| 52 | { |
---|
| 53 | public: |
---|
| 54 | SimpleSpline(); |
---|
| 55 | ~SimpleSpline(); |
---|
| 56 | |
---|
| 57 | /** Adds a control point to the end of the spline. */ |
---|
| 58 | void addPoint(const Vector3& p); |
---|
| 59 | |
---|
| 60 | /** Gets the detail of one of the control points of the spline. */ |
---|
| 61 | const Vector3& getPoint(unsigned short index) const; |
---|
| 62 | |
---|
| 63 | /** Gets the number of control points in the spline. */ |
---|
| 64 | unsigned short getNumPoints(void) const; |
---|
| 65 | |
---|
| 66 | /** Clears all the points in the spline. */ |
---|
| 67 | void clear(void); |
---|
| 68 | |
---|
| 69 | /** Updates a single point in the spline. |
---|
| 70 | @remarks |
---|
| 71 | This point must already exist in the spline. |
---|
| 72 | */ |
---|
| 73 | void updatePoint(unsigned short index, const Vector3& value); |
---|
| 74 | |
---|
| 75 | /** Returns an interpolated point based on a parametric value over the whole series. |
---|
| 76 | @remarks |
---|
| 77 | Given a t value between 0 and 1 representing the parametric distance along the |
---|
| 78 | whole length of the spline, this method returns an interpolated point. |
---|
| 79 | @param t Parametric value. |
---|
| 80 | */ |
---|
| 81 | Vector3 interpolate(Real t); |
---|
| 82 | |
---|
| 83 | /** Interpolates a single segment of the spline given a parametric value. |
---|
| 84 | @param fromIndex The point index to treat as t=0. fromIndex + 1 is deemed to be t=1 |
---|
| 85 | @param t Parametric value |
---|
| 86 | */ |
---|
| 87 | Vector3 interpolate(unsigned int fromIndex, Real t); |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | /** Tells the spline whether it should automatically calculate tangents on demand |
---|
| 91 | as points are added. |
---|
| 92 | @remarks |
---|
| 93 | The spline calculates tangents at each point automatically based on the input points. |
---|
| 94 | Normally it does this every time a point changes. However, if you have a lot of points |
---|
| 95 | to add in one go, you probably don't want to incur this overhead and would prefer to |
---|
| 96 | defer the calculation until you are finished setting all the points. You can do this |
---|
| 97 | by calling this method with a parameter of 'false'. Just remember to manually call |
---|
| 98 | the recalcTangents method when you are done. |
---|
| 99 | @param autoCalc If true, tangents are calculated for you whenever a point changes. If false, |
---|
| 100 | you must call reclacTangents to recalculate them when it best suits. |
---|
| 101 | */ |
---|
| 102 | void setAutoCalculate(bool autoCalc); |
---|
| 103 | |
---|
| 104 | /** Recalculates the tangents associated with this spline. |
---|
| 105 | @remarks |
---|
| 106 | If you tell the spline not to update on demand by calling setAutoCalculate(false) |
---|
| 107 | then you must call this after completing your updates to the spline points. |
---|
| 108 | */ |
---|
| 109 | void recalcTangents(void); |
---|
| 110 | |
---|
| 111 | protected: |
---|
| 112 | |
---|
| 113 | bool mAutoCalc; |
---|
| 114 | |
---|
| 115 | std::vector<Vector3> mPoints; |
---|
| 116 | std::vector<Vector3> mTangents; |
---|
| 117 | |
---|
| 118 | /// Matrix of coefficients |
---|
| 119 | Matrix4 mCoeffs; |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | }; |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | #endif |
---|
| 130 | |
---|