Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: smooth-rotation is better now
PNODE_MOVEMENT_ROTATE-children are correcly smooth-reparented
some other minor fixes

THIS IS 5000 :)
so
generated the endOfTheWorld-function
implemented de-generic recapitualisation Procedures
imported magnificizer
dezentralized obscurities
some other minor stuff
flush
eliminated deamons

man… i must have to much time

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