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