Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3265 in orxonox.OLD for orxonox/branches/parenting/src/p_node.cc


Ignore:
Timestamp:
Dec 24, 2004, 1:45:15 PM (20 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.

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.