Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: PNode is now std::list-conform

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