Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 7, 2005, 3:54:49 PM (19 years ago)
Author:
chris
Message:

orxonox/branches/levelloader: Merged trunk into branch… still not working though…

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/levelloader/src/lib/coord/p_node.cc

    r3605 r3746  
    2121
    2222#include "p_node.h"
    23 
     23#include "stdincl.h"
     24
     25#include "error.h"
     26#include "debug.h"
     27#include "list.h"
     28#include "vector.h"
    2429#include "null_parent.h"
    25 #include "vector.h"
     30
     31
     32//#include "vector.h"
     33//#include "quaternion.h"
    2634
    2735using namespace std;
     
    5260  this->init(parent);
    5361
    54   this->absCoordinate = *absCoordinate;
     62  *this->absCoordinate = *absCoordinate;
    5563  if (parent != NULL)
    5664    {
    57       this->relCoordinate = this->absCoordinate - parent->getAbsCoor ();
     65      *this->relCoordinate = *this->absCoordinate - parent->getAbsCoor ();
    5866      parent->addChild (this);
    5967    }
    6068  else
    61     this->relCoordinate = Vector(0,0,0);
     69    this->relCoordinate = new Vector(0,0,0);
    6270}
    6371
     
    94102}
    95103
     104
    96105void PNode::init(PNode* parent)
    97106{
     
    103112  this->parent = parent;
    104113  this->objectName = NULL;
     114
     115  this->absCoordinate = new Vector();
     116  this->relCoordinate = new Vector();
     117  this->absDirection = new Quaternion();
     118  this->relDirection = new Quaternion();
     119  this->lastAbsCoordinate = new Vector();
    105120}
    106121
     
    129144   \brief get relative coordinates
    130145   \returns relative coordinates to its parent
    131 */
    132 Vector PNode::getRelCoor ()
    133 {
    134   Vector r = this->relCoordinate; /* return a copy, so it can't be modified */
    135   return r;
     146   
     147   the reference that is returned is a pointer to the real relCoor, so don't
     148   change it unless you realy know what you are doing.
     149*/
     150Vector* PNode::getRelCoor ()
     151{
     152  //Vector r = *this->relCoordinate; /* return a copy, so it can't be modified */
     153  return this->relCoordinate;
    136154}
    137155
     
    148166{
    149167  this->bRelCoorChanged = true;
    150   this->relCoordinate = *relCoord;
     168  *this->relCoordinate = *relCoord;
     169}
     170
     171
     172/**
     173   \brief set relative coordinates
     174   \param relCoord relative coordinates to its parent
     175
     176   it is very importand, that you use this function, if you want to update the
     177   relCoordinates. If you don't use this, the PNode won't recognize, that something
     178   has changed and won't update the children Nodes.
     179*/
     180void PNode::setRelCoor (Vector relCoord)
     181{
     182  this->bRelCoorChanged = true;
     183  *this->relCoordinate = relCoord;
    151184}
    152185
     
    158191Vector PNode::getAbsCoor ()
    159192{
    160   return this->absCoordinate;
     193  return *this->absCoordinate;
    161194}
    162195
     
    172205{
    173206  this->bAbsCoorChanged = true;
    174   this->absCoordinate = *absCoord;
     207  *this->absCoordinate = *absCoord;
     208}
     209
     210
     211
     212/**
     213   \param absCoord set absolute coordinate
     214
     215   it is very importand, that you use this function, if you want to update the
     216   absCoordinates. If you don't use this, the PNode won't recognize, that something
     217   has changed and won't update the children Nodes.
     218*/
     219void PNode::setAbsCoor (Vector absCoord)
     220{
     221  this->bAbsCoorChanged = true;
     222  *this->absCoordinate = absCoord;
    175223}
    176224
     
    200248  if( this->bAbsCoorChanged)
    201249    {
    202       this->absCoordinate = this->absCoordinate + *shift;
     250      *this->absCoordinate = *this->absCoordinate + *shift;
    203251    }
    204252  else
    205253    {
    206       this->relCoordinate = this->relCoordinate + *shift;
     254      *this->relCoordinate = *this->relCoordinate + *shift;
     255      this->bRelCoorChanged = true;
     256    }
     257}
     258
     259
     260
     261/**
     262   \brief shift coordinate (abs and rel)
     263   \param shift vector
     264
     265   this function shifts the current coordinates about the vector shift. this is
     266   usefull because from some place else you can:
     267   PNode* someNode = ...;
     268   Vector objectMovement = calculateShift();
     269   someNode->shiftCoor(objectMovement);
     270
     271   elsewhere you would have to:
     272   PNode* someNode = ...;
     273   Vector objectMovement = calculateShift();
     274   Vector currentCoor = someNode->getRelCoor();
     275   Vector newCoor = currentCoor + objectMovement;
     276   someNode->setRelCoor(newCoor);
     277   
     278   yea right... shorter...
     279
     280*/
     281void PNode::shiftCoor (Vector shift)
     282{
     283  if( this->bAbsCoorChanged)
     284    {
     285      *this->absCoordinate = *this->absCoordinate + shift;
     286    }
     287  else
     288    {
     289      *this->relCoordinate = *this->relCoordinate + shift;
    207290      this->bRelCoorChanged = true;
    208291    }
     
    217300Quaternion PNode::getRelDir ()
    218301{
    219   return this->relDirection;
     302  return *this->relDirection;
    220303}
    221304
     
    232315{
    233316  this->bRelCoorChanged = true;
    234   this->relDirection = *relDir;
     317  *this->relDirection = *relDir;
     318}
     319
     320
     321void PNode::setRelDir (Quaternion relDir)
     322{
     323  this->bRelCoorChanged = true;
     324  *this->relDirection = relDir;
    235325}
    236326
     
    242332Quaternion PNode::getAbsDir ()
    243333{
    244   return this->absDirection;
     334  return *this->absDirection;
    245335}
    246336
     
    257347{
    258348  this->bAbsDirChanged = true;
    259   this->absDirection = *absDir;
    260 }
     349  *this->absDirection = *absDir;
     350}
     351
     352
     353
     354/**
     355   \brief sets the absolute direction (0,0,1)
     356   \param absDir absolute coordinates
     357
     358   it is very importand, that you use this function, if you want to update the
     359   absDirection. If you don't use this, the PNode won't recognize, that something
     360   has changed and won't update the children Nodes.
     361*/
     362void PNode::setAbsDir (Quaternion absDir)
     363{
     364  this->bAbsDirChanged = true;
     365  *this->absDirection = absDir;
     366}
     367
    261368
    262369
     
    285392{}
    286393
     394
     395/**
     396   \brief shift coordinate (abs and rel)
     397   \param shift vector
     398
     399   this function shifts the current coordinates about the vector shift. this is
     400   usefull because from some place else you can:
     401   PNode* someNode = ...;
     402   Quaternion objectMovement = calculateShift();
     403   someNode->shiftCoor(objectMovement);
     404
     405   elsewhere you would have to:
     406   PNode* someNode = ...;
     407   Quaternion objectMovement = calculateShift();
     408   Quaternion currentCoor = someNode->getRelCoor();
     409   Quaternion newCoor = currentCoor + objectMovement;
     410   someNode->setRelCoor(newCoor);
     411   
     412   yea right... shorter...
     413
     414   \todo implement this
     415*/
     416void PNode::shiftDir (Quaternion shift)
     417{}
     418
     419
     420/**
     421   \brief this calculates the current movement speed of the node
     422*/
     423float PNode::getSpeed()
     424{
     425  if(this->time == 0)
     426    return 1000;
     427  Vector diff;
     428  diff = *this->absCoordinate - *this->lastAbsCoordinate;
     429  float x = diff.len();
     430  return x / this->time;
     431}
     432
     433
    287434/**
    288435   \brief adds a child and makes this node to a parent
     
    308455  if( pNode->parent != NULL )
    309456    {
    310       PRINTF(2)("PNode::addChild() - reparenting node: removing it and adding it again\n");
     457      PRINTF(3)("PNode::addChild() - reparenting node: removing it and adding it again\n");
    311458      pNode->parent->children->remove(pNode);
    312459    }
     
    338485void PNode::remove()
    339486{
    340   NullParent* np = NullParent::getInstance();
    341   PNode* pn = this->children->enumerate();
     487  NullParent* nullParent = NullParent::getInstance();
     488
     489  tIterator<PNode>* iterator = this->children->getIterator();
     490  PNode* pn = iterator->nextElement();
     491 
    342492  while( pn != NULL)
    343493    {
    344       this->children->remove(pn);
    345       np->addChild(pn, pn->getMode());
    346       pn = this->children->nextElement();
    347     }
     494      //this->children->remove(pn);
     495      nullParent->addChild(pn, pn->getMode());
     496      pn = iterator->nextElement();
     497    }
     498  delete iterator;
     499  this->parent->children->remove(this);
    348500}
    349501
     
    410562   worry, normaly...
    411563*/
    412 void PNode::update ()
    413 {
    414   PRINTF(2)("PNode::update - %s - (%f, %f, %f)\n", this->objectName, this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
    415   // printf("%s", this->objectName);
     564void PNode::update (float dt)
     565{
     566  *this->lastAbsCoordinate = *this->absCoordinate;
     567  this->time = dt;
     568  PRINTF(4)("PNode::update - %s - (%f, %f, %f)\n", this->objectName, this->absCoordinate->x, this->absCoordinate->y, this->absCoordinate->z);
    416569  if(this->mode & PNODE_MOVEMENT )
    417570    {
     
    419572        {
    420573          /* if you have set the absolute coordinates this overrides all other changes */
    421           this->relCoordinate = this->absCoordinate - parent->getAbsCoor ();
     574          *this->relCoordinate = *this->absCoordinate - parent->getAbsCoor ();
    422575        }
    423576      else if( this->bRelCoorChanged /*&& this->timeStamp != DataTank::timeStamp*/)
     
    426579          if( this->parent == NULL)
    427580            {
    428               this->absCoordinate = this->relCoordinate;
     581              *this->absCoordinate = *this->relCoordinate;
    429582            }
    430583          else
    431             this->absCoordinate = parent->getAbsCoor() + this->relCoordinate;         /* update the current absCoordinate */
     584            *this->absCoordinate = parent->getAbsCoor() + *this->relCoordinate;       /* update the current absCoordinate */
    432585        }
    433586    }
     
    438591        {
    439592          /* if you have set the absolute coordinates this overrides all other changes */
    440           this->relDirection = this->absDirection - parent->getAbsDir();
     593          *this->relDirection = *this->absDirection - parent->getAbsDir();
    441594        }
    442595      else if( this->bRelDirChanged /*&& this->timeStamp != DataTank::timeStamp*/)
    443596        {
    444597          /* update the current absDirection - remember * means rotation around sth.*/
    445           this->absDirection = parent->getAbsDir() * this->relDirection;
     598          *this->absDirection = parent->getAbsDir() * *this->relDirection;
    446599        }
    447600    }
     
    452605        {
    453606          /* if you have set the absolute coordinates this overrides all other changes */
    454           this->relCoordinate = this->absCoordinate - parent->getAbsCoor ();
     607          *this->relCoordinate = *this->absCoordinate - parent->getAbsCoor ();
    455608        }
    456609      else if( this->bRelCoorChanged /*&& this->timeStamp != DataTank::timeStamp*/)
     
    458611          /*this is bad style... must be deleted later - just for testing*/
    459612          if( this->parent == NULL)
    460             this->absCoordinate = this->relCoordinate;
     613            *this->absCoordinate = *this->relCoordinate;
    461614          else
    462             this->absCoordinate = parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate);              /* update the current absCoordinate */
     615            *this->absCoordinate = parent->getAbsCoor() + parent->getAbsDir().apply(*this->relCoordinate);            /* update the current absCoordinate */
    463616        }
    464617    }
    465618 
    466619 
    467   PNode* pn = this->children->enumerate();
     620  tIterator<PNode>* iterator = this->children->getIterator();
     621  //PNode* pn = this->children->enumerate();
     622  PNode* pn = iterator->nextElement();
    468623  while( pn != NULL)
    469624    {
     
    473628      if( this->bRelDirChanged || this->bAbsDirChanged)
    474629        pn->parentDirChanged ();
    475       pn->update();
    476       pn = this->children->nextElement();
    477     }
     630
     631      pn->update(dt);
     632      //pn = this->children->nextElement();
     633      pn = iterator->nextElement();
     634    }
     635  delete iterator;
    478636
    479637  this->timeStamp = timeStamp;
     
    507665{
    508666  PRINTF(2)("PNode::debug() - absCoord: (%f, %f, %f)\n",
    509          this->absCoordinate.x,
    510          this->absCoordinate.y,
    511          this->absCoordinate.z);
     667         this->absCoordinate->x,
     668         this->absCoordinate->y,
     669         this->absCoordinate->z);
    512670}
    513671
Note: See TracChangeset for help on using the changeset viewer.