1 | /*! |
---|
2 | \file p_node.h |
---|
3 | * 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 | //! Parental linkage modes |
---|
35 | typedef 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. |
---|
41 | // special linkage modes |
---|
42 | PNODE_ALL = 3, //!< Moves all children around the center of their parent, and also rotates their centers |
---|
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. |
---|
44 | |
---|
45 | } PARENT_MODE; |
---|
46 | |
---|
47 | //! The default mode of the translation-binding. |
---|
48 | #define DEFAULT_MODE PNODE_ALL |
---|
49 | |
---|
50 | |
---|
51 | //! Patent Node is a Engine to calculate the position of an Object in respect to the position of its parent. |
---|
52 | class PNode : virtual public BaseObject { |
---|
53 | |
---|
54 | public: |
---|
55 | PNode (); |
---|
56 | PNode(const TiXmlElement* root); |
---|
57 | PNode (const Vector& absCoordinate, PNode* pNode); |
---|
58 | virtual ~PNode (); |
---|
59 | |
---|
60 | void loadParams(const TiXmlElement* root); |
---|
61 | |
---|
62 | void setRelCoor (const Vector& relCoord); |
---|
63 | void setRelCoor (float x, float y, float z); |
---|
64 | /** @returns the relative position */ |
---|
65 | inline const Vector& getRelCoor () const { return this->relCoordinate; }; |
---|
66 | void setAbsCoor (const Vector& absCoord); |
---|
67 | void setAbsCoor (float x, float y, float z); |
---|
68 | /** @returns the absolute position */ |
---|
69 | inline const Vector& getAbsCoor () const { return this->absCoordinate; }; |
---|
70 | void shiftCoor (const Vector& shift); |
---|
71 | |
---|
72 | void setRelDir (const Quaternion& relDir); |
---|
73 | void setRelDir (float x, float y, float z); |
---|
74 | /** @returns the relative Direction */ |
---|
75 | inline const Quaternion& getRelDir () const { return this->relDirection; }; |
---|
76 | /** @returns a Vector pointing into the relative Direction */ |
---|
77 | inline Vector getRelDirV() const { return this->relDirection.apply(Vector(0,1,0)); }; |
---|
78 | void setAbsDir (const Quaternion& absDir); |
---|
79 | void setAbsDir (float x, float y, float z); |
---|
80 | /** @returns the absolute Direction */ |
---|
81 | inline const Quaternion& getAbsDir () const { return this->absDirection; }; |
---|
82 | /** @returns a Vector pointing into the absolute Direction */ |
---|
83 | inline Vector getAbsDirV() const { return this->absDirection.apply(Vector(0,1,0)); }; |
---|
84 | void shiftDir (const Quaternion& shift); |
---|
85 | |
---|
86 | /** @returns the Speed of the Node */ |
---|
87 | inline float getSpeed() const {return this->velocity.len();} |
---|
88 | /** @returns the Velocity of the Node */ |
---|
89 | inline const Vector& getVelocity() const {return this->velocity;} |
---|
90 | |
---|
91 | |
---|
92 | void addChild (PNode* pNode, int parentingMode = DEFAULT_MODE); |
---|
93 | void addChild (const char* childName); |
---|
94 | void removeChild (PNode* pNode); |
---|
95 | void remove(); |
---|
96 | |
---|
97 | void setParent (PNode* parent); |
---|
98 | void setParent (const char* name); |
---|
99 | |
---|
100 | void setParentMode (PARENT_MODE parentMode); |
---|
101 | void setParentMode (const char* parentingMode); |
---|
102 | /** @returns the Parenting mode of this node */ |
---|
103 | int getParentMode() const { return this->parentMode; }; |
---|
104 | |
---|
105 | void update (float dt); |
---|
106 | |
---|
107 | void debug (unsigned int depth = 1, unsigned int level = 0) const; |
---|
108 | void debugDraw(float size = 1.0) const; |
---|
109 | |
---|
110 | private: |
---|
111 | void init(PNode* parent); |
---|
112 | /** \brief tells the child that the parent's Coordinate has changed */ |
---|
113 | inline void parentCoorChanged () { this->bRelCoorChanged = true; } |
---|
114 | /** \brief tells the child that the parent's Direction has changed */ |
---|
115 | inline void parentDirChanged () { this->bRelDirChanged = true; } |
---|
116 | /** @returns the last calculated coordinate */ |
---|
117 | inline Vector getLastAbsCoor() {return this->lastAbsCoordinate;} |
---|
118 | |
---|
119 | |
---|
120 | private: |
---|
121 | bool bAbsCoorChanged; //!< If Absolute Coordinate has changed since last time we checked |
---|
122 | bool bRelCoorChanged; //!< If Relative Coordinate has changed since last time we checked |
---|
123 | bool bAbsDirChanged; //!< If Absolute Direction has changed since last time we checked |
---|
124 | bool bRelDirChanged; //!< If Relative Direction has changed since last time we checked |
---|
125 | |
---|
126 | Vector relCoordinate; //!< coordinates relative to the parent |
---|
127 | Vector absCoordinate; //!< absolute coordinates in the world ( from (0,0,0) ) |
---|
128 | Quaternion relDirection; //!< direction relative to the parent |
---|
129 | Quaternion absDirection; //!< absolute direvtion in the world ( from (0,0,1) ) |
---|
130 | |
---|
131 | Vector velocity; //!< Saves the velocity. |
---|
132 | Vector lastAbsCoordinate; //!< this is used for speedcalculation, it stores the last coordinate |
---|
133 | |
---|
134 | PNode* parent; //!< a pointer to the parent node |
---|
135 | tList<PNode>* children; //!< list of the children |
---|
136 | |
---|
137 | unsigned int parentMode; //!< the mode of the binding |
---|
138 | }; |
---|
139 | |
---|
140 | #endif /* _P_NODE_H */ |
---|
141 | |
---|