Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: saver Weapon-Projectile-generation and Stuff

File size: 7.3 KB
RevLine 
[4570]1/*!
[4993]2    @file p_node.h
[4836]3  *  Definition of a parenting node
[3246]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 \\
[4436]28class TiXmlElement;
[3607]29template<class T> class tList;
[3246]30
[5006]31#define PNODE_ITERATION_DELTA    .001
[4765]32//! Parental linkage modes
33typedef enum
34{
35  PNODE_LOCAL_ROTATE          =   1,    //!< Rotates all the children around their centers.
36  PNODE_ROTATE_MOVEMENT       =   2,    //!< Moves all the children around the center of their parent, without the rotation around their own centers.
37
38  PNODE_MOVEMENT              =   4,    //!< Moves all children along with the parent.
[3565]39// special linkage modes
[4765]40  PNODE_ALL                   =   3,    //!< Moves all children around the center of their parent, and also rotates their centers
[4991]41  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.
[3565]42
[4765]43} PARENT_MODE;
44
[3450]45//! The default mode of the translation-binding.
[5209]46#define PNODE_PARENT_MODE_DEFAULT PNODE_ALL
[3246]47
[4440]48
[3450]49//! Patent Node is a Engine to calculate the position of an Object in respect to the position of its parent.
[4382]50class PNode : virtual public BaseObject {
[3365]51
[3246]52 public:
53  PNode ();
[4436]54  PNode(const TiXmlElement* root);
[4993]55  PNode (const Vector& absCoor, PNode* pNode);
[3365]56  virtual ~PNode ();
[3246]57
[4436]58  void loadParams(const TiXmlElement* root);
59
[3810]60  void setRelCoor (const Vector& relCoord);
[4610]61  void setRelCoor (float x, float y, float z);
[4992]62  void setRelCoorSoft(const Vector& relCoordSoft, float bias = 1.0);
63  void setRelCoorSoft(float x, float y, float z, float bias = 1.0);
[4836]64  /** @returns the relative position */
[5050]65  inline const Vector& getRelCoor () const { return this->prevRelCoordinate; };
[5113]66  /** @returns the Relative Coordinate Destination */
67  inline const Vector& getRelCoorSoft2D() const { return (this->toCoordinate)?*this->toCoordinate:this->relCoordinate; };
[3809]68  void setAbsCoor (const Vector& absCoord);
[4610]69  void setAbsCoor (float x, float y, float z);
[4836]70  /** @returns the absolute position */
[4372]71  inline const Vector& getAbsCoor () const { return this->absCoordinate; };
[3809]72  void shiftCoor (const Vector& shift);
[3246]73
[3810]74  void setRelDir (const Quaternion& relDir);
[4771]75  void setRelDir (float x, float y, float z);
[4992]76  void setRelDirSoft(const Quaternion& relDirSoft, float bias = 1.0);
77  void setRelDirSoft(float x, float y, float z, float bias = 1.0);
[4836]78  /** @returns the relative Direction */
[5050]79  inline const Quaternion& getRelDir () const { return this->prevRelDirection; };
[5113]80  /** @returns the Relative Directional Destination */
81  inline const Quaternion& getRelDirSoft2D() const { return (this->toDirection)?*this->toDirection:this->relDirection; };
[4836]82  /** @returns a Vector pointing into the relative Direction */
[5050]83  inline Vector getRelDirV() const { return this->prevRelDirection.apply(Vector(0,1,0)); };
[3810]84  void setAbsDir (const Quaternion& absDir);
[4771]85  void setAbsDir (float x, float y, float z);
[4836]86  /** @returns the absolute Direction */
[4372]87  inline const Quaternion& getAbsDir () const { return this->absDirection; };
[4836]88  /** @returns a Vector pointing into the absolute Direction */
[4372]89  inline Vector getAbsDirV() const { return this->absDirection.apply(Vector(0,1,0)); };
[3802]90  void shiftDir (const Quaternion& shift);
[3246]91
[4836]92  /** @returns the Speed of the Node */
[4993]93  inline float getSpeed() const { return this->velocity.len(); };
[4836]94  /** @returns the Velocity of the Node */
[4993]95  inline const Vector& getVelocity() const { return this->velocity; };
[3644]96
[4440]97
[5209]98  void addChild (PNode* child, int parentingMode = PNODE_PARENT_MODE_DEFAULT);
[4765]99  void addChild (const char* childName);
[4993]100  void removeChild (PNode* child);
[3537]101  void remove();
102
[3535]103  void setParent (PNode* parent);
[4987]104  void setParent (const char* parentName);
[4966]105  /** @returns the parent of this PNode */
106  PNode* getParent () const { return this->parent; };
[4761]107
[4992]108  void softReparent(PNode* parentNode, float bias = 1.0);
109  void softReparent(const char* parentName, float bias = 1.0);
[4987]110
[4993]111  /** @param parentMode sets the parentingMode of this Node */
112  void setParentMode (PARENT_MODE parentMode) { this->parentMode = parentMode; };
[4765]113  void setParentMode (const char* parentingMode);
[4836]114  /** @returns the Parenting mode of this node */
[4444]115  int getParentMode() const { return this->parentMode; };
[3246]116
[4440]117  void update (float dt);
[3246]118
[4574]119  void debug (unsigned int depth = 1, unsigned int level = 0) const;
[5008]120  void debugDraw(unsigned int depth = 1, float size = 1.0, Vector color = Vector(1,1,1)) const;
[3365]121
[4993]122
123  // helper functions //
124  static const char* parentingModeToChar(int parentingMode);
125  static PARENT_MODE charToParentingMode(const char* parentingMode);
[4440]126 private:
127  void init(PNode* parent);
[4987]128  /** tells the child that the parent's Coordinate has changed */
[4440]129  inline void parentCoorChanged () { this->bRelCoorChanged = true; }
[4987]130  /** tells the child that the parent's Direction has changed */
[4440]131  inline void parentDirChanged () { this->bRelDirChanged = true; }
[4836]132  /** @returns the last calculated coordinate */
[4993]133  inline Vector getLastAbsCoor() { return this->lastAbsCoordinate; }
[3246]134
[3537]135
[3644]136 private:
[4440]137  bool            bRelCoorChanged;    //!< If Relative Coordinate has changed since last time we checked
138  bool            bRelDirChanged;     //!< If Relative Direction has changed since last time we checked
[3644]139
[4440]140  Vector          relCoordinate;      //!< coordinates relative to the parent
141  Vector          absCoordinate;      //!< absolute coordinates in the world ( from (0,0,0) )
142  Quaternion      relDirection;       //!< direction relative to the parent
143  Quaternion      absDirection;       //!< absolute direvtion in the world ( from (0,0,1) )
144
[5050]145  Vector          prevRelCoordinate;  //!< The last Relative Coordinate from the last update-Cycle.
[4440]146  Vector          lastAbsCoordinate;  //!< this is used for speedcalculation, it stores the last coordinate
[5050]147  Quaternion      prevRelDirection;   //!< The last Relative Direciton from the last update-Cycle.
148//  Quaternion      lastAbsDirection;
[4440]149
[5050]150  Vector          velocity;           //!< Saves the velocity.
[4987]151
[4993]152  Vector*         toCoordinate;       //!< a position to which to iterate. (This is used in conjunction with softReparent.and set*CoorSoft)
[4990]153  Quaternion*     toDirection;        //!< a direction to which to iterate. (This is used in conjunction with softReparent and set*DirSoft)
[4992]154  float           bias;               //!< how fast to iterate to the given position (default is 1)
[4987]155
[4440]156  PNode*          parent;             //!< a pointer to the parent node
[4987]157  tList<PNode>*   children;           //!< list of the children of this PNode
[4440]158
[4444]159  unsigned int    parentMode;         //!< the mode of the binding
[3246]160};
161
162#endif /* _P_NODE_H */
[4570]163
Note: See TracBrowser for help on using the repository browser.