Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4440 in orxonox.OLD for orxonox


Ignore:
Timestamp:
Jun 1, 2005, 9:57:19 PM (20 years ago)
Author:
patrick
Message:

orxonox/trunk: pnode enhancement and cleanup, very tight now

Location:
orxonox/trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/coord/null_parent.cc

    r3966 r4440  
    4343{
    4444  PRINTF(4)("NullParent::NullParent() - making new NullParent, there can only be one..\n");
    45   this->parent = this;
    46   this->mode = PNODE_ALL;
     45  this->setMode(PNODE_ALL);
    4746  this->setName("NullParent");
    4847}
     
    5251{
    5352  singletonRef = this;
    54   this->parent = this;
    55   this->mode = PNODE_ALL;
    56   this->absCoordinate = absCoordinate;
     53  this->setMode(PNODE_ALL);
    5754  this->setName("NullParent");
    5855}
     
    7774   worry, normaly...
    7875*/
    79 void NullParent::update (float dt)
    80 {
    81 
    82   PRINTF(4)("NullParent::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
    83   this->absCoordinate = this->relCoordinate;
    84   this->absDirection = parent->getAbsDir () * this->relDirection;
    85 
    86   tIterator<PNode>* iterator = this->children->getIterator();
    87   //PNode* pn = this->children->enumerate ();
    88   PNode* pn = iterator->nextElement();
    89   while( pn != NULL)
    90     {
    91       /* if this node has changed, make sure, that all children are updated also */
    92       if( this->bRelCoorChanged || this->bAbsCoorChanged)
    93         pn->parentCoorChanged ();
    94       if( this->bRelDirChanged || this->bAbsDirChanged)
    95         pn->parentDirChanged ();
    96       pn->update (dt);
    97       //pn = this->children->nextElement ();
    98       pn = iterator->nextElement();
    99     }
    100 
    101   this->timeStamp = timeStamp;
    102   this->bRelCoorChanged = false;
    103   this->bAbsCoorChanged = false;
    104   this->bRelDirChanged = false;
    105   this->bAbsDirChanged = false;
    106 }
  • orxonox/trunk/src/lib/coord/null_parent.h

    r3809 r4440  
    1919
    2020
    21   virtual void update (float dt);
    22  
    2321 private:
    2422  NullParent ();
  • orxonox/trunk/src/lib/coord/p_node.cc

    r4436 r4440  
    408408void PNode::update (float dt)
    409409{
    410   this->lastAbsCoordinate = this->absCoordinate;
    411 
    412   PRINTF(4)("PNode::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
    413 
    414 
    415   if( likely(this->mode & PNODE_MOVEMENT))
     410  if( likely(this->parent != NULL))
    416411    {
    417       if( unlikely(this->bAbsCoorChanged) /*&& this->timeStamp != DataTank::timeStamp*/)
     412      this->lastAbsCoordinate = this->absCoordinate;
     413
     414      PRINTF(4)("PNode::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
     415
     416
     417      if( likely(this->mode & PNODE_MOVEMENT))
    418418        {
    419           /* if you have set the absolute coordinates this overrides all other changes */
    420           this->relCoordinate = this->absCoordinate - parent->getAbsCoor ();
     419          if( unlikely(this->bAbsCoorChanged) /*&& this->timeStamp != DataTank::timeStamp*/)
     420            {
     421              /* if you have set the absolute coordinates this overrides all other changes */
     422              this->relCoordinate = this->absCoordinate - parent->getAbsCoor ();
     423            }
     424          if( likely(this->bRelCoorChanged) /*&& this->timeStamp != DataTank::timeStamp*/)
     425
     426            {
     427              /*this is bad style... must be deleted later - just for testing*/
     428
     429              /*
     430                if( unlikely(this->parent == NULL))
     431                {
     432                *this->absCoordinate = *this->relCoordinate;
     433                }
     434                else */
     435              this->absCoordinate = parent->getAbsCoor() + this->relCoordinate;       /* update the current absCoordinate */
     436            }
    421437        }
    422       if( likely(this->bRelCoorChanged) /*&& this->timeStamp != DataTank::timeStamp*/)
    423 
     438 
     439      if( this->mode & PNODE_LOCAL_ROTATE)
    424440        {
    425           /*this is bad style... must be deleted later - just for testing*/
    426 
    427           /*
    428           if( unlikely(this->parent == NULL))
     441          if( unlikely(this->bAbsDirChanged) /*&& this->timeStamp != DataTank::timeStamp*/)
    429442            {
    430               *this->absCoordinate = *this->relCoordinate;
     443              /* if you have set the absolute coordinates this overrides all other changes */
     444              this->relDirection = this->absDirection - parent->getAbsDir();
    431445            }
    432             else */
    433           this->absCoordinate = parent->getAbsCoor() + this->relCoordinate;           /* update the current absCoordinate */
     446          else if( likely(this->bRelDirChanged) /*&& this->timeStamp != DataTank::timeStamp*/)
     447            {
     448              /* update the current absDirection - remember * means rotation around sth.*/
     449              this->absDirection = parent->getAbsDir() * this->relDirection;
     450            }
    434451        }
    435     }
    436452 
    437   if( this->mode & PNODE_LOCAL_ROTATE)
    438     {
    439       if( unlikely(this->bAbsDirChanged) /*&& this->timeStamp != DataTank::timeStamp*/)
     453      if( this->mode & PNODE_ROTATE_MOVEMENT)
    440454        {
    441           /* if you have set the absolute coordinates this overrides all other changes */
    442           this->relDirection = this->absDirection - parent->getAbsDir();
     455          if( unlikely(this->bAbsCoorChanged) /*&& this->timeStamp != DataTank::timeStamp*/)
     456            {
     457              /* if you have set the absolute coordinates this overrides all other changes */
     458              this->relCoordinate = this->absCoordinate - parent->getAbsCoor ();
     459            }
     460          else if( likely(this->bRelCoorChanged) /*&& this->timeStamp != DataTank::timeStamp*/)
     461            {
     462              /*this is bad style... must be deleted later - just for testing*/
     463              /*if( this->parent == NULL)
     464               *this->absCoordinate = *this->relCoordinate;
     465               else*/
     466              this->absCoordinate = parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate);            /* update the current absCoordinate */
     467            }
    443468        }
    444       else if( likely(this->bRelDirChanged) /*&& this->timeStamp != DataTank::timeStamp*/)
    445         {
    446           /* update the current absDirection - remember * means rotation around sth.*/
    447           this->absDirection = parent->getAbsDir() * this->relDirection;
    448         }
    449     }
    450  
    451   if( this->mode & PNODE_ROTATE_MOVEMENT)
    452     {
    453       if( unlikely(this->bAbsCoorChanged) /*&& this->timeStamp != DataTank::timeStamp*/)
    454         {
    455           /* if you have set the absolute coordinates this overrides all other changes */
    456           this->relCoordinate = this->absCoordinate - parent->getAbsCoor ();
    457         }
    458       else if( likely(this->bRelCoorChanged) /*&& this->timeStamp != DataTank::timeStamp*/)
    459         {
    460           /*this is bad style... must be deleted later - just for testing*/
    461           /*if( this->parent == NULL)
    462             *this->absCoordinate = *this->relCoordinate;
    463             else*/
    464           this->absCoordinate = parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate);        /* update the current absCoordinate */
    465         }
    466     }
    467469 
    468470 
    469   tIterator<PNode>* iterator = this->children->getIterator();
    470   //PNode* pn = this->children->enumerate();
    471   PNode* pn = iterator->nextElement();
    472   while( pn != NULL)
    473     {
    474       /* if this node has changed, make sure, that all children are updated also */
    475       if( likely(this->bRelCoorChanged || this->bAbsCoorChanged))
    476         pn->parentCoorChanged ();
    477       if( likely(this->bRelDirChanged || this->bAbsDirChanged))
    478         pn->parentDirChanged ();
    479 
    480       pn->update(dt);
    481       //pn = this->children->nextElement();
    482       pn = iterator->nextElement();
    483     }
    484   delete iterator;
    485 
    486   this->velocity = (this->absCoordinate - this->lastAbsCoordinate) / dt;
    487   this->timeStamp = timeStamp;
    488   this->bRelCoorChanged = false;
    489   this->bAbsCoorChanged = false;
    490   this->bRelDirChanged = false;
    491   this->bAbsDirChanged = false;
     471      tIterator<PNode>* iterator = this->children->getIterator();
     472      //PNode* pn = this->children->enumerate();
     473      PNode* pn = iterator->nextElement();
     474      while( pn != NULL)
     475        {
     476          /* if this node has changed, make sure, that all children are updated also */
     477          if( likely(this->bRelCoorChanged || this->bAbsCoorChanged))
     478            pn->parentCoorChanged ();
     479          if( likely(this->bRelDirChanged || this->bAbsDirChanged))
     480            pn->parentDirChanged ();
     481
     482          pn->update(dt);
     483          //pn = this->children->nextElement();
     484          pn = iterator->nextElement();
     485        }
     486      delete iterator;
     487
     488      this->velocity = (this->absCoordinate - this->lastAbsCoordinate) / dt;
     489      this->bRelCoorChanged = false;
     490      this->bAbsCoorChanged = false;
     491      this->bRelDirChanged = false;
     492      this->bAbsDirChanged = false;
     493    }
     494  else
     495    {
     496      PRINTF(4)("NullParent::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
     497      this->absCoordinate = this->relCoordinate;
     498      this->absDirection = this->getAbsDir () * this->relDirection;
     499
     500      tIterator<PNode>* iterator = this->children->getIterator();
     501      //PNode* pn = this->children->enumerate ();
     502      PNode* pn = iterator->nextElement();
     503      while( pn != NULL)
     504        {
     505          /* if this node has changed, make sure, that all children are updated also */
     506          if( this->bRelCoorChanged || this->bAbsCoorChanged)
     507            pn->parentCoorChanged ();
     508          if( this->bRelDirChanged || this->bAbsDirChanged)
     509            pn->parentDirChanged ();
     510          pn->update (dt);
     511          //pn = this->children->nextElement ();
     512          pn = iterator->nextElement();
     513        }
     514
     515      this->bRelCoorChanged = false;
     516      this->bAbsCoorChanged = false;
     517      this->bRelDirChanged = false;
     518      this->bAbsDirChanged = false;
     519    }
    492520}
    493521
  • orxonox/trunk/src/lib/coord/p_node.h

    r4436 r4440  
    4545#define DEFAULT_MODE PNODE_ALL
    4646
     47
    4748//! Patent Node is a Engine to calculate the position of an Object in respect to the position of its parent.
    4849class PNode : virtual public BaseObject {
     
    5556
    5657  void loadParams(const TiXmlElement* root);
    57 
    58 
    59   PNode* parent;            //!< a pointer to the parent node
    60   tList<PNode>* children;   //!< list of the children
    61 
    62 
    6358
    6459  void setRelCoor (const Vector& relCoord);
     
    8075  /** \returns a Vector pointing into the absolute Direction */
    8176  inline Vector getAbsDirV() const { return this->absDirection.apply(Vector(0,1,0)); };
    82 
    8377  void shiftDir (const Quaternion& shift);
    8478
    8579  /** \returns the Speed of the Node */
    86   inline float getSpeed() const {return this->velocity.len()/1000;} //! \FIX THIS SHOULD NOT BE /1000
     80  inline float getSpeed() const {return this->velocity.len();}
    8781  /** \returns the Velocity of the Node */
    8882  inline const Vector& getVelocity() const {return this->velocity;}
    89   /** \returns the last calculated coordinate */
    90   inline Vector getLastAbsCoor(void) {return this->lastAbsCoordinate;}
     83
    9184
    9285  void addChild (PNode* pNode, int parentingMode = DEFAULT_MODE);
     
    9487  void remove();
    9588
    96 
    9789  void setParent (PNode* parent);
    98   inline void parentCoorChanged () { this->bRelCoorChanged = true; }
    99   inline void parentDirChanged () { this->bRelDirChanged = true; }
    10090  void setMode (int parentingMode);
    10191  int getMode() const;
    10292
    103   virtual void update (float dt);
     93  void update (float dt);
    10494  void processTick (float dt);
    10595
    10696  void debug ();
    10797
    108  protected:
    109   float timeStamp;         //!< this the timeStamp of when the abs{Coordinat, Direction} has been calculated
    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   int mode;                //!< the mode of the binding
    12198
    12299 private:
    123100  void init(PNode* parent);
     101  inline void parentCoorChanged () { this->bRelCoorChanged = true; }
     102  inline void parentDirChanged () { this->bRelDirChanged = true; }
     103  /** \returns the last calculated coordinate */
     104  inline Vector getLastAbsCoor(void) {return this->lastAbsCoordinate;}
    124105
    125   Vector velocity;          //!< Saves the velocity.
    126   Vector lastAbsCoordinate; //!< this is used for speedcalculation, it stores the last coordinate
     106
     107 private:
     108  bool            bAbsCoorChanged;    //!< If Absolute Coordinate has changed since last time we checked
     109  bool            bRelCoorChanged;    //!< If Relative Coordinate has changed since last time we checked
     110  bool            bAbsDirChanged;     //!< If Absolute Direction has changed since last time we checked
     111  bool            bRelDirChanged;     //!< If Relative Direction has changed since last time we checked
     112
     113  Vector          relCoordinate;      //!< coordinates relative to the parent
     114  Vector          absCoordinate;      //!< absolute coordinates in the world ( from (0,0,0) )
     115  Quaternion      relDirection;       //!< direction relative to the parent
     116  Quaternion      absDirection;       //!< absolute direvtion in the world ( from (0,0,1) )
     117
     118  Vector          velocity;           //!< Saves the velocity.
     119  Vector          lastAbsCoordinate;  //!< this is used for speedcalculation, it stores the last coordinate
     120
     121  PNode*          parent;             //!< a pointer to the parent node
     122  tList<PNode>*   children;           //!< list of the children
     123
     124  unsigned int    mode;               //!< the mode of the binding
    127125};
    128126
  • orxonox/trunk/src/lib/physics/physics_interface.cc

    r4397 r4440  
    6565void PhysicsInterface::recalcMass()
    6666{
     67  /*
    6768  PNode* massCalcPNode = dynamic_cast<PNode*>(this);  //! \todo not sure if this will work ....
    6869  float massSum = 0;
     
    8788    this->massChildren = massSum;
    8889  }
     90  */
    8991}
    9092       
     
    9597  this->forceSum += field->calcForce(tmp->getAbsCoor()); 
    9698}
     99
    97100
    98101void PhysicsInterface::tickPhys( float dt )
  • orxonox/trunk/src/util/track/track_node.cc

    r4320 r4440  
    4343TrackNode::TrackNode (const Vector& absCoordinate)
    4444{
    45   this->parent = NullParent::getInstance();
    4645  this->trackManager = TrackManager::getInstance();
    4746  this->setMode(PNODE_ALL);
Note: See TracChangeset for help on using the changeset viewer.