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