source: GTP/trunk/App/Demos/Geom/include/OgreRotationalSpline.h @ 1030

Revision 1030, 5.3 KB checked in by gumbau, 18 years ago (diff)

Ogre Stuff initial import

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#ifndef __RotationalSpline_H__
26#define __RotationalSpline_H__
27
28#include "OgrePrerequisites.h"
29#include "OgreQuaternion.h"
30
31namespace Ogre {
32
33    /** This class interpolates orientations (rotations) along a spline using
34        derivatives of quaternions.
35    @remarks
36        Like the SimpleSpline class, this class is about interpolating values
37        smoothly over a spline. Whilst SimpleSpline deals with positions (the normal
38        sense we think about splines), this class interpolates orientations. The
39        theory is identical, except we're now in 4-dimensional space instead of 3.
40    @par
41        In positional splines, we use the points and tangents on those points to generate
42        control points for the spline. In this case, we use quaternions and derivatives
43        of the quaternions (i.e. the rate and direction of change at each point). This is the
44        same as SimpleSpline since a tangent is a derivative of a position. We effectively
45        generate an extra quaternion in between each actual quaternion which when take with
46        the original quaternion forms the 'tangent' of that quaternion.
47    */
48    class _OgreExport RotationalSpline
49    {
50    public:
51        RotationalSpline();
52        ~RotationalSpline();
53
54        /** Adds a control point to the end of the spline. */
55        void addPoint(const Quaternion& p);
56
57        /** Gets the detail of one of the control points of the spline. */
58        const Quaternion& getPoint(unsigned short index) const;
59
60        /** Gets the number of control points in the spline. */
61        unsigned short getNumPoints(void) const;
62
63        /** Clears all the points in the spline. */
64        void clear(void);
65
66        /** Updates a single point in the spline.
67        @remarks
68            This point must already exist in the spline.
69        */
70        void updatePoint(unsigned short index, const Quaternion& value);
71
72        /** Returns an interpolated point based on a parametric value over the whole series.
73        @remarks
74            Given a t value between 0 and 1 representing the parametric distance along the
75            whole length of the spline, this method returns an interpolated point.
76        @param t Parametric value.
77                @param useShortestPath Defines if rotation should take the shortest possible path
78        */
79        Quaternion interpolate(Real t, bool useShortestPath=true);
80
81        /** Interpolates a single segment of the spline given a parametric value.
82        @param fromIndex The point index to treat as t=0. fromIndex + 1 is deemed to be t=1
83        @param t Parametric value
84                @param useShortestPath Defines if rotation should take the shortest possible path
85        */
86        Quaternion interpolate(unsigned int fromIndex, Real t, bool useShortestPath=true);
87
88        /** Tells the spline whether it should automatically calculate tangents on demand
89            as points are added.
90        @remarks
91            The spline calculates tangents at each point automatically based on the input points.
92            Normally it does this every time a point changes. However, if you have a lot of points
93            to add in one go, you probably don't want to incur this overhead and would prefer to
94            defer the calculation until you are finished setting all the points. You can do this
95            by calling this method with a parameter of 'false'. Just remember to manually call
96            the recalcTangents method when you are done.
97        @param autoCalc If true, tangents are calculated for you whenever a point changes. If false,
98            you must call reclacTangents to recalculate them when it best suits.
99        */
100        void setAutoCalculate(bool autoCalc);
101
102        /** Recalculates the tangents associated with this spline.
103        @remarks
104            If you tell the spline not to update on demand by calling setAutoCalculate(false)
105            then you must call this after completing your updates to the spline points.
106        */
107        void recalcTangents(void);
108
109    protected:
110
111        bool mAutoCalc;
112
113
114
115        std::vector<Quaternion> mPoints;
116        std::vector<Quaternion> mTangents;
117
118    };
119
120
121}
122
123
124#endif
125
Note: See TracBrowser for help on using the repository browser.