| [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" | 
|---|
 | 13 |  | 
|---|
| [5225] | 14 | template<class T> class tList; | 
|---|
 | 15 | template<class T> class tIterator; | 
|---|
 | 16 |  | 
|---|
| [3365] | 17 | //! An Enumerator that defines what sort of Curves are availible | 
|---|
| [5225] | 18 | enum CurveType { | 
|---|
 | 19 |   CURVE_BEZIER | 
|---|
 | 20 | }; | 
|---|
| [3018] | 21 |  | 
|---|
| [3365] | 22 |  | 
|---|
 | 23 | //! An abstract class to handle curves. Needed for the Tracking system in orxonox. | 
|---|
| [3019] | 24 | class Curve | 
|---|
| [3018] | 25 | { | 
|---|
| [3019] | 26 |  protected: | 
|---|
| [3217] | 27 |   //! Handles the curve-points (dynamic List) | 
|---|
| [3018] | 28 |   struct PathNode | 
|---|
 | 29 |   { | 
|---|
| [4472] | 30 |     int          number;       //!< The N-th node of this curve. | 
|---|
 | 31 |     float        factor;       //!< Curve specific multiplier factor. | 
|---|
 | 32 |     Vector       vFactor;      //!< A Vector-factor for multipliing. | 
|---|
 | 33 |     Vector       position;     //!< Vector Pointung to this curve-point. | 
|---|
 | 34 |     PathNode*    next;         //!< Pointer to the next Node. | 
|---|
| [3018] | 35 |   }; | 
|---|
 | 36 |  | 
|---|
| [3019] | 37 |  public: | 
|---|
| [4746] | 38 |   Curve(); | 
|---|
| [5231] | 39 |   virtual ~Curve(); | 
|---|
| [3588] | 40 |  | 
|---|
| [3365] | 41 |   void addNode(const Vector& newNode); | 
|---|
| [3433] | 42 |   void addNode(const Vector& newNode, unsigned int insertPosition); | 
|---|
| [3365] | 43 |   Vector getNode(unsigned int nodeToFind); | 
|---|
| [4836] | 44 |   /** @returns the count of nodes in this curve */ | 
|---|
| [4746] | 45 |   inline int getNodeCount() const { return this->nodeCount; }; | 
|---|
| [4836] | 46 |   /** @returns the directional Curve */ | 
|---|
| [4746] | 47 |   Curve* getDirCurve() const { return this->dirCurve; }; | 
|---|
| [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 |  | 
|---|
| [5225] | 73 |   tList<PathNode>*      nodeList;        //!< A list of all the Nodes of a Curve. | 
|---|
 | 74 |   tIterator<PathNode>*  nodeIterator;    //!< An iterator that should point to the current Node | 
|---|
 | 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 */ | 
|---|