[3246] | 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 | |
---|
[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 | |
---|
[3605] | 24 | #include "base_object.h" |
---|
[3246] | 25 | |
---|
[3605] | 26 | // FORWARD DEFINITION \\ |
---|
[3365] | 27 | class PNode; /* forward decleration, so that parentEntry has access to PNode */ |
---|
[3605] | 28 | class Quaternion; |
---|
| 29 | class Vector; |
---|
[3246] | 30 | |
---|
[3450] | 31 | //! enumeration for the different translation-binding-types |
---|
[3605] | 32 | //typedef enum parentingMode {PNODE_LOCAL_ROTATE, PNODE_ROTATE_MOVEMENT, PNODE_ALL, PNODE_MOVEMENT, PNODE_ROTATE_AND_MOVE}; |
---|
| 33 | // linkage modes |
---|
| 34 | #define PNODE_LOCAL_ROTATE 1 //!< Rotates all the children around their centers. |
---|
| 35 | #define PNODE_ROTATE_MOVEMENT 2 //!< Moves all the children around the center of their parent, without the rotation around their own centers. |
---|
| 36 | #define PNODE_MOVEMENT 4 //!< Moves all children along with the parent. |
---|
| 37 | // special linkage modes |
---|
| 38 | #define PNODE_ALL 3 //!< Moves all children around the center of their parent, and also rotates their centers |
---|
| 39 | #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. |
---|
| 40 | |
---|
[3450] | 41 | //! The default mode of the translation-binding. |
---|
[3605] | 42 | #define DEFAULT_MODE PNODE_ALL |
---|
[3246] | 43 | |
---|
[3450] | 44 | //! Patent Node is a Engine to calculate the position of an Object in respect to the position of its parent. |
---|
[3365] | 45 | class PNode : public BaseObject { |
---|
| 46 | |
---|
[3246] | 47 | public: |
---|
| 48 | PNode (); |
---|
[3365] | 49 | PNode (Vector* absCoordinate, PNode* pNode); |
---|
| 50 | virtual ~PNode (); |
---|
[3246] | 51 | |
---|
[3450] | 52 | PNode* parent; //!< a pointer to the parent node |
---|
| 53 | tList<PNode>* children; //!< list of the children |
---|
[3365] | 54 | |
---|
| 55 | |
---|
[3605] | 56 | |
---|
[3246] | 57 | Vector getRelCoor (); |
---|
[3365] | 58 | void setRelCoor (Vector* relCoord); |
---|
| 59 | //void setRelCoor (Vector relCoord); |
---|
[3246] | 60 | Vector getAbsCoor (); |
---|
[3365] | 61 | void setAbsCoor (Vector* absCoord); |
---|
| 62 | //void setAbsCoor (Vector absCoord); |
---|
| 63 | void shiftCoor (Vector* shift); |
---|
| 64 | //void shiftCoor (Vector shift); |
---|
[3246] | 65 | |
---|
| 66 | Quaternion getRelDir (); |
---|
[3365] | 67 | void setRelDir (Quaternion* relDir); |
---|
[3246] | 68 | Quaternion getAbsDir (); |
---|
[3365] | 69 | void setAbsDir (Quaternion* absDir); |
---|
| 70 | void shiftDir (Quaternion* shift); |
---|
[3246] | 71 | |
---|
| 72 | void addChild (PNode* pNode); |
---|
[3605] | 73 | void addChild (PNode* pNode, int parentingMode); |
---|
[3246] | 74 | void removeChild (PNode* pNode); |
---|
[3605] | 75 | void remove(); |
---|
| 76 | |
---|
| 77 | |
---|
[3365] | 78 | void setParent (PNode* parent); |
---|
| 79 | void parentCoorChanged (); |
---|
| 80 | void parentDirChanged (); |
---|
[3605] | 81 | void setMode (int parentingMode); |
---|
| 82 | int getMode(); |
---|
[3246] | 83 | |
---|
[3605] | 84 | virtual void update (); |
---|
[3365] | 85 | void processTick (float dt); |
---|
[3246] | 86 | |
---|
[3557] | 87 | void setName (const char* newName); |
---|
| 88 | const char* getName (); |
---|
[3365] | 89 | |
---|
| 90 | |
---|
| 91 | void debug (); |
---|
| 92 | |
---|
[3605] | 93 | private: |
---|
| 94 | void init(PNode* parent); |
---|
| 95 | |
---|
| 96 | protected: |
---|
[3450] | 97 | float timeStamp; //!< this the timeStamp of when the abs{Coordinat, Direction} has been calculated |
---|
| 98 | char* objectName; //!< The name of the Object |
---|
| 99 | bool bAbsCoorChanged; //!< If Absolute Coordinate has changed since last time we checked |
---|
| 100 | bool bRelCoorChanged; //!< If Relative Coordinate has changed since last time we checked |
---|
| 101 | bool bAbsDirChanged; //!< If Absolute Direction has changed since last time we checked |
---|
| 102 | bool bRelDirChanged; //!< If Relative Direction has changed since last time we checked |
---|
[3365] | 103 | |
---|
[3450] | 104 | Vector relCoordinate; //!< coordinates relative to the parent |
---|
| 105 | Vector absCoordinate; //!< absolute coordinates in the world ( from (0,0,0) ) |
---|
| 106 | Quaternion relDirection; //!< direction relative to the parent |
---|
| 107 | Quaternion absDirection; //!< absolute direvtion in the world ( from (0,0,1) ) |
---|
[3246] | 108 | |
---|
[3605] | 109 | int mode; //!< the mode of the binding |
---|
| 110 | |
---|
[3246] | 111 | }; |
---|
| 112 | |
---|
| 113 | #endif /* _P_NODE_H */ |
---|
[3605] | 114 | |
---|