Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/math/curve.h @ 6310

Last change on this file since 6310 was 5231, checked in by patrick, 19 years ago

orxonox/trunk: hunted a valgrind error msg in the curve class, restructured the code to delete only local variables not external

File size: 3.3 KB
Line 
1
2/*!
3 * @file curve.h
4  *  A basic 3D curve framework
5
6    Contains classes to handle curves
7*/
8
9#ifndef _CURVE_H
10#define _CURVE_H
11
12#include "vector.h"
13
14template<class T> class tList;
15template<class T> class tIterator;
16
17//! An Enumerator that defines what sort of Curves are availible
18enum CurveType {
19  CURVE_BEZIER
20};
21
22
23//! An abstract class to handle curves. Needed for the Tracking system in orxonox.
24class Curve
25{
26 protected:
27  //! Handles the curve-points (dynamic List)
28  struct PathNode
29  {
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.
35  };
36
37 public:
38  Curve();
39  virtual ~Curve();
40
41  void addNode(const Vector& newNode);
42  void addNode(const Vector& newNode, unsigned int insertPosition);
43  Vector getNode(unsigned int nodeToFind);
44  /** @returns the count of nodes in this curve */
45  inline int getNodeCount() const { return this->nodeCount; };
46  /** @returns the directional Curve */
47  Curve* getDirCurve() const { return this->dirCurve; };
48
49  /** @param t the value on the curve [0-1] @returns Vector to the position */
50  virtual Vector calcPos(float t) = 0;
51  /** @param t the value on the curve [0-1] @returns the direction */
52  virtual Vector calcDir(float t) = 0;
53  /** @param t the value on the curve [0-1] @returns the acceleration */
54  virtual Vector calcAcc(float t) = 0;
55  /** @param t the value on the curve [0-1] @returns quaternion of the rotation */
56  virtual Quaternion calcQuat(float t) = 0;
57
58  // DEBUG
59  void debug();
60
61 private:
62  /** \brief rebuilds the curve */
63  virtual void rebuild() = 0;
64
65 protected:
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.
70
71  Curve*                dirCurve;        //!< The derivation-curve of this Curve.
72
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).
77
78};
79
80//!    Class to handle bezier curves in 3-dimesnsional space
81/**
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.
84*/
85class BezierCurve : public Curve
86{
87 public:
88  BezierCurve();
89  BezierCurve(int derivation);
90  virtual ~BezierCurve();
91
92  virtual Vector calcPos(float t);
93  virtual Vector calcDir(float t);
94  virtual Vector calcAcc(float t);
95  virtual Quaternion calcQuat(float t);
96
97
98  Vector getPos() const;
99
100 private:
101  void rebuild();
102};
103
104
105//! B-Spline
106/**
107   class to handle b-spline in 3d space
108*/
109class BSplieCurve : public Curve
110{
111
112
113};
114
115#endif /* _CURVE_H */
Note: See TracBrowser for help on using the repository browser.