Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10706 was 10618, checked in by bknecht, 18 years ago

merged cleanup into trunk (only improvements)

File size: 3.1 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 <list>
13#include "vector.h"
14#include "quaternion.h"
15
16//! An Enumerator that defines what sort of Curves are availible
17enum CurveType {
18  CURVE_BEZIER
19};
20
21
22//! An abstract class to handle curves. Needed for the Tracking system in orxonox.
23class Curve
24{
25 protected:
26  //! Handles the curve-points (dynamic List)
27  struct PathNode
28  {
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.
34  };
35
36 public:
37  Curve();
38  virtual ~Curve();
39
40  void addNode(const Vector& newNode);
41  void addNode(const Vector& newNode, unsigned int insertPosition);
42  Vector getNode(unsigned int nodeToFind);
43  /** @returns the count of nodes in this curve */
44  inline int getNodeCount() const { return this->nodeCount; };
45  /** @returns the directional Curve */
46  Curve* getDirCurve() const { return this->dirCurve; };
47  float getLength();
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  std::list<PathNode>   nodeList;        //!< A list of all the Nodes of a Curve.
74  PathNode*             firstNode;       //!< First node of the curve.
75  PathNode*             currentNode;     //!< The node we are working with (the Last node).
76
77};
78
79//!    Class to handle bezier curves in 3-dimesnsional space
80/**
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.
83*/
84class BezierCurve : public Curve
85{
86 public:
87  BezierCurve();
88  BezierCurve(int derivation);
89  virtual ~BezierCurve();
90
91  virtual Vector calcPos(float t);
92  virtual Vector calcDir(float t);
93  virtual Vector calcAcc(float t);
94  virtual Quaternion calcQuat(float t);
95
96
97  Vector getPos() const;
98
99 private:
100  void rebuild();
101};
102
103
104#endif /* _CURVE_H */
Note: See TracBrowser for help on using the repository browser.