Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5769 was 5769, checked in by bensch, 18 years ago

orxonox/trunk: sync

File size: 8.2 KB
RevLine 
[4570]1/*!
[5391]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 */
[3246]16
17
18#ifndef _P_NODE_H
19#define _P_NODE_H
20
[3543]21#include "base_object.h"
[3804]22#include "vector.h"
[3246]23
[5405]24// FORWARD DECLARATION
[4436]25class TiXmlElement;
[3607]26template<class T> class tList;
[3246]27
[5006]28#define PNODE_ITERATION_DELTA    .001
[4765]29//! Parental linkage modes
30typedef enum
31{
[5769]32  // PARENTAL FOLLOWING
33  PNODE_LOCAL_ROTATE                   = 0x00000001,    //!< Rotates all the children around their centers.
34  PNODE_ROTATE_MOVEMENT                = 0x00000002,    //!< Moves all the children around the center of their parent, without the rotation around their own centers.
[4765]35
[5769]36  PNODE_MOVEMENT                       = 0x00000004,    //!< Moves all children along with the parent.
[3565]37// special linkage modes
[5769]38  PNODE_ALL                            = 0x00000003,    //!< Moves all children around the center of their parent, and also rotates their centers
39  PNODE_ROTATE_AND_MOVE                = 0x00000005,    //!< Rotates all children around their axis, and moves them as the Parent Moves, but does not rotate around the center of their parent.
[3565]40
[5769]41
42  PNODE_INACTIVE_NODE                  = 0x00000010,    //!< If the node is Active (if not, it and its child wont be updated).
43
44  // REPARENTING
45  PNODE_REPARENT_TO_NULLPARENT         = 0x00000100,
46  PNODE_REPARENT_KEEP_POSITION         = 0x00000200,
47
48
49  // DELETION
50  PNODE_PROHIBIT_CHILD_DELETE          = 0x00010000,
51  PNODE_PROHIBIT_DELETE_WITH_PARENT    = 0x00020000,
52
[4765]53} PARENT_MODE;
54
[3450]55//! The default mode of the translation-binding.
[5769]56#define PNODE_PARENT_MODE_DEFAULT PNODE_ALL | PNODE_REPARENT_KEEP_POSITION
[3246]57
[4440]58
[3450]59//! Patent Node is a Engine to calculate the position of an Object in respect to the position of its parent.
[4382]60class PNode : virtual public BaseObject {
[3365]61
[3246]62 public:
63  PNode ();
[4436]64  PNode(const TiXmlElement* root);
[4993]65  PNode (const Vector& absCoor, PNode* pNode);
[3365]66  virtual ~PNode ();
[3246]67
[4436]68  void loadParams(const TiXmlElement* root);
69
[3810]70  void setRelCoor (const Vector& relCoord);
[4610]71  void setRelCoor (float x, float y, float z);
[4992]72  void setRelCoorSoft(const Vector& relCoordSoft, float bias = 1.0);
73  void setRelCoorSoft(float x, float y, float z, float bias = 1.0);
[4836]74  /** @returns the relative position */
[5050]75  inline const Vector& getRelCoor () const { return this->prevRelCoordinate; };
[5113]76  /** @returns the Relative Coordinate Destination */
77  inline const Vector& getRelCoorSoft2D() const { return (this->toCoordinate)?*this->toCoordinate:this->relCoordinate; };
[3809]78  void setAbsCoor (const Vector& absCoord);
[4610]79  void setAbsCoor (float x, float y, float z);
[5406]80  void setAbsCoorSoft(const Vector& absCoordSoft, float bias = 1.0);
81  void setAbsCoorSoft(float x, float y, float z, float bias = 1.0);
[4836]82  /** @returns the absolute position */
[4372]83  inline const Vector& getAbsCoor () const { return this->absCoordinate; };
[3809]84  void shiftCoor (const Vector& shift);
[5750]85  void shiftCoor (float x, float y, float z) { this->shiftCoor(Vector(x, y, z)); };
[3246]86
[3810]87  void setRelDir (const Quaternion& relDir);
[4771]88  void setRelDir (float x, float y, float z);
[4992]89  void setRelDirSoft(const Quaternion& relDirSoft, float bias = 1.0);
90  void setRelDirSoft(float x, float y, float z, float bias = 1.0);
[4836]91  /** @returns the relative Direction */
[5050]92  inline const Quaternion& getRelDir () const { return this->prevRelDirection; };
[5113]93  /** @returns the Relative Directional Destination */
94  inline const Quaternion& getRelDirSoft2D() const { return (this->toDirection)?*this->toDirection:this->relDirection; };
[4836]95  /** @returns a Vector pointing into the relative Direction */
[5050]96  inline Vector getRelDirV() const { return this->prevRelDirection.apply(Vector(0,1,0)); };
[3810]97  void setAbsDir (const Quaternion& absDir);
[4771]98  void setAbsDir (float x, float y, float z);
[5414]99  void setAbsDirSoft(const Quaternion& absDirSoft, float bias = 1.0);
100  void setAbsDirSoft(float x, float y, float z, float bias = 1.0);
[4836]101  /** @returns the absolute Direction */
[4372]102  inline const Quaternion& getAbsDir () const { return this->absDirection; };
[4836]103  /** @returns a Vector pointing into the absolute Direction */
[4372]104  inline Vector getAbsDirV() const { return this->absDirection.apply(Vector(0,1,0)); };
[3802]105  void shiftDir (const Quaternion& shift);
[3246]106
[4836]107  /** @returns the Speed of the Node */
[4993]108  inline float getSpeed() const { return this->velocity.len(); };
[4836]109  /** @returns the Velocity of the Node */
[4993]110  inline const Vector& getVelocity() const { return this->velocity; };
[3644]111
[4440]112
[5382]113  void addChild (PNode* child);
[4765]114  void addChild (const char* childName);
[4993]115  void removeChild (PNode* child);
[5769]116  void removeNode();
[3537]117
[3535]118  void setParent (PNode* parent);
[4987]119  void setParent (const char* parentName);
[4966]120  /** @returns the parent of this PNode */
[5387]121  inline PNode* getParent () const { return this->parent; };
122  /** @returns the List of Children of this PNode */
[5769]123 // inline const tList<PNode>* getChildren() const { return this->children; };
[4761]124
[5382]125  void setParentSoft(PNode* parentNode, float bias = 1.0);
126  void setParentSoft(const char* parentName, float bias = 1.0);
[4987]127
[4993]128  /** @param parentMode sets the parentingMode of this Node */
129  void setParentMode (PARENT_MODE parentMode) { this->parentMode = parentMode; };
[4765]130  void setParentMode (const char* parentingMode);
[4836]131  /** @returns the Parenting mode of this node */
[4444]132  int getParentMode() const { return this->parentMode; };
[3246]133
[5769]134  void updateNode (float dt);
[3246]135
[5769]136  void countChildNodes(int& nodes) const;
137  void debugNode (unsigned int depth = 1, unsigned int level = 0) const;
[5383]138  void debugDraw(unsigned int depth = 1, float size = 1.0, const Vector& color = Vector(1, 0, 0), unsigned int level = 0) const;
[3365]139
[4993]140
141  // helper functions //
142  static const char* parentingModeToChar(int parentingMode);
143  static PARENT_MODE charToParentingMode(const char* parentingMode);
[5750]144
145
[4440]146 private:
147  void init(PNode* parent);
[4987]148  /** tells the child that the parent's Coordinate has changed */
[4440]149  inline void parentCoorChanged () { this->bRelCoorChanged = true; }
[4987]150  /** tells the child that the parent's Direction has changed */
[4440]151  inline void parentDirChanged () { this->bRelDirChanged = true; }
[4836]152  /** @returns the last calculated coordinate */
[4993]153  inline Vector getLastAbsCoor() { return this->lastAbsCoordinate; }
[3246]154
[3537]155
[3644]156 private:
[4440]157  bool            bRelCoorChanged;    //!< If Relative Coordinate has changed since last time we checked
158  bool            bRelDirChanged;     //!< If Relative Direction has changed since last time we checked
[3644]159
[4440]160  Vector          relCoordinate;      //!< coordinates relative to the parent
161  Vector          absCoordinate;      //!< absolute coordinates in the world ( from (0,0,0) )
162  Quaternion      relDirection;       //!< direction relative to the parent
163  Quaternion      absDirection;       //!< absolute direvtion in the world ( from (0,0,1) )
164
[5050]165  Vector          prevRelCoordinate;  //!< The last Relative Coordinate from the last update-Cycle.
[4440]166  Vector          lastAbsCoordinate;  //!< this is used for speedcalculation, it stores the last coordinate
[5050]167  Quaternion      prevRelDirection;   //!< The last Relative Direciton from the last update-Cycle.
168//  Quaternion      lastAbsDirection;
[4440]169
[5050]170  Vector          velocity;           //!< Saves the velocity.
[4987]171
[5382]172  Vector*         toCoordinate;       //!< a position to which to iterate. (This is used in conjunction with setParentSoft.and set*CoorSoft)
173  Quaternion*     toDirection;        //!< a direction to which to iterate. (This is used in conjunction with setParentSoft and set*DirSoft)
[4992]174  float           bias;               //!< how fast to iterate to the given position (default is 1)
[4987]175
[4440]176  PNode*          parent;             //!< a pointer to the parent node
[4987]177  tList<PNode>*   children;           //!< list of the children of this PNode
[4440]178
[4444]179  unsigned int    parentMode;         //!< the mode of the binding
[3246]180};
181
182#endif /* _P_NODE_H */
[4570]183
Note: See TracBrowser for help on using the repository browser.