Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6054 in orxonox.OLD


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

Location:
trunk/src
Files:
18 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:
  • trunk/src/story_entities/world.cc

    r6034 r6054  
    145145  // erease everything that is left.
    146146  delete NullParent::getInstance();
     147
     148  //secondary cleanup of PNodes;
     149  const std::list<BaseObject*>* nodeList = ClassList::getList(CL_PARENT_NODE);
     150  if (nodeList != NULL)
     151    while (!nodeList->empty())
     152      delete nodeList->front();
    147153
    148154  Shader::suspendShader();
  • trunk/src/world_entities/npcs/npc.cc

    r6004 r6054  
    5959    }
    6060    State::getWorldEntityList()->remove(this);
     61    this->removeNode();
    6162
    6263      this->collider = entity;
     
    6869    this->setVisibiliy(false);
    6970    State::getWorldEntityList()->remove(this);
     71    this->removeNode();
    7072  }
    7173}
  • trunk/src/world_entities/npcs/npc_test.cc

    r6004 r6054  
    5858
    5959
    60 void NPC2::collidesWith(WorldEntity* entity, const Vector& location)
    61 {
    62   if (entity->isA(CL_PROJECTILE))
    63   {
    64     PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getName(), entity->getName(), location.x, location.y, location.z);
    65     this->applyForce(Vector(0,0,0)-location*1000);
    66   }
    67   else if (entity->isA(CL_PLAYER))
    68     this->applyForce(Vector(0,0,0)-location*100);
    69   else
    70   {
    71     this->setVisibiliy(false);
    72    State::getWorldEntityList()->remove(this);
    73   }
    74 }
    75 
    7660
    7761/**
  • trunk/src/world_entities/npcs/npc_test.h

    r6004 r6054  
    2020  virtual void draw() const;
    2121
    22   virtual void collidesWith (WorldEntity* entity, const Vector& location);
    23 
    24 
    2522 private:
    2623   Vector   randomRotAxis;
  • trunk/src/world_entities/npcs/npc_test1.cc

    r6004 r6054  
    4646
    4747
    48 void NPCTest1::collidesWith(WorldEntity* entity, const Vector& location)
    49 {
    50   if (entity->isA(CL_PROJECTILE) && entity != this->collider)
    51   {
    52 //    PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getName(), entity->getName(), location.x, location.y, location.z);
    53 //    this->applyForce(Vector(0,0,0)-location*1000);
    54     if ((float)rand()/RAND_MAX < .3)
    55     {
    56       WorldEntity* powerUp = new TurretPowerUp();
    57       powerUp->setAbsCoor(this->getAbsCoor());
    58       State::getWorldEntityList()->add(powerUp);
    59     }
    60     else if ((float)rand()/RAND_MAX < .3)
    61     {
    62       WorldEntity* powerUp = new LaserPowerUp();
    63       powerUp->setAbsCoor(this->getAbsCoor());
    64       State::getWorldEntityList()->add(powerUp);
    65     }
    66     State::getWorldEntityList()->remove(this);
    67 
    68       this->collider = entity;
    69   }
    70   else if (entity->isA(CL_PLAYER))
    71     this->applyForce(Vector(0,0,0)-location*100);
    72   else if (entity->isA(CL_NPC))
    73   {
    74     this->setVisibiliy(false);
    75     State::getWorldEntityList()->remove(this);
    76   }
    77 }
    78 
    7948
    8049void NPCTest1::tick(float dt)
  • trunk/src/world_entities/npcs/npc_test1.h

    r6004 r6054  
    1818  virtual void tick(float dt);
    1919
    20   virtual void collidesWith (WorldEntity* entity, const Vector& location);
    21 
    22 
    2320 private:
    2421   Vector   randomRotAxis;
  • trunk/src/world_entities/weapons/aim.cc

    r5779 r6054  
    6565  this->setClassID(CL_CROSSHAIR, "Aim");
    6666  this->setName("Aim");
     67
     68  this->addNodeModeFlags(PNODE_REPARENT_TO_NULLPARENT);
    6769
    6870  this->setLayer(E2D_LAYER_TOP);
  • trunk/src/world_entities/weapons/guided_missile.cc

    r5994 r6054  
    152152{
    153153  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
    154   if (target != NULL && target->getParent() != NullParent::getInstance())
     154  if (target.getParent() != NullParent::getInstance())
    155155   {
    156      velocity += ((target->getAbsCoor() - this->getAbsCoor()).getNormalized())*agility;
     156     velocity += ((target.getAbsCoor() - this->getAbsCoor()).getNormalized())*agility;
    157157     float speed = velocity.len();
    158158     if (speed > this->maxVelocity)
  • trunk/src/world_entities/weapons/guided_missile.h

    r5766 r6054  
    99#include "projectile.h"
    1010
    11 class Vector;
    1211class Weapon;
    1312class ParticleSystem;
  • trunk/src/world_entities/weapons/projectile.cc

    r5994 r6054  
    3838  this->lifeCycle = 0.0;
    3939  this->lifeSpan = 1.0f; /* sec */
    40   this->target = NULL;
     40  this->target.addNodeModeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT |
     41                                PNODE_REPARENT_TO_NULLPARENT);
    4142
    4243  this->removeNode();
     
    103104void Projectile::setTarget(PNode* target)
    104105{
    105 
    106   if (this->target == NULL)
    107      this->target = new PNode();
    108   this->target->setParent(target);
     106  this->target.setParent(target);
    109107}
    110108
  • trunk/src/world_entities/weapons/projectile.h

    r5994 r6054  
    5555    Vector                velocity;                  //!< velocity of the projectile.
    5656
    57     PNode*                target;                    //!< A target for guided Weapons.
     57    PNode                 target;                    //!< A target for guided Weapons.
    5858};
    5959
  • trunk/src/world_entities/weapons/weapon.cc

    r5930 r6054  
    528528  tick(dt);
    529529}
    530 
    531 /**
    532  *  this will draw the weapon
    533 */
    534 void Weapon::draw () const
    535 {}
    536 
    537530
    538531
  • trunk/src/world_entities/weapons/weapon.h

    r5750 r6054  
    148148
    149149    virtual void tick(float dt) {};
    150     virtual void draw() const;
    151150
    152151    bool check() const;
  • trunk/src/world_entities/weapons/weapon_manager.cc

    r5982 r6054  
    3535
    3636/**
    37  * this initializes the weaponManager for a given nnumber of weapon slots
     37 * @brief this initializes the weaponManager for a given nnumber of weapon slots
    3838 * @param number of weapon slots of the model/ship <= 8 (limitied)
    3939 */
     
    5151
    5252/**
    53  * Destroys a WeaponManager
     53 * @brief Destroys a WeaponManager
    5454 */
    5555WeaponManager::~WeaponManager()
     
    6060
    6161/**
    62  * initializes the WeaponManager
     62 * @brief initializes the WeaponManager
    6363 */
    6464void WeaponManager::init()
Note: See TracChangeset for help on using the changeset viewer.