[3365] | 1 | |
---|
[4597] | 2 | /*! |
---|
[5039] | 3 | * @file curve.h |
---|
[4836] | 4 | * A basic 3D curve framework |
---|
[4597] | 5 | |
---|
[3018] | 6 | Contains classes to handle curves |
---|
[4597] | 7 | */ |
---|
[3018] | 8 | |
---|
| 9 | #ifndef _CURVE_H |
---|
| 10 | #define _CURVE_H |
---|
| 11 | |
---|
| 12 | #include "vector.h" |
---|
[6616] | 13 | #include "quaternion.h" |
---|
[3018] | 14 | |
---|
[5225] | 15 | template<class T> class tList; |
---|
| 16 | template<class T> class tIterator; |
---|
| 17 | |
---|
[3365] | 18 | //! An Enumerator that defines what sort of Curves are availible |
---|
[5225] | 19 | enum CurveType { |
---|
| 20 | CURVE_BEZIER |
---|
| 21 | }; |
---|
[3018] | 22 | |
---|
[3365] | 23 | |
---|
| 24 | //! An abstract class to handle curves. Needed for the Tracking system in orxonox. |
---|
[3019] | 25 | class Curve |
---|
[3018] | 26 | { |
---|
[3019] | 27 | protected: |
---|
[3217] | 28 | //! Handles the curve-points (dynamic List) |
---|
[3018] | 29 | struct PathNode |
---|
| 30 | { |
---|
[4472] | 31 | int number; //!< The N-th node of this curve. |
---|
| 32 | float factor; //!< Curve specific multiplier factor. |
---|
| 33 | Vector vFactor; //!< A Vector-factor for multipliing. |
---|
| 34 | Vector position; //!< Vector Pointung to this curve-point. |
---|
| 35 | PathNode* next; //!< Pointer to the next Node. |
---|
[3018] | 36 | }; |
---|
| 37 | |
---|
[3019] | 38 | public: |
---|
[4746] | 39 | Curve(); |
---|
[5231] | 40 | virtual ~Curve(); |
---|
[3588] | 41 | |
---|
[3365] | 42 | void addNode(const Vector& newNode); |
---|
[3433] | 43 | void addNode(const Vector& newNode, unsigned int insertPosition); |
---|
[3365] | 44 | Vector getNode(unsigned int nodeToFind); |
---|
[4836] | 45 | /** @returns the count of nodes in this curve */ |
---|
[4746] | 46 | inline int getNodeCount() const { return this->nodeCount; }; |
---|
[4836] | 47 | /** @returns the directional Curve */ |
---|
[4746] | 48 | Curve* getDirCurve() const { return this->dirCurve; }; |
---|
[3019] | 49 | |
---|
[4836] | 50 | /** @param t the value on the curve [0-1] @returns Vector to the position */ |
---|
[3365] | 51 | virtual Vector calcPos(float t) = 0; |
---|
[4836] | 52 | /** @param t the value on the curve [0-1] @returns the direction */ |
---|
[3365] | 53 | virtual Vector calcDir(float t) = 0; |
---|
[4836] | 54 | /** @param t the value on the curve [0-1] @returns the acceleration */ |
---|
[3433] | 55 | virtual Vector calcAcc(float t) = 0; |
---|
[4836] | 56 | /** @param t the value on the curve [0-1] @returns quaternion of the rotation */ |
---|
[3365] | 57 | virtual Quaternion calcQuat(float t) = 0; |
---|
[4597] | 58 | |
---|
[3433] | 59 | // DEBUG |
---|
[4746] | 60 | void debug(); |
---|
[4472] | 61 | |
---|
| 62 | private: |
---|
| 63 | /** \brief rebuilds the curve */ |
---|
[4746] | 64 | virtual void rebuild() = 0; |
---|
[4472] | 65 | |
---|
| 66 | protected: |
---|
[5225] | 67 | int nodeCount; //!< The count of nodes the Curve has. |
---|
| 68 | Vector curvePoint; //!< The point on the Cureve at a local Time. |
---|
| 69 | float localTime; //!< If the time of one point is asked more than once the programm will not calculate it again. |
---|
| 70 | int derivation; //!< Which derivation of a Curve is this. |
---|
[4472] | 71 | |
---|
[5225] | 72 | Curve* dirCurve; //!< The derivation-curve of this Curve. |
---|
[4472] | 73 | |
---|
[5225] | 74 | tList<PathNode>* nodeList; //!< A list of all the Nodes of a Curve. |
---|
| 75 | tIterator<PathNode>* nodeIterator; //!< An iterator that should point to the current Node |
---|
| 76 | PathNode* firstNode; //!< First node of the curve. |
---|
| 77 | PathNode* currentNode; //!< The node we are working with (the Last node). |
---|
[4472] | 78 | |
---|
[3019] | 79 | }; |
---|
| 80 | |
---|
[3365] | 81 | //! Class to handle bezier curves in 3-dimesnsional space |
---|
[3019] | 82 | /** |
---|
[3365] | 83 | This Curve is good, for Fast Interaction. If you want to change it during the game, go on. |
---|
| 84 | !!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] | 85 | */ |
---|
| 86 | class BezierCurve : public Curve |
---|
| 87 | { |
---|
[3018] | 88 | public: |
---|
[4746] | 89 | BezierCurve(); |
---|
[3365] | 90 | BezierCurve(int derivation); |
---|
[4746] | 91 | virtual ~BezierCurve(); |
---|
[3365] | 92 | |
---|
[4472] | 93 | virtual Vector calcPos(float t); |
---|
| 94 | virtual Vector calcDir(float t); |
---|
| 95 | virtual Vector calcAcc(float t); |
---|
| 96 | virtual Quaternion calcQuat(float t); |
---|
[4597] | 97 | |
---|
| 98 | |
---|
[4746] | 99 | Vector getPos() const; |
---|
[4472] | 100 | |
---|
| 101 | private: |
---|
[4746] | 102 | void rebuild(); |
---|
[3018] | 103 | }; |
---|
| 104 | |
---|
| 105 | |
---|
[3365] | 106 | //! B-Spline |
---|
| 107 | /** |
---|
| 108 | class to handle b-spline in 3d space |
---|
| 109 | */ |
---|
| 110 | class BSplieCurve : public Curve |
---|
| 111 | { |
---|
[3018] | 112 | |
---|
[3365] | 113 | |
---|
| 114 | }; |
---|
| 115 | |
---|
[3018] | 116 | #endif /* _CURVE_H */ |
---|