Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3265 in orxonox.OLD


Ignore:
Timestamp:
Dec 24, 2004, 1:45:15 PM (19 years ago)
Author:
patrick
Message:

orxonox/branches/parenting: now finished the parenting class more or less - yet sill have som bugs that i have to find.

Location:
orxonox/branches/parenting/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/parenting/src/p_node.cc

    r3249 r3265  
    1414   main-programmer: Patrick Boenzli
    1515   co-programmer: ...
     16
     17   \todo Null-Parent => center of the coord system - singleton
     18   \todo Smooth-Parent: delay, speed
    1619*/
    1720
     
    3134{
    3235  this->children = new tList<PNode>();
    33   this->bCoorChanged = true;
    34   this->bDirChanged = true;
     36  this->bRelCoorChanged = true;
     37  this->bAbsCoorChanged = false;
     38  this->bRelDirChanged = true;
     39  this->bAbsDirChanged = false;
     40  this->parent = NULL;
     41}
     42
     43
     44/**
     45   \brief constructor with coodinates
     46*/
     47PNode::PNode (Vector* absCoordinate, PNode* parent )
     48{
     49  this->absCoordinate = *absCoordinate;
     50  this->relCoordinate = this->absCoordinate - this->parent->getAbsCoor ();
     51 
     52 
     53  this->children = new tList<PNode>();
     54  this->bRelCoorChanged = false;
     55  this->bAbsCoorChanged = true;
     56  this->bRelDirChanged = true;
     57  this->bAbsDirChanged = false;
     58  this->parent = parent;
     59
     60  parent->addChild (this);
    3561}
    3662
     
    6894*/
    6995void PNode::setRelCoor (Vector relCoord)
    70 {}
     96{
     97  this->bRelCoorChanged = true;
     98  this->relCoordinate = relCoord;
     99}
    71100
    72101
     
    76105*/
    77106Vector PNode::getAbsCoor ()
    78 {}
     107{
     108  return this->absCoordinate;
     109}
    79110
    80111
     
    88119*/
    89120void PNode::setAbsCoor (Vector absCoord)
    90 {}
     121{
     122  this->bAbsCoorChanged = true;
     123  this->absCoordinate = absCoord;
     124}
    91125
    92126
     
    111145
    112146*/
    113 void PNode::shiftCoor (Vector shift)
    114 {}
     147void PNode::shiftCoor (Vector* shift)
     148{
     149  if( this->bAbsCoorChanged)
     150    {
     151      this->absCoordinate = this->absCoordinate + *shift;
     152    }
     153  else
     154    {
     155      this->relCoordinate = this->relCoordinate + *shift;
     156      this->bRelCoorChanged = true;
     157    }
     158
     159  printf("PNode::shiftCoor() - relCoord: (%f, %f, %f)\n",
     160         this->relCoordinate.x,
     161         this->relCoordinate.y,
     162         this->relCoordinate.z);
     163}
    115164
    116165
     
    121170*/
    122171Quaternion PNode::getRelDir ()
    123 {}
     172{
     173  return this->relDirection;
     174}
    124175
    125176
     
    133184*/
    134185void PNode::setRelDir (Quaternion relDir)
    135 {}
     186{
     187  this->bRelCoorChanged = true;
     188  this->relDirection = relDir;
     189}
    136190
    137191
     
    176230
    177231*/
    178 void PNode::shiftDir (Quaternion shift)
     232void PNode::shiftDir (Quaternion* shift)
    179233{}
    180234
     
    203257{
    204258  pNode->mode = mode;
     259  pNode->parent = this;
    205260  this->children->add (pNode);
    206261}
     
    222277{
    223278  this->parent = parent;
     279}
     280
     281/**
     282   \brief set the mode of this parent manualy
     283*/
     284void PNode::setMode (parentingMode mode)
     285{
     286  this->mode = mode;
     287}
     288
     289/**
     290   \brief has to be called, if the parent coordinate has changed
     291   
     292   normaly this will be done by the parent itself automaticaly. If you call this, you
     293   will force an update of the coordinated of the node.
     294*/
     295void PNode::parentCoorChanged ()
     296{
     297  this->bRelCoorChanged = true;
     298}
     299
     300
     301/**
     302   \brief has to be called, if the parent direction has changed
     303   
     304   normaly this will be done by the parent itself automaticaly. If you call this, you
     305   will force an update of the direction of the node.
     306*/
     307void PNode::parentDirChanged ()
     308{
     309  this->bRelDirChanged = true;
    224310}
    225311
     
    232318   worry, normaly...
    233319*/
    234 void PNode::update(long timeStamp)
    235 {
    236   if(this->parent == NULL)
    237     printf("PNode::upate(long timeStamp) - parent is NULL...");
    238   if( this->bCoorChanged && this->timeStamp != DataTank::timeStamp)
    239     {
    240       /* update the current absCoordinate */
    241       this->absCoordinate = parent->getAbsCoor () + this->relCoordinate;
    242     }
    243   if( this->bDirChanged && this->timeStamp != DataTank::timeStamp)
    244     {
    245       /* update the current absDirection - remember * means rotation around sth.*/
    246       this->absDirection = parent->getAbsDir () * this->relDirection;
    247     }
    248  
     320void PNode::update (long timeStamp)
     321{
     322  printf("PNode::update() \n");
     323  //if( this->parent != NULL)
     324  //    {
     325     
     326      if( this->mode == MOVEMENT || this->mode == ALL)
     327        {
     328          if( this->bAbsCoorChanged /*&& this->timeStamp != DataTank::timeStamp*/)
     329            {
     330              /* if you have set the absolute coordinates this overrides all other changes */
     331              this->relCoordinate = this->absCoordinate - parent->getAbsCoor ();
     332            }
     333          else if( this->bRelCoorChanged /*&& this->timeStamp != DataTank::timeStamp*/)
     334            {
     335 printf("PNode::update() - inside: before: absCoord: (%f, %f, %f)\n",
     336         this->absCoordinate.x,
     337         this->absCoordinate.y,
     338         this->absCoordinate.z);
     339printf("PNode::update() - inside: before: relCoord: (%f, %f, %f)\n",
     340         this->relCoordinate.x,
     341         this->relCoordinate.y,
     342         this->relCoordinate.z);
     343              /*this is bad style... must be deleted later - just for testing*/
     344              if( this->parent == NULL)
     345                {
     346                this->absCoordinate = this->relCoordinate;
     347                printf("PNode::update() - insinde: NULL NULL NULL\n");
     348                }
     349              else
     350                this->absCoordinate = parent->getAbsCoor () + this->relCoordinate;            /* update the current absCoordinate */
     351 printf("PNode::update() - inside after: absCoord: (%f, %f, %f)\n",
     352         this->absCoordinate.x,
     353         this->absCoordinate.y,
     354         this->absCoordinate.z);
     355printf("PNode::update() - inside after: relCoord: (%f, %f, %f)\n",
     356         this->relCoordinate.x,
     357         this->relCoordinate.y,
     358         this->relCoordinate.z);
     359            }
     360        }
     361     
     362      if( this->mode == ROTATION && this->mode == ALL)
     363        {
     364          if( this->bAbsDirChanged /*&& this->timeStamp != DataTank::timeStamp*/)
     365            {
     366              /* if you have set the absolute coordinates this overrides all other changes */
     367              this->relDirection = this->absDirection - parent->getAbsDir ();
     368            }
     369          else if( this->bRelDirChanged /*&& this->timeStamp != DataTank::timeStamp*/)
     370            {
     371              /* update the current absDirection - remember * means rotation around sth.*/
     372              this->absDirection = parent->getAbsDir () * this->relDirection;
     373            }
     374        }   
     375      // }
    249376  PNode* pn = this->children->enumerate();
    250377  while( pn != NULL)
    251378    {
     379      /* if this node has changed, make sure, that all children are updated also */
     380      if( this->bRelCoorChanged || this->bAbsCoorChanged)
     381        pn->parentCoorChanged ();
     382      if( this->bRelDirChanged || this->bAbsDirChanged)
     383        pn->parentDirChanged ();
    252384      pn->update(timeStamp);
    253385      pn = this->children->nextElement();
     
    255387
    256388  this->timeStamp = timeStamp;
    257   this->bCoorChanged = false;
    258   this->bDirChanged = false;
    259 
    260 }
    261 
     389  this->bRelCoorChanged = false;
     390  this->bAbsCoorChanged = false;
     391  this->bRelDirChanged = false;
     392  this->bAbsDirChanged = false;
     393}
     394
     395
     396void PNode::debug()
     397{
     398  printf("PNode::debug() - absCoord: (%f, %f, %f)\n",
     399         this->absCoordinate.x,
     400         this->absCoordinate.y,
     401         this->absCoordinate.z);
     402}
  • orxonox/branches/parenting/src/p_node.h

    r3249 r3265  
    3333 public:
    3434  PNode ();
     35  PNode (Vector* absCoordinate, PNode* pNode);
    3536  ~PNode ();
     37
     38  PNode* parent; //! a pointer to the parent node
     39  tList<PNode>* children; //! list of the children
    3640
    3741  parentingMode mode;
     
    4145  Vector getAbsCoor ();
    4246  void setAbsCoor (Vector absCoord);
    43   void shiftCoor (Vector shift);
     47  void shiftCoor (Vector* shift);
    4448
    4549  Quaternion getRelDir ();
     
    4751  Quaternion getAbsDir ();
    4852  void setAbsDir (Quaternion absDir);
    49   void shiftDir (Quaternion shift);
     53  void shiftDir (Quaternion* shift);
    5054
    5155  void addChild (PNode* pNode);
     
    5357  void removeChild (PNode* pNode);
    5458  void setParent (PNode* parent);
    55   void update (long timeStamp);
     59  void parentCoorChanged ();
     60  void parentDirChanged ();
     61  void setMode (parentingMode mode);
     62  virtual void update (long timeStamp);
     63
     64  void debug ();
    5665
    5766 private:
    58   long timeStamp; //! this the timeStamp of when the abs{Coordinat, Direction} has been calculated
    59   bool bCoorChanged;
    60   bool bDirChanged;
     67  long timeStamp;   //! this the timeStamp of when the abs{Coordinat, Direction} has been calculated
     68  bool bAbsCoorChanged;
     69  bool bRelCoorChanged;
     70  bool bRelDirChanged;
     71  bool bAbsDirChanged;
    6172
    6273  Vector relCoordinate;  //! coordinates relative to the parent
     
    6576  Quaternion absDirection; //! absolute direvtion in the world ( from (0,0,1) )
    6677
    67   PNode* parent;
    68   tList<PNode>* children; //! list of the children
    69 
    7078};
    7179
  • orxonox/branches/parenting/src/world.cc

    r3233 r3265  
    2323#include "camera.h"
    2424#include "environment.h"
     25#include "p_node.h"
    2526
    2627using namespace std;
     
    7879  cn->addToWorld(this);
    7980  cn->enable(true);
     81
     82  /* this is only for test purposes */
     83  this->debug ();
    8084}
    8185
     
    571575void World::debug()
    572576{
    573   //List<WorldEntity> *l;
     577  printf("World::debug() - starting debug\n");
     578  PNode* p1 = new PNode ();
     579  PNode* p2 = new PNode (new Vector(2, 2, 2), p1);
     580  PNode* p3 = new PNode (new Vector(4, 4, 4), p1);
     581  PNode* p4 = new PNode (new Vector(6, 6, 6), p2);
     582
     583  p1->setMode (ALL);
     584
     585  //p1->addChild (p2);
     586  // p1->addChild (p3);
     587  //p2->addChild (p4);
     588
     589  p1->debug ();
     590  p2->debug ();
     591  p3->debug ();
     592  p4->debug ();
     593
     594  p1->shiftCoor (new Vector(-1, -1, -1));
     595
     596  printf("World::debug() - shift\n");
     597  p1->debug ();
     598  p2->debug ();
     599  p3->debug ();
     600  p4->debug ();
     601 
     602  p1->update (1);
     603
     604  printf("World::debug() - update\n");
     605  p1->debug ();
     606  p2->debug ();
     607  p3->debug ();
     608  p4->debug ();
     609
     610
     611  /*
    574612  WorldEntity* entity;
    575  
    576613  printf("counting all entities\n");
    577614  printf("World::debug() - enumerate()\n");
     
    582619      entity = entities->nextElement();
    583620    }
     621  */
    584622}
    585623
     
    800838  return false;
    801839}
     840
Note: See TracChangeset for help on using the changeset viewer.