1 | |
---|
2 | /*! |
---|
3 | \file curve.h |
---|
4 | \brief A basic 3D curve framework |
---|
5 | |
---|
6 | Contains classes to handle curves |
---|
7 | */ |
---|
8 | |
---|
9 | #ifndef _CURVE_H |
---|
10 | #define _CURVE_H |
---|
11 | |
---|
12 | #include "vector.h" |
---|
13 | |
---|
14 | //! An Enumerator that defines what sort of Curves are availible |
---|
15 | enum CurveType {BEZIERCURVE, UPOINTCURVE}; |
---|
16 | |
---|
17 | |
---|
18 | //! An abstract class to handle curves. Needed for the Tracking system in orxonox. |
---|
19 | /** |
---|
20 | A Curve is a smooth line which tries to approximate a path through the nodes given to it. |
---|
21 | <br> |
---|
22 | |
---|
23 | <b>Usage of Curves:</b><br> |
---|
24 | \li Creation: Curve* newCurve = new BezierCurve(); |
---|
25 | \li Adding some Points: newCurve->addNode([Vector to the point to add]); |
---|
26 | \li Get Point on Curve: newCurve->calcPos(timeIndex); // where timeindex is in the interval [0,1] |
---|
27 | <br> |
---|
28 | More Fuctionality is: |
---|
29 | \li debug(): outputs some info about this curve. |
---|
30 | \li getNode(i): returns a Vector to the n'th node of the Curve. |
---|
31 | \li getNodeCount(): returns the count of nodes. |
---|
32 | <br> |
---|
33 | General Info: |
---|
34 | \li Curves take rather much power to be created/altered, but are fast calculated at runtime. |
---|
35 | */ |
---|
36 | class Curve |
---|
37 | { |
---|
38 | protected: |
---|
39 | int nodeCount; //!< The count of nodes the Curve has. |
---|
40 | Vector curvePoint; //!< The point on the Cureve at a local Time. |
---|
41 | float localTime; //!< If the time of one point is asked more than once the programm will not calculate it again. |
---|
42 | int derivation; //!< Which derivation of a Curve is this. |
---|
43 | |
---|
44 | //! Handles the curve-points (dynamic List) |
---|
45 | struct PathNode |
---|
46 | { |
---|
47 | int number; //!< The N-th node of this curve. |
---|
48 | float factor; //!< Curve specific multiplier factor. |
---|
49 | Vector vFactor; //!< A Vector-factor for multipliing. |
---|
50 | Vector position; //!< Vector Pointung to this curve-point. |
---|
51 | PathNode* next; //!< Pointer to the next Node. |
---|
52 | }; |
---|
53 | |
---|
54 | PathNode* firstNode; //!< First node of the curve. |
---|
55 | PathNode* currentNode; //!< The node we are working with (the Last node). |
---|
56 | |
---|
57 | private: |
---|
58 | //! rebuilds the Curve with the right algorithm |
---|
59 | virtual void rebuild(void) = 0; |
---|
60 | public: |
---|
61 | Curve* dirCurve; //!< The derivation-curve of this Curve. |
---|
62 | void addNode(const Vector& newNode); |
---|
63 | void addNode(const Vector& newNode, unsigned int insertPosition); |
---|
64 | Vector getNode(unsigned int nodeToFind); |
---|
65 | /** \returns the Count of nodes of this Curve */ |
---|
66 | inline int getNodeCount(void) { return this->nodeCount;} |
---|
67 | |
---|
68 | /** |
---|
69 | \brief A virtual function to calculate the Position on the Curve |
---|
70 | \returns positionVector |
---|
71 | \param t the timeindex on this curve [0,1]f |
---|
72 | */ |
---|
73 | virtual Vector calcPos(float t) = 0; |
---|
74 | /** |
---|
75 | \brief A virtual function to calculate the Direction of the Curve |
---|
76 | \returns directionVector |
---|
77 | \param t the timeindex on this curve [0,1]f |
---|
78 | */ |
---|
79 | virtual Vector calcDir(float t) = 0; |
---|
80 | /** |
---|
81 | \brief A virtual function to calculate the acceleration on the Curve |
---|
82 | \returns accelerationVector |
---|
83 | \param t the timeindex on this curve [0,1]f |
---|
84 | */ |
---|
85 | virtual Vector calcAcc(float t) = 0; |
---|
86 | /** |
---|
87 | \brief A virtual function to calculate the Quaternion on the Curve |
---|
88 | \returns directional Quaternion |
---|
89 | \param t the timeindex on this curve [0,1]f |
---|
90 | */ |
---|
91 | virtual Quaternion calcQuat(float t) = 0; |
---|
92 | |
---|
93 | // DEBUG |
---|
94 | void debug(void); |
---|
95 | }; |
---|
96 | |
---|
97 | //! Class to handle bezier curves in 3-dimesnsional space |
---|
98 | /** |
---|
99 | This Curve is good, for Fast Interaction. If you want to change it during the game, go on. |
---|
100 | !!be aware!! BezierCurves only flow through their first and last Node. Their Tangents at those Points a directed to the second and second-last Point. |
---|
101 | */ |
---|
102 | class BezierCurve : public Curve |
---|
103 | { |
---|
104 | private: |
---|
105 | void rebuild(void); |
---|
106 | public: |
---|
107 | BezierCurve(void); |
---|
108 | BezierCurve(int derivation); |
---|
109 | ~BezierCurve(void); |
---|
110 | void init(void); |
---|
111 | |
---|
112 | Vector calcPos(float t); |
---|
113 | Vector calcDir(float t); |
---|
114 | Vector calcAcc(float t); |
---|
115 | Quaternion calcQuat(float t); |
---|
116 | |
---|
117 | |
---|
118 | Vector getPos(void) const; |
---|
119 | }; |
---|
120 | |
---|
121 | |
---|
122 | //! B-Spline |
---|
123 | /** |
---|
124 | class to handle b-spline in 3d space |
---|
125 | */ |
---|
126 | class BSplieCurve : public Curve |
---|
127 | { |
---|
128 | |
---|
129 | |
---|
130 | }; |
---|
131 | |
---|
132 | //! Uniform Point Curve-class |
---|
133 | /** |
---|
134 | A UPoint Curve is a A Curve, that flows through all the nodes given it. |
---|
135 | The Algorithm to buid the curve is rather slow, but Painting and tracing along the curve has high speed, so do not change this curve during the Game. |
---|
136 | |
---|
137 | This Curve is very erattic, so i do not recommend to use it. |
---|
138 | */ |
---|
139 | class UPointCurve : public Curve |
---|
140 | { |
---|
141 | private: |
---|
142 | void rebuild(void); |
---|
143 | public: |
---|
144 | UPointCurve(void); |
---|
145 | UPointCurve(int derivation); |
---|
146 | ~UPointCurve(void); |
---|
147 | void init(void); |
---|
148 | |
---|
149 | Vector calcPos(float t); |
---|
150 | Vector calcDir(float t); |
---|
151 | Vector calcAcc(float t); |
---|
152 | Quaternion calcQuat(float t); |
---|
153 | |
---|
154 | Vector getPos(void) const; |
---|
155 | }; |
---|
156 | |
---|
157 | #endif /* _CURVE_H */ |
---|