[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 | |
---|
[10618] | 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 | |
---|
[10618] | 73 | std::list<PathNode> nodeList; //!< A list of all the Nodes of a Curve. |
---|
[5225] | 74 | PathNode* firstNode; //!< First node of the curve. |
---|
| 75 | PathNode* currentNode; //!< The node we are working with (the Last node). |
---|
[4472] | 76 | |
---|
[3019] | 77 | }; |
---|
| 78 | |
---|
[3365] | 79 | //! Class to handle bezier curves in 3-dimesnsional space |
---|
[3019] | 80 | /** |
---|
[3365] | 81 | This Curve is good, for Fast Interaction. If you want to change it during the game, go on. |
---|
| 82 | !!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] | 83 | */ |
---|
| 84 | class BezierCurve : public Curve |
---|
| 85 | { |
---|
[3018] | 86 | public: |
---|
[4746] | 87 | BezierCurve(); |
---|
[3365] | 88 | BezierCurve(int derivation); |
---|
[4746] | 89 | virtual ~BezierCurve(); |
---|
[3365] | 90 | |
---|
[4472] | 91 | virtual Vector calcPos(float t); |
---|
| 92 | virtual Vector calcDir(float t); |
---|
| 93 | virtual Vector calcAcc(float t); |
---|
| 94 | virtual Quaternion calcQuat(float t); |
---|
[4597] | 95 | |
---|
| 96 | |
---|
[4746] | 97 | Vector getPos() const; |
---|
[4472] | 98 | |
---|
| 99 | private: |
---|
[4746] | 100 | void rebuild(); |
---|
[3018] | 101 | }; |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | #endif /* _CURVE_H */ |
---|