1 | /*! |
---|
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 | |
---|
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 \\ |
---|
28 | class PNode; /* forward decleration, so that parentEntry has access to PNode */ |
---|
29 | //class Quaternion; |
---|
30 | //class Vector; |
---|
31 | class TiXmlElement; |
---|
32 | template<class T> class tList; |
---|
33 | |
---|
34 | //! enumeration for the different translation-binding-types |
---|
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 | |
---|
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. |
---|
49 | class PNode : virtual public BaseObject { |
---|
50 | |
---|
51 | public: |
---|
52 | PNode (); |
---|
53 | PNode(const TiXmlElement* root); |
---|
54 | PNode (const Vector& absCoordinate, PNode* pNode); |
---|
55 | virtual ~PNode (); |
---|
56 | |
---|
57 | void loadParams(const TiXmlElement* root); |
---|
58 | |
---|
59 | void setRelCoor (const Vector& relCoord); |
---|
60 | /** \returns the relative position */ |
---|
61 | inline const Vector& getRelCoor () const { return this->relCoordinate; }; |
---|
62 | void setAbsCoor (const Vector& absCoord); |
---|
63 | /** \returns the absolute position */ |
---|
64 | inline const Vector& getAbsCoor () const { return this->absCoordinate; }; |
---|
65 | void shiftCoor (const Vector& shift); |
---|
66 | |
---|
67 | void setRelDir (const Quaternion& relDir); |
---|
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)); }; |
---|
72 | void setAbsDir (const Quaternion& absDir); |
---|
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)); }; |
---|
77 | void shiftDir (const Quaternion& shift); |
---|
78 | |
---|
79 | /** \returns the Speed of the Node */ |
---|
80 | inline float getSpeed() const {return this->velocity.len();} |
---|
81 | /** \returns the Velocity of the Node */ |
---|
82 | inline const Vector& getVelocity() const {return this->velocity;} |
---|
83 | |
---|
84 | |
---|
85 | void addChild (PNode* pNode, int parentingMode = DEFAULT_MODE); |
---|
86 | void removeChild (PNode* pNode); |
---|
87 | void remove(); |
---|
88 | |
---|
89 | void setParent (PNode* parent); |
---|
90 | void setParentMode (unsigned int parentingMode); |
---|
91 | /** \returns the Parenting mode of this node */ |
---|
92 | int getParentMode() const { return this->parentMode; }; |
---|
93 | |
---|
94 | void update (float dt); |
---|
95 | |
---|
96 | void debug (); |
---|
97 | |
---|
98 | |
---|
99 | private: |
---|
100 | void init(PNode* parent); |
---|
101 | /** \brief tells the child that the parent's Coordinate has changed */ |
---|
102 | inline void parentCoorChanged () { this->bRelCoorChanged = true; } |
---|
103 | /** \brief tells the child that the parent's Direction has changed */ |
---|
104 | inline void parentDirChanged () { this->bRelDirChanged = true; } |
---|
105 | /** \returns the last calculated coordinate */ |
---|
106 | inline Vector getLastAbsCoor(void) {return this->lastAbsCoordinate;} |
---|
107 | |
---|
108 | |
---|
109 | private: |
---|
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 |
---|
114 | |
---|
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 | |
---|
126 | unsigned int parentMode; //!< the mode of the binding |
---|
127 | }; |
---|
128 | |
---|
129 | #endif /* _P_NODE_H */ |
---|
130 | |
---|