Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/coord/p_node.h @ 5414

Last change on this file since 5414 was 5414, checked in by bensch, 19 years ago

orxonox/trunk: new functionality in PNode and Element2D
they now support setAbsCoordSofy*
and setAbsDirSoft*

these functions are used in the new Turret, for smooth iteration, so it does not just snap to place

File size: 7.5 KB
Line 
1/*!
2 * @file p_node.h
3 * @brief  Definition of a parenting node
4 *
5 *  parenting is how coordinates are handled in orxonox, meaning, that all coordinates
6 *  are representet relative to another parent node. this nodes build a parenting
7 *  tree of one-sided references (from up to down referenced).
8 *  Every node manages itself a list of childrens (of whos it is parent - easy...).
9 *
10 *  absCoordinate, absDirection have to be recalculated as soon as there was a change in
11 *  place or ortientation. this is only the case if
12 *  o bDirChanged is true (so changed) AND timeStamp != now
13 *  o bCoorChanged is true (so moved) AND timeStamp != now
14 *  this conditions make it cheaper to recalculate the tree (reduces redundant work).
15 */
16
17
18#ifndef _P_NODE_H
19#define _P_NODE_H
20
21#include "base_object.h"
22#include "vector.h"
23
24// FORWARD DECLARATION
25class TiXmlElement;
26template<class T> class tList;
27
28#define PNODE_ITERATION_DELTA    .001
29//! Parental linkage modes
30typedef enum
31{
32  PNODE_LOCAL_ROTATE          =   1,    //!< Rotates all the children around their centers.
33  PNODE_ROTATE_MOVEMENT       =   2,    //!< Moves all the children around the center of their parent, without the rotation around their own centers.
34
35  PNODE_MOVEMENT              =   4,    //!< Moves all children along with the parent.
36// special linkage modes
37  PNODE_ALL                   =   3,    //!< Moves all children around the center of their parent, and also rotates their centers
38  PNODE_ROTATE_AND_MOVE       =   5     //!< Rotates all children around their axis, and moves them as the Parent Moves, but does not rotate around the center of their parent.
39
40} PARENT_MODE;
41
42//! The default mode of the translation-binding.
43#define PNODE_PARENT_MODE_DEFAULT PNODE_ALL
44
45
46//! Patent Node is a Engine to calculate the position of an Object in respect to the position of its parent.
47class PNode : virtual public BaseObject {
48
49 public:
50  PNode ();
51  PNode(const TiXmlElement* root);
52  PNode (const Vector& absCoor, PNode* pNode);
53  virtual ~PNode ();
54
55  void loadParams(const TiXmlElement* root);
56
57  void setRelCoor (const Vector& relCoord);
58  void setRelCoor (float x, float y, float z);
59  void setRelCoorSoft(const Vector& relCoordSoft, float bias = 1.0);
60  void setRelCoorSoft(float x, float y, float z, float bias = 1.0);
61  /** @returns the relative position */
62  inline const Vector& getRelCoor () const { return this->prevRelCoordinate; };
63  /** @returns the Relative Coordinate Destination */
64  inline const Vector& getRelCoorSoft2D() const { return (this->toCoordinate)?*this->toCoordinate:this->relCoordinate; };
65  void setAbsCoor (const Vector& absCoord);
66  void setAbsCoor (float x, float y, float z);
67  void setAbsCoorSoft(const Vector& absCoordSoft, float bias = 1.0);
68  void setAbsCoorSoft(float x, float y, float z, float bias = 1.0);
69  /** @returns the absolute position */
70  inline const Vector& getAbsCoor () const { return this->absCoordinate; };
71  void shiftCoor (const Vector& shift);
72
73  void setRelDir (const Quaternion& relDir);
74  void setRelDir (float x, float y, float z);
75  void setRelDirSoft(const Quaternion& relDirSoft, float bias = 1.0);
76  void setRelDirSoft(float x, float y, float z, float bias = 1.0);
77  /** @returns the relative Direction */
78  inline const Quaternion& getRelDir () const { return this->prevRelDirection; };
79  /** @returns the Relative Directional Destination */
80  inline const Quaternion& getRelDirSoft2D() const { return (this->toDirection)?*this->toDirection:this->relDirection; };
81  /** @returns a Vector pointing into the relative Direction */
82  inline Vector getRelDirV() const { return this->prevRelDirection.apply(Vector(0,1,0)); };
83  void setAbsDir (const Quaternion& absDir);
84  void setAbsDir (float x, float y, float z);
85  void setAbsDirSoft(const Quaternion& absDirSoft, float bias = 1.0);
86  void setAbsDirSoft(float x, float y, float z, float bias = 1.0);
87  /** @returns the absolute Direction */
88  inline const Quaternion& getAbsDir () const { return this->absDirection; };
89  /** @returns a Vector pointing into the absolute Direction */
90  inline Vector getAbsDirV() const { return this->absDirection.apply(Vector(0,1,0)); };
91  void shiftDir (const Quaternion& shift);
92
93  /** @returns the Speed of the Node */
94  inline float getSpeed() const { return this->velocity.len(); };
95  /** @returns the Velocity of the Node */
96  inline const Vector& getVelocity() const { return this->velocity; };
97
98
99  void addChild (PNode* child);
100  void addChild (const char* childName);
101  void removeChild (PNode* child);
102  void remove();
103
104  void setParent (PNode* parent);
105  void setParent (const char* parentName);
106  /** @returns the parent of this PNode */
107  inline PNode* getParent () const { return this->parent; };
108  /** @returns the List of Children of this PNode */
109  inline const tList<PNode>* getChildren() const { return this->children; };
110
111  void setParentSoft(PNode* parentNode, float bias = 1.0);
112  void setParentSoft(const char* parentName, float bias = 1.0);
113
114  /** @param parentMode sets the parentingMode of this Node */
115  void setParentMode (PARENT_MODE parentMode) { this->parentMode = parentMode; };
116  void setParentMode (const char* parentingMode);
117  /** @returns the Parenting mode of this node */
118  int getParentMode() const { return this->parentMode; };
119
120  void update (float dt);
121
122  void debug (unsigned int depth = 1, unsigned int level = 0) const;
123  void debugDraw(unsigned int depth = 1, float size = 1.0, const Vector& color = Vector(1, 0, 0), unsigned int level = 0) const;
124
125
126  // helper functions //
127  static const char* parentingModeToChar(int parentingMode);
128  static PARENT_MODE charToParentingMode(const char* parentingMode);
129 private:
130  void init(PNode* parent);
131  /** tells the child that the parent's Coordinate has changed */
132  inline void parentCoorChanged () { this->bRelCoorChanged = true; }
133  /** tells the child that the parent's Direction has changed */
134  inline void parentDirChanged () { this->bRelDirChanged = true; }
135  /** @returns the last calculated coordinate */
136  inline Vector getLastAbsCoor() { return this->lastAbsCoordinate; }
137
138
139 private:
140  bool            bRelCoorChanged;    //!< If Relative Coordinate has changed since last time we checked
141  bool            bRelDirChanged;     //!< If Relative Direction has changed since last time we checked
142
143  Vector          relCoordinate;      //!< coordinates relative to the parent
144  Vector          absCoordinate;      //!< absolute coordinates in the world ( from (0,0,0) )
145  Quaternion      relDirection;       //!< direction relative to the parent
146  Quaternion      absDirection;       //!< absolute direvtion in the world ( from (0,0,1) )
147
148  Vector          prevRelCoordinate;  //!< The last Relative Coordinate from the last update-Cycle.
149  Vector          lastAbsCoordinate;  //!< this is used for speedcalculation, it stores the last coordinate
150  Quaternion      prevRelDirection;   //!< The last Relative Direciton from the last update-Cycle.
151//  Quaternion      lastAbsDirection;
152
153  Vector          velocity;           //!< Saves the velocity.
154
155  Vector*         toCoordinate;       //!< a position to which to iterate. (This is used in conjunction with setParentSoft.and set*CoorSoft)
156  Quaternion*     toDirection;        //!< a direction to which to iterate. (This is used in conjunction with setParentSoft and set*DirSoft)
157  float           bias;               //!< how fast to iterate to the given position (default is 1)
158
159  PNode*          parent;             //!< a pointer to the parent node
160  tList<PNode>*   children;           //!< list of the children of this PNode
161
162  unsigned int    parentMode;         //!< the mode of the binding
163};
164
165#endif /* _P_NODE_H */
166
Note: See TracBrowser for help on using the repository browser.