Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6054 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Dec 11, 2005, 6:23:42 PM (19 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

Location:
trunk/src/lib
Files:
4 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;
  • trunk/src/lib/coord/p_node.h

    r6048 r6054  
    2828
    2929#define PNODE_ITERATION_DELTA    .001
     30
    3031//! Parental linkage modes
    3132typedef enum
     
    4546  PNODE_REPARENT_TO_PARENTS_PARENT     = 0x0020,    //!< Reparents the Node to the parents (old) parent it the parent gets removed.
    4647  PNODE_REPARENT_DELETE_CHILDREN       = 0x0040,    //!< Deletes the Children of the node when This Node is Removed. (Use with care).
    47   PNODE_REPARENT_KEEP_POSITION         = 0x0080,    //!< Tries to keep the Position if the Node is reparented.
     48  /// FIXME
     49   PNODE_REPARENT_KEEP_POSITION         = 0x0080,    //!< Tries to keep the Position if the Node is reparented.
    4850
    4951
     
    5153  PNODE_PROHIBIT_CHILD_DELETE          = 0x0100,    //!< Prohibits the Children from being deleted if this Node gets deleted.
    5254  PNODE_PROHIBIT_DELETE_WITH_PARENT    = 0x0200,    //!< Prohibits the Node to be deleted if the Parent is. Child will be reparented according to the Repaenting-Rules
    53   PNODE_REPARENT_CHILDREN_ON_DELETE    = 0x0400,    //!< Reparents the Children of the Node to
    54   PNODE_REPARANT_CHILDREN_ON_REMOVE    = 0x0800,    //!< Reparents the Children of the Node if the Node gets Removed.
     55  PNODE_REPARENT_CHILDREN_ON_REMOVE    = 0x0400,    //!< Reparents the Children of the Node if the Node gets Removed.
    5556
    5657  // VISIBILITY/ACTIVITY
     
    6465//! The default mode of the translation-binding.
    6566#define PNODE_PARENT_MODE_DEFAULT PNODE_ALL | \
     67                                  PNODE_REPARENT_CHILDREN_ON_REMOVE | \
    6668                                  PNODE_REPARENT_KEEP_POSITION
    6769
     
    7779
    7880  void loadParams(const TiXmlElement* root);
     81
     82  inline void activateNode() { this->bActive = true; };
     83  inline void deactivateNode() { this->bActive = false; };
     84  inline bool getNodeActiveState() { return this->bActive; };
    7985
    8086  void setRelCoor (const Vector& relCoord);
     
    132138  void removeNode();
    133139
    134   /** @param the new parent of this node */
     140  /** @param parent the new parent of this node */
    135141  inline void setParent (PNode* parent) { parent->addChild(this); };
    136142  void setParent (const char* parentName);
     
    143149  void setParentSoft(const char* parentName, float bias = 1.0);
    144150
    145   /** @param parentMode sets the parentingMode of this Node */
    146   void setParentMode (PARENT_MODE parentMode) { this->parentMode = parentMode; };
     151  void setParentMode (PARENT_MODE parentMode);
    147152  void setParentMode (const char* parentingMode);
    148153  /** @returns the Parenting mode of this node */
    149   int getParentMode() const { return this->parentMode; };
     154  int getParentMode() const { return 0x000f & this->parentMode; };
     155
     156  void addNodeModeFlags(unsigned short nodeFlags);
     157  void removeNodeModeFlags(unsigned short nodeFlags);
     158
    150159
    151160  void updateNode (float dt);
  • trunk/src/lib/event/event_handler.cc

    r5978 r6054  
    258258void EventHandler::grabEvents(bool grabEvents)
    259259{
    260      this->eventsGrabbed = grabEvents;
    261      if(!grabEvents)
    262       SDL_WM_GrabInput(SDL_GRAB_OFF);
    263      else
    264       SDL_WM_GrabInput(SDL_GRAB_ON);
     260  this->eventsGrabbed = grabEvents;
     261  if(!grabEvents)
     262    SDL_WM_GrabInput(SDL_GRAB_OFF);
     263  else
     264    SDL_WM_GrabInput(SDL_GRAB_ON);
    265265}
    266266
     
    364364  {
    365365    printf("Not sending event to the WindowManager\n");
     366
     367    EventHandler::getInstance()->grabEvents(false);
    366368    return 0;
    367369  }
  • trunk/src/lib/event/event_handler.h

    r5978 r6054  
    4444  void withUNICODE(bool enableUNICODE);
    4545  void grabEvents(bool grabEvents);
     46  bool grabbedEvents() const { return this->eventsGrabbed; };
    4647
    4748  void process();
     
    5253 private:
    5354  EventHandler();
    54 
    5555
    5656 private:
Note: See TracChangeset for help on using the changeset viewer.