Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: now PNodes can be rendered in Debug-Mode

File size: 5.6 KB
RevLine 
[4570]1/*!
[3246]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
[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
[3450]34//! enumeration for the different translation-binding-types
[3565]35//typedef enum parentingMode {PNODE_LOCAL_ROTATE, PNODE_ROTATE_MOVEMENT, PNODE_ALL, PNODE_MOVEMENT, PNODE_ROTATE_AND_MOVE};
36// linkage modes
37#define PNODE_LOCAL_ROTATE       1    //!< Rotates all the children around their centers.
38#define PNODE_ROTATE_MOVEMENT    2    //!< Moves all the children around the center of their parent, without the rotation around their own centers.
39#define PNODE_MOVEMENT           4    //!< Moves all children along with the parent.
40// special linkage modes
41#define PNODE_ALL                3    //!< Moves all children around the center of their parent, and also rotates their centers
42#define 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.
43
[3450]44//! The default mode of the translation-binding.
[3565]45#define DEFAULT_MODE PNODE_ALL
[3246]46
[4440]47
[3450]48//! Patent Node is a Engine to calculate the position of an Object in respect to the position of its parent.
[4382]49class PNode : virtual public BaseObject {
[3365]50
[3246]51 public:
52  PNode ();
[4436]53  PNode(const TiXmlElement* root);
[3809]54  PNode (const Vector& absCoordinate, PNode* pNode);
[3365]55  virtual ~PNode ();
[3246]56
[4436]57  void loadParams(const TiXmlElement* root);
58
[3810]59  void setRelCoor (const Vector& relCoord);
[4372]60  /** \returns the relative position */
61  inline const Vector& getRelCoor () const { return this->relCoordinate; };
[3809]62  void setAbsCoor (const Vector& absCoord);
[4448]63  /** \returns the absolute position */
[4372]64  inline const Vector& getAbsCoor () const { return this->absCoordinate; };
[3809]65  void shiftCoor (const Vector& shift);
[3246]66
[3810]67  void setRelDir (const Quaternion& relDir);
[4372]68  /** \returns the relative Direction */
69  inline const Quaternion& getRelDir () const { return this->relDirection; };
70  /** \returns a Vector pointing into the relative Direction */
71  inline Vector getRelDirV() const { return this->relDirection.apply(Vector(0,1,0)); };
[3810]72  void setAbsDir (const Quaternion& absDir);
[4372]73  /** \returns the absolute Direction */
74  inline const Quaternion& getAbsDir () const { return this->absDirection; };
75  /** \returns a Vector pointing into the absolute Direction */
76  inline Vector getAbsDirV() const { return this->absDirection.apply(Vector(0,1,0)); };
[3802]77  void shiftDir (const Quaternion& shift);
[3246]78
[4145]79  /** \returns the Speed of the Node */
[4570]80  inline float getSpeed() const {return this->velocity.len();}
[4145]81  /** \returns the Velocity of the Node */
82  inline const Vector& getVelocity() const {return this->velocity;}
[3644]83
[4440]84
[3802]85  void addChild (PNode* pNode, int parentingMode = DEFAULT_MODE);
[3246]86  void removeChild (PNode* pNode);
[3537]87  void remove();
88
[3535]89  void setParent (PNode* parent);
[4444]90  void setParentMode (unsigned int parentingMode);
[4448]91  /** \returns the Parenting mode of this node */
[4444]92  int getParentMode() const { return this->parentMode; };
[3246]93
[4440]94  void update (float dt);
[3246]95
[3365]96  void debug ();
[4570]97  void debugDraw(float size = 1.0) const;
[3365]98
[4440]99 private:
100  void init(PNode* parent);
[4448]101  /** \brief tells the child that the parent's Coordinate has changed */
[4440]102  inline void parentCoorChanged () { this->bRelCoorChanged = true; }
[4448]103  /** \brief tells the child that the parent's Direction has changed */
[4440]104  inline void parentDirChanged () { this->bRelDirChanged = true; }
105  /** \returns the last calculated coordinate */
106  inline Vector getLastAbsCoor(void) {return this->lastAbsCoordinate;}
[3246]107
[3537]108
[3644]109 private:
[4440]110  bool            bAbsCoorChanged;    //!< If Absolute Coordinate has changed since last time we checked
111  bool            bRelCoorChanged;    //!< If Relative Coordinate has changed since last time we checked
112  bool            bAbsDirChanged;     //!< If Absolute Direction has changed since last time we checked
113  bool            bRelDirChanged;     //!< If Relative Direction has changed since last time we checked
[3644]114
[4440]115  Vector          relCoordinate;      //!< coordinates relative to the parent
116  Vector          absCoordinate;      //!< absolute coordinates in the world ( from (0,0,0) )
117  Quaternion      relDirection;       //!< direction relative to the parent
118  Quaternion      absDirection;       //!< absolute direvtion in the world ( from (0,0,1) )
119
120  Vector          velocity;           //!< Saves the velocity.
121  Vector          lastAbsCoordinate;  //!< this is used for speedcalculation, it stores the last coordinate
122
123  PNode*          parent;             //!< a pointer to the parent node
124  tList<PNode>*   children;           //!< list of the children
125
[4444]126  unsigned int    parentMode;         //!< the mode of the binding
[3246]127};
128
129#endif /* _P_NODE_H */
[4570]130
Note: See TracBrowser for help on using the repository browser.