Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: optimizations

File size: 6.7 KB
RevLine 
[4570]1/*!
[3246]2    \file p_node.h
[4836]3  *  Definition of a parenting node
[3246]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
[4570]11    place or ortientation. this is only the case if
[3246]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
[3365]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...
[3246]18*/
19
20
21#ifndef _P_NODE_H
22#define _P_NODE_H
23
[3543]24#include "base_object.h"
[3804]25#include "vector.h"
[3246]26
[3543]27// FORWARD DEFINITION \\
[3365]28class PNode; /* forward decleration, so that parentEntry has access to PNode */
[3804]29//class Quaternion;
30//class Vector;
[4436]31class TiXmlElement;
[3607]32template<class T> class tList;
[3246]33
[4765]34//! Parental linkage modes
35typedef enum
36{
37  PNODE_LOCAL_ROTATE          =   1,    //!< Rotates all the children around their centers.
38  PNODE_ROTATE_MOVEMENT       =   2,    //!< Moves all the children around the center of their parent, without the rotation around their own centers.
39
40  PNODE_MOVEMENT              =   4,    //!< Moves all children along with the parent.
[3565]41// special linkage modes
[4765]42  PNODE_ALL                   =   3,    //!< Moves all children around the center of their parent, and also rotates their centers
[4991]43  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.
[3565]44
[4765]45} PARENT_MODE;
46
[3450]47//! The default mode of the translation-binding.
[3565]48#define DEFAULT_MODE PNODE_ALL
[3246]49
[4440]50
[3450]51//! Patent Node is a Engine to calculate the position of an Object in respect to the position of its parent.
[4382]52class PNode : virtual public BaseObject {
[3365]53
[3246]54 public:
55  PNode ();
[4436]56  PNode(const TiXmlElement* root);
[3809]57  PNode (const Vector& absCoordinate, PNode* pNode);
[3365]58  virtual ~PNode ();
[3246]59
[4436]60  void loadParams(const TiXmlElement* root);
61
[3810]62  void setRelCoor (const Vector& relCoord);
[4610]63  void setRelCoor (float x, float y, float z);
[4992]64  void setRelCoorSoft(const Vector& relCoordSoft, float bias = 1.0);
65  void setRelCoorSoft(float x, float y, float z, float bias = 1.0);
[4836]66  /** @returns the relative position */
[4372]67  inline const Vector& getRelCoor () const { return this->relCoordinate; };
[3809]68  void setAbsCoor (const Vector& absCoord);
[4610]69  void setAbsCoor (float x, float y, float z);
[4836]70  /** @returns the absolute position */
[4372]71  inline const Vector& getAbsCoor () const { return this->absCoordinate; };
[3809]72  void shiftCoor (const Vector& shift);
[3246]73
[3810]74  void setRelDir (const Quaternion& relDir);
[4771]75  void setRelDir (float x, float y, float z);
[4992]76  void setRelDirSoft(const Quaternion& relDirSoft, float bias = 1.0);
77  void setRelDirSoft(float x, float y, float z, float bias = 1.0);
[4836]78  /** @returns the relative Direction */
[4372]79  inline const Quaternion& getRelDir () const { return this->relDirection; };
[4836]80  /** @returns a Vector pointing into the relative Direction */
[4372]81  inline Vector getRelDirV() const { return this->relDirection.apply(Vector(0,1,0)); };
[3810]82  void setAbsDir (const Quaternion& absDir);
[4771]83  void setAbsDir (float x, float y, float z);
[4836]84  /** @returns the absolute Direction */
[4372]85  inline const Quaternion& getAbsDir () const { return this->absDirection; };
[4836]86  /** @returns a Vector pointing into the absolute Direction */
[4372]87  inline Vector getAbsDirV() const { return this->absDirection.apply(Vector(0,1,0)); };
[3802]88  void shiftDir (const Quaternion& shift);
[3246]89
[4836]90  /** @returns the Speed of the Node */
[4570]91  inline float getSpeed() const {return this->velocity.len();}
[4836]92  /** @returns the Velocity of the Node */
[4145]93  inline const Vector& getVelocity() const {return this->velocity;}
[3644]94
[4440]95
[3802]96  void addChild (PNode* pNode, int parentingMode = DEFAULT_MODE);
[4765]97  void addChild (const char* childName);
[3246]98  void removeChild (PNode* pNode);
[3537]99  void remove();
100
[3535]101  void setParent (PNode* parent);
[4987]102  void setParent (const char* parentName);
[4966]103  /** @returns the parent of this PNode */
104  PNode* getParent () const { return this->parent; };
[4761]105
[4992]106  void softReparent(PNode* parentNode, float bias = 1.0);
107  void softReparent(const char* parentName, float bias = 1.0);
[4987]108
[4765]109  void setParentMode (PARENT_MODE parentMode);
110  void setParentMode (const char* parentingMode);
[4836]111  /** @returns the Parenting mode of this node */
[4444]112  int getParentMode() const { return this->parentMode; };
[3246]113
[4440]114  void update (float dt);
[3246]115
[4574]116  void debug (unsigned int depth = 1, unsigned int level = 0) const;
[4570]117  void debugDraw(float size = 1.0) const;
[3365]118
[4440]119 private:
120  void init(PNode* parent);
[4987]121  /** tells the child that the parent's Coordinate has changed */
[4440]122  inline void parentCoorChanged () { this->bRelCoorChanged = true; }
[4987]123  /** tells the child that the parent's Direction has changed */
[4440]124  inline void parentDirChanged () { this->bRelDirChanged = true; }
[4836]125  /** @returns the last calculated coordinate */
[4746]126  inline Vector getLastAbsCoor() {return this->lastAbsCoordinate;}
[3246]127
[3537]128
[3644]129 private:
[4440]130  bool            bAbsCoorChanged;    //!< If Absolute Coordinate has changed since last time we checked
131  bool            bRelCoorChanged;    //!< If Relative Coordinate has changed since last time we checked
132  bool            bAbsDirChanged;     //!< If Absolute Direction has changed since last time we checked
133  bool            bRelDirChanged;     //!< If Relative Direction has changed since last time we checked
[3644]134
[4440]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
[4987]143
[4990]144  Vector*         toPosition;         //!< 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)
[4992]146  float           bias;               //!< how fast to iterate to the given position (default is 1)
[4987]147
[4440]148  PNode*          parent;             //!< a pointer to the parent node
[4987]149  tList<PNode>*   children;           //!< list of the children of this PNode
[4440]150
[4444]151  unsigned int    parentMode;         //!< the mode of the binding
[3246]152};
153
154#endif /* _P_NODE_H */
[4570]155
Note: See TracBrowser for help on using the repository browser.