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