source: GTP/trunk/App/Demos/Geom/OgreStuff/include/OgreSimpleSpline.h @ 1812

Revision 1812, 4.8 KB checked in by gumbau, 18 years ago (diff)
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
26#ifndef __SimpleSpline_H__
27#define __SimpleSpline_H__
28
29#include "OgrePrerequisites.h"
30#include "OgreVector3.h"
31#include "OgreMatrix4.h"
32
33namespace Ogre {
34
35
36    /** A very simple spline class which implements the Catmull-Rom class of splines.
37    @remarks
38        Splines are bendy lines. You define a series of points, and the spline forms
39        a smoother line between the points to eliminate the sharp angles.
40    @par
41        Catmull-Rom splines are a specialisation of the general Hermite spline. With
42        a Hermite spline, you define the start and end point of the line, and 2 tangents,
43        one at the start of the line and one at the end. The Catmull-Rom spline simplifies
44        this by just asking you to define a series of points, and the tangents are
45        created for you.
46    */
47    class _OgreExport SimpleSpline
48    {
49    public:
50        SimpleSpline();
51        ~SimpleSpline();
52
53        /** Adds a control point to the end of the spline. */
54        void addPoint(const Vector3& p);
55
56        /** Gets the detail of one of the control points of the spline. */
57        const Vector3& getPoint(unsigned short index) const;
58
59        /** Gets the number of control points in the spline. */
60        unsigned short getNumPoints(void) const;
61
62        /** Clears all the points in the spline. */
63        void clear(void);
64
65        /** Updates a single point in the spline.
66        @remarks
67            This point must already exist in the spline.
68        */
69        void updatePoint(unsigned short index, const Vector3& value);
70
71        /** Returns an interpolated point based on a parametric value over the whole series.
72        @remarks
73            Given a t value between 0 and 1 representing the parametric distance along the
74            whole length of the spline, this method returns an interpolated point.
75        @param t Parametric value.
76        */
77        Vector3 interpolate(Real t);
78
79        /** Interpolates a single segment of the spline given a parametric value.
80        @param fromIndex The point index to treat as t=0. fromIndex + 1 is deemed to be t=1
81        @param t Parametric value
82        */
83        Vector3 interpolate(unsigned int fromIndex, Real t);
84
85
86        /** Tells the spline whether it should automatically calculate tangents on demand
87            as points are added.
88        @remarks
89            The spline calculates tangents at each point automatically based on the input points.
90            Normally it does this every time a point changes. However, if you have a lot of points
91            to add in one go, you probably don't want to incur this overhead and would prefer to
92            defer the calculation until you are finished setting all the points. You can do this
93            by calling this method with a parameter of 'false'. Just remember to manually call
94            the recalcTangents method when you are done.
95        @param autoCalc If true, tangents are calculated for you whenever a point changes. If false,
96            you must call reclacTangents to recalculate them when it best suits.
97        */
98        void setAutoCalculate(bool autoCalc);
99
100        /** Recalculates the tangents associated with this spline.
101        @remarks
102            If you tell the spline not to update on demand by calling setAutoCalculate(false)
103            then you must call this after completing your updates to the spline points.
104        */
105        void recalcTangents(void);
106
107    protected:
108
109        bool mAutoCalc;
110
111        std::vector<Vector3> mPoints;
112        std::vector<Vector3> mTangents;
113
114        /// Matrix of coefficients
115        Matrix4 mCoeffs;
116
117
118
119    };
120
121
122}
123
124
125#endif
126
Note: See TracBrowser for help on using the repository browser.