[3365] | 1 | |
---|
[3018] | 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 | |
---|
[3365] | 14 | //! An Enumerator that defines what sort of Curves are availible |
---|
| 15 | enum CurveType {BEZIERCURVE, UPOINTCURVE}; |
---|
[3018] | 16 | |
---|
[3365] | 17 | |
---|
| 18 | //! An abstract class to handle curves. Needed for the Tracking system in orxonox. |
---|
[3517] | 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 | */ |
---|
[3019] | 36 | class Curve |
---|
[3018] | 37 | { |
---|
[3019] | 38 | protected: |
---|
[3217] | 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. |
---|
[3365] | 42 | int derivation; //!< Which derivation of a Curve is this. |
---|
[3019] | 43 | |
---|
[3217] | 44 | //! Handles the curve-points (dynamic List) |
---|
[3018] | 45 | struct PathNode |
---|
| 46 | { |
---|
[3217] | 47 | int number; //!< The N-th node of this curve. |
---|
[3365] | 48 | float factor; //!< Curve specific multiplier factor. |
---|
| 49 | Vector vFactor; //!< A Vector-factor for multipliing. |
---|
[3217] | 50 | Vector position; //!< Vector Pointung to this curve-point. |
---|
| 51 | PathNode* next; //!< Pointer to the next Node. |
---|
[3018] | 52 | }; |
---|
| 53 | |
---|
[3217] | 54 | PathNode* firstNode; //!< First node of the curve. |
---|
| 55 | PathNode* currentNode; //!< The node we are working with (the Last node). |
---|
[3018] | 56 | |
---|
[3365] | 57 | private: |
---|
[3517] | 58 | //! rebuilds the Curve with the right algorithm |
---|
[3365] | 59 | virtual void rebuild(void) = 0; |
---|
[3019] | 60 | public: |
---|
[3433] | 61 | Curve* dirCurve; //!< The derivation-curve of this Curve. |
---|
[3365] | 62 | void addNode(const Vector& newNode); |
---|
[3433] | 63 | void addNode(const Vector& newNode, unsigned int insertPosition); |
---|
[3365] | 64 | Vector getNode(unsigned int nodeToFind); |
---|
[3517] | 65 | /** \returns the Count of nodes of this Curve */ |
---|
[3365] | 66 | inline int getNodeCount(void) { return this->nodeCount;} |
---|
[3019] | 67 | |
---|
[3517] | 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 | */ |
---|
[3365] | 79 | virtual Vector calcDir(float t) = 0; |
---|
[3517] | 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 | */ |
---|
[3433] | 85 | virtual Vector calcAcc(float t) = 0; |
---|
[3517] | 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 | */ |
---|
[3365] | 91 | virtual Quaternion calcQuat(float t) = 0; |
---|
| 92 | |
---|
[3433] | 93 | // DEBUG |
---|
| 94 | void debug(void); |
---|
[3019] | 95 | }; |
---|
| 96 | |
---|
[3365] | 97 | //! Class to handle bezier curves in 3-dimesnsional space |
---|
[3019] | 98 | /** |
---|
[3365] | 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. |
---|
[3019] | 101 | */ |
---|
| 102 | class BezierCurve : public Curve |
---|
| 103 | { |
---|
| 104 | private: |
---|
[3365] | 105 | void rebuild(void); |
---|
[3018] | 106 | public: |
---|
[3365] | 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); |
---|
[3433] | 114 | Vector calcAcc(float t); |
---|
[3365] | 115 | Quaternion calcQuat(float t); |
---|
[3018] | 116 | |
---|
[3028] | 117 | |
---|
[3365] | 118 | Vector getPos(void) const; |
---|
[3018] | 119 | }; |
---|
| 120 | |
---|
| 121 | |
---|
[3365] | 122 | //! B-Spline |
---|
| 123 | /** |
---|
| 124 | class to handle b-spline in 3d space |
---|
| 125 | */ |
---|
| 126 | class BSplieCurve : public Curve |
---|
| 127 | { |
---|
[3018] | 128 | |
---|
[3365] | 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); |
---|
[3433] | 151 | Vector calcAcc(float t); |
---|
[3365] | 152 | Quaternion calcQuat(float t); |
---|
| 153 | |
---|
| 154 | Vector getPos(void) const; |
---|
| 155 | }; |
---|
| 156 | |
---|
[3018] | 157 | #endif /* _CURVE_H */ |
---|