[148] | 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 | #ifndef __RotationalSpline_H__ |
---|
| 29 | #define __RotationalSpline_H__ |
---|
| 30 | |
---|
| 31 | #include "OgrePrerequisites.h" |
---|
| 32 | #include "OgreQuaternion.h" |
---|
| 33 | #include "OgreHeaderPrefix.h" |
---|
| 34 | |
---|
| 35 | namespace Ogre { |
---|
| 36 | |
---|
| 37 | /** \addtogroup Core |
---|
| 38 | * @{ |
---|
| 39 | */ |
---|
| 40 | /** \addtogroup Math |
---|
| 41 | * @{ |
---|
| 42 | */ |
---|
| 43 | /** This class interpolates orientations (rotations) along a spline using |
---|
| 44 | derivatives of quaternions. |
---|
| 45 | @remarks |
---|
| 46 | Like the SimpleSpline class, this class is about interpolating values |
---|
| 47 | smoothly over a spline. Whilst SimpleSpline deals with positions (the normal |
---|
| 48 | sense we think about splines), this class interpolates orientations. The |
---|
| 49 | theory is identical, except we're now in 4-dimensional space instead of 3. |
---|
| 50 | @par |
---|
| 51 | In positional splines, we use the points and tangents on those points to generate |
---|
| 52 | control points for the spline. In this case, we use quaternions and derivatives |
---|
| 53 | of the quaternions (i.e. the rate and direction of change at each point). This is the |
---|
| 54 | same as SimpleSpline since a tangent is a derivative of a position. We effectively |
---|
| 55 | generate an extra quaternion in between each actual quaternion which when take with |
---|
| 56 | the original quaternion forms the 'tangent' of that quaternion. |
---|
| 57 | */ |
---|
| 58 | class _OgreExport RotationalSpline |
---|
| 59 | { |
---|
| 60 | public: |
---|
| 61 | RotationalSpline(); |
---|
| 62 | ~RotationalSpline(); |
---|
| 63 | |
---|
| 64 | /** Adds a control point to the end of the spline. */ |
---|
| 65 | void addPoint(const Quaternion& p); |
---|
| 66 | |
---|
| 67 | /** Gets the detail of one of the control points of the spline. */ |
---|
| 68 | const Quaternion& getPoint(unsigned short index) const; |
---|
| 69 | |
---|
| 70 | /** Gets the number of control points in the spline. */ |
---|
| 71 | unsigned short getNumPoints(void) const; |
---|
| 72 | |
---|
| 73 | /** Clears all the points in the spline. */ |
---|
| 74 | void clear(void); |
---|
| 75 | |
---|
| 76 | /** Updates a single point in the spline. |
---|
| 77 | @remarks |
---|
| 78 | This point must already exist in the spline. |
---|
| 79 | */ |
---|
| 80 | void updatePoint(unsigned short index, const Quaternion& value); |
---|
| 81 | |
---|
| 82 | /** Returns an interpolated point based on a parametric value over the whole series. |
---|
| 83 | @remarks |
---|
| 84 | Given a t value between 0 and 1 representing the parametric distance along the |
---|
| 85 | whole length of the spline, this method returns an interpolated point. |
---|
| 86 | @param t Parametric value. |
---|
| 87 | @param useShortestPath Defines if rotation should take the shortest possible path |
---|
| 88 | */ |
---|
| 89 | Quaternion interpolate(Real t, bool useShortestPath=true); |
---|
| 90 | |
---|
| 91 | /** Interpolates a single segment of the spline given a parametric value. |
---|
| 92 | @param fromIndex The point index to treat as t=0. fromIndex + 1 is deemed to be t=1 |
---|
| 93 | @param t Parametric value |
---|
| 94 | @param useShortestPath Defines if rotation should take the shortest possible path |
---|
| 95 | */ |
---|
| 96 | Quaternion interpolate(unsigned int fromIndex, Real t, bool useShortestPath=true); |
---|
| 97 | |
---|
| 98 | /** Tells the spline whether it should automatically calculate tangents on demand |
---|
| 99 | as points are added. |
---|
| 100 | @remarks |
---|
| 101 | The spline calculates tangents at each point automatically based on the input points. |
---|
| 102 | Normally it does this every time a point changes. However, if you have a lot of points |
---|
| 103 | to add in one go, you probably don't want to incur this overhead and would prefer to |
---|
| 104 | defer the calculation until you are finished setting all the points. You can do this |
---|
| 105 | by calling this method with a parameter of 'false'. Just remember to manually call |
---|
| 106 | the recalcTangents method when you are done. |
---|
| 107 | @param autoCalc If true, tangents are calculated for you whenever a point changes. If false, |
---|
| 108 | you must call reclacTangents to recalculate them when it best suits. |
---|
| 109 | */ |
---|
| 110 | void setAutoCalculate(bool autoCalc); |
---|
| 111 | |
---|
| 112 | /** Recalculates the tangents associated with this spline. |
---|
| 113 | @remarks |
---|
| 114 | If you tell the spline not to update on demand by calling setAutoCalculate(false) |
---|
| 115 | then you must call this after completing your updates to the spline points. |
---|
| 116 | */ |
---|
| 117 | void recalcTangents(void); |
---|
| 118 | |
---|
| 119 | protected: |
---|
| 120 | |
---|
| 121 | bool mAutoCalc; |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | vector<Quaternion>::type mPoints; |
---|
| 126 | vector<Quaternion>::type mTangents; |
---|
| 127 | |
---|
| 128 | }; |
---|
| 129 | |
---|
| 130 | /** @} */ |
---|
| 131 | /** @} */ |
---|
| 132 | |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | #include "OgreHeaderSuffix.h" |
---|
| 136 | |
---|
| 137 | #endif |
---|
| 138 | |
---|