Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6054 in orxonox.OLD for trunk/src/lib/coord/p_node.cc


Ignore:
Timestamp:
Dec 11, 2005, 6:23:42 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: multiple new Reparenting modes in PNode.
Testing the stuff in GuidedMissile
Projectile has a PNode as reference not as pointer
some minor weapon changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/coord/p_node.cc

    r6048 r6054  
    2222#include "class_list.h"
    2323
    24 #include "stdincl.h"
    2524#include "compiler.h"
    26 #include "error.h"
    2725#include "debug.h"
    28 #include "vector.h"
    29 
     26
     27#include "glincl.h"
    3028#include "color.h"
    3129
     
    8684PNode::~PNode ()
    8785{
    88   // remove the Node, delete it's children.
    89   PNode* tmp;
    90   while (this->children.size() > 0)
    91   {
    92     tmp = this->children.front();
    93     this->children.pop_front();
    94       delete tmp;
     86  // remove the Node, delete it's children (if required).
     87  std::list<PNode*>::iterator tmp = this->children.begin();
     88  std::list<PNode*>::iterator deleteNode;
     89  while (tmp != this->children.end())
     90  {
     91    deleteNode = tmp++;
     92    if ((this->parentMode & PNODE_PROHIBIT_CHILD_DELETE) || ((*deleteNode)->parentMode & PNODE_PROHIBIT_DELETE_WITH_PARENT) )
     93      (*deleteNode)->reparent();
     94    else
     95      delete (*deleteNode);
    9596  }
    9697  if (this->parent != NULL)
     
    120121  this->parent = parent;
    121122  this->parentMode = PNODE_PARENT_MODE_DEFAULT;
    122 
    123   // iterators
     123  this->bActive = true;
     124
     125  // smooth-movers
    124126  this->toCoordinate = NULL;
    125127  this->toDirection = NULL;
     
    269271  this->setAbsCoor(Vector(x, y, z));
    270272}
     273
    271274
    272275/**
     
    321324}
    322325
     326
    323327/**
    324328 * @brief set relative direction
     
    336340  this->bRelCoorChanged = true;
    337341}
     342
    338343
    339344/**
     
    366371}
    367372
     373
    368374/**
    369375 * @see void PNode::setRelDirSoft (const Quaternion& relDir)
     
    379385}
    380386
     387
    381388/**
    382389 * @brief sets the absolute direction
     
    399406}
    400407
     408
    401409/**
    402410 * @see void PNode::setAbsDir (const Quaternion& relDir)
     
    412420}
    413421
     422
    414423/**
    415424 * @brief sets the absolute direction
     
    430439  this->bRelDirChanged = true;
    431440}
     441
    432442
    433443/**
     
    491501 * @param child the child to remove from this pNode.
    492502 *
    493  * Children from pNode will not be lost, they are referenced to NullPointer
     503 * Children from pNode will not be lost, they are Reparented by the rules of the ParentMode
    494504 */
    495505void PNode::removeChild (PNode* child)
     
    503513}
    504514
     515
    505516/**
    506517 * @brief remove this pnode from the tree and adds all following to NullParent
     
    510521void PNode::removeNode()
    511522{
    512   list<PNode*>::iterator child;
    513   for (child = this->children.begin(); child != this->children.end(); child ++)
    514     NullParent::getInstance()->addChild(*child);
    515 
     523  if (this->parentMode & PNODE_REPARENT_CHILDREN_ON_REMOVE)
     524  {
     525    list<PNode*>::iterator child = this->children.begin();
     526    list<PNode*>::iterator reparenter;
     527    while (child != this->children.end())
     528    {
     529      reparenter = child++;
     530      (*reparenter)->reparent();
     531    }
     532  }
    516533  if (this->parent != NULL)
    517534    this->parent->children.remove(this);
     
    529546    parentNode->addChild(this);
    530547}
     548
    531549
    532550/**
     
    568586}
    569587
     588
    570589/**
    571590 * @brief does the reparenting in a very smooth way
     
    580599}
    581600
     601/**
     602 * @param parentMode sets the parentingMode of this Node
     603 */
     604void PNode::setParentMode(PARENT_MODE parentMode)
     605{
     606  this->parentMode &= (0xfff0 | parentMode);
     607}
    582608
    583609/**
     
    589615  this->setParentMode(PNode::charToParentingMode(parentingMode));
    590616}
     617
     618
     619/**
     620 * !!PRIVATE FUNCTION:
     621 * @brief reparents a node (happens on Parents Node delete or remove if Flags are set.)
     622 */
     623void PNode::reparent()
     624{
     625  if (this->parentMode & PNODE_REPARENT_TO_NULLPARENT)
     626    this->setParent(NullParent::getInstance());
     627  else if (this->parentMode & PNODE_REPARENT_TO_PARENTS_PARENT && this->parent != NULL)
     628    this->setParent(this->parent->getParent());
     629}
     630
     631void PNode::addNodeModeFlags(unsigned short nodeFlags)
     632{
     633  this->parentMode |= nodeFlags;
     634}
     635
     636
     637void PNode::removeNodeModeFlags(unsigned short nodeFlags)
     638{
     639  this->parentMode &= !nodeFlags;
     640}
     641
    591642
    592643/**
     
    602653  if( likely(this->parent != NULL))
    603654    {
    604       // movement for nodes with smoothMove enabled
    605       if (unlikely(this->toCoordinate != NULL))
     655      if (!(this->parentMode & PNODE_STATIC_NODE))
    606656      {
    607         Vector moveVect = (*this->toCoordinate - this->relCoordinate) *fabsf(dt)*bias;
    608         if (likely(moveVect.len() >= PNODE_ITERATION_DELTA))
     657        // movement for nodes with smoothMove enabled
     658        if (unlikely(this->toCoordinate != NULL))
    609659        {
    610           this->shiftCoor(moveVect);
     660          Vector moveVect = (*this->toCoordinate - this->relCoordinate) *fabsf(dt)*bias;
     661          if (likely(moveVect.len() >= PNODE_ITERATION_DELTA))
     662          {
     663            this->shiftCoor(moveVect);
     664          }
     665          else
     666          {
     667            delete this->toCoordinate;
     668            this->toCoordinate = NULL;
     669            PRINTF(5)("SmoothMove of %s finished\n", this->getName());
     670          }
    611671        }
    612         else
     672        if (unlikely(this->toDirection != NULL))
    613673        {
    614           delete this->toCoordinate;
    615           this->toCoordinate = NULL;
    616           PRINTF(5)("SmoothMove of %s finished\n", this->getName());
     674          Quaternion rotQuat = Quaternion::quatSlerp(this->relDirection,*this->toDirection, fabsf(dt)*this->bias);
     675          if (this->relDirection.distance(rotQuat) >PNODE_ITERATION_DELTA)
     676          {
     677            this->relDirection = rotQuat;
     678            this->bRelDirChanged;
     679          }
     680          else
     681          {
     682            delete this->toDirection;
     683            this->toDirection = NULL;
     684             PRINTF(5)("SmoothRotate of %s finished\n", this->getName());
     685          }
     686        }
     687
     688        // MAIN UPDATE /////////////////////////////////////
     689        this->lastAbsCoordinate = this->absCoordinate;
     690
     691        PRINTF(5)("PNode::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
     692
     693
     694        if( this->parentMode & PNODE_LOCAL_ROTATE && this->bRelDirChanged)
     695        {
     696          /* update the current absDirection - remember * means rotation around sth.*/
     697          this->prevRelCoordinate = this->relCoordinate;
     698          this->absDirection = this->relDirection * parent->getAbsDir();;
     699        }
     700
     701        if(likely(this->parentMode & PNODE_MOVEMENT && this->bRelCoorChanged))
     702        {
     703         /* update the current absCoordinate */
     704         this->prevRelCoordinate = this->relCoordinate;
     705         this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate;
     706        }
     707        else if( this->parentMode & PNODE_ROTATE_MOVEMENT && this->bRelCoorChanged)
     708        {
     709          /* update the current absCoordinate */
     710         this->prevRelCoordinate = this->relCoordinate;
     711         this->absCoordinate = this->parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate);
     712        }
     713        /////////////////////////////////////////////////
     714      }
     715  }
     716   else // Nodes without a Parent are handled faster :: MOST LIKELY THE NULLPARENT
     717    {
     718      if (!(this->parentMode & PNODE_STATIC_NODE))
     719      {
     720        PRINTF(4)("NullParent::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
     721        if (this->bRelCoorChanged)
     722        {
     723          this->prevRelCoordinate = this->relCoordinate;
     724          this->absCoordinate = this->relCoordinate;
     725        }
     726        if (this->bRelDirChanged)
     727        {
     728          this->prevRelDirection = this->relDirection;
     729          this->absDirection = this->getAbsDir () * this->relDirection;
    617730        }
    618731      }
    619       if (unlikely(this->toDirection != NULL))
    620       {
    621         Quaternion rotQuat = Quaternion::quatSlerp(this->relDirection,*this->toDirection, fabsf(dt)*this->bias);
    622         if (this->relDirection.distance(rotQuat) >PNODE_ITERATION_DELTA)
    623         {
    624           this->relDirection = rotQuat;
    625           this->bRelDirChanged;
    626         }
    627         else
    628         {
    629           delete this->toDirection;
    630           this->toDirection = NULL;
    631           PRINTF(5)("SmoothRotate of %s finished\n", this->getName());
    632         }
    633       }
    634 
    635       // MAIN UPDATE /////////////////////////////////////
    636       this->lastAbsCoordinate = this->absCoordinate;
    637 
    638       PRINTF(5)("PNode::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
    639 
    640 
    641       if( this->parentMode & PNODE_LOCAL_ROTATE && this->bRelDirChanged)
    642       {
    643         /* update the current absDirection - remember * means rotation around sth.*/
    644         this->prevRelCoordinate = this->relCoordinate;
    645         this->absDirection = this->relDirection * parent->getAbsDir();;
    646       }
    647 
    648       if(likely(this->parentMode & PNODE_MOVEMENT && this->bRelCoorChanged))
    649       {
    650         /* update the current absCoordinate */
    651         this->prevRelCoordinate = this->relCoordinate;
    652         this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate;
    653       }
    654       else if( this->parentMode & PNODE_ROTATE_MOVEMENT && this->bRelCoorChanged)
    655       {
    656         /* update the current absCoordinate */
    657         this->prevRelCoordinate = this->relCoordinate;
    658         this->absCoordinate = this->parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate);
    659       }
    660       /////////////////////////////////////////////////
    661    }
    662   else
    663     {
    664       PRINTF(4)("NullParent::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
    665       if (this->bRelCoorChanged)
    666       {
    667         this->prevRelCoordinate = this->relCoordinate;
    668         this->absCoordinate = this->relCoordinate;
    669       }
    670       if (this->bRelDirChanged)
    671       {
    672         this->prevRelDirection = this->relDirection;
    673         this->absDirection = this->getAbsDir () * this->relDirection;
    674       }
    675732    }
    676733
    677     if(!this->children.empty())
     734    if(!this->children.empty() && (this->bActive || this->parentMode & PNODE_UPDATE_CHILDREN_IF_INACTIVE ))
    678735    {
    679736      list<PNode*>::iterator child;
Note: See TracChangeset for help on using the changeset viewer.