Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: PNode and Element2D can now return their children-lists as const tList<type>*

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