Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5382 in orxonox.OLD for trunk


Ignore:
Timestamp:
Oct 15, 2005, 8:22:30 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: fixed a reparenting bug
made the naming more compliant

Location:
trunk/src
Files:
8 edited

Legend:

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

    r5372 r5382  
    235235}
    236236
     237
    237238/**
    238239 * @param absCoord set absolute coordinate
     
    266267}
    267268
     269
    268270/**
    269271 * @param x x-coordinate.
     
    287289   someNode->shiftCoor(objectMovement);
    288290
    289    elsewhere you would have to:
     291   otherwise you would have to:
    290292   PNode* someNode = ...;
    291293   Vector objectMovement = calculateShift();
     
    293295   Vector newCoor = currentCoor + objectMovement;
    294296   someNode->setRelCoor(newCoor);
    295 
    296    yea right... shorter...
    297297 *
    298 */
     298 */
    299299void PNode::shiftCoor (const Vector& shift)
    300300{
     
    405405 *  adds a child and makes this node to a parent
    406406 * @param child child reference
    407  * @param parentMode on which changes the child should also change ist state
    408  *
    409407 * use this to add a child to this node.
    410408*/
    411 void PNode::addChild (PNode* child, int parentMode)
     409void PNode::addChild (PNode* child)
    412410{
    413411  if( likely(child->parent != NULL))
     
    416414      child->parent->children->remove(child);
    417415    }
    418   child->parentMode = parentMode;
    419416  child->parent = this;
    420417  this->children->add(child);
     
    461458  while( pn != NULL)
    462459    {
    463       NullParent::getInstance()->addChild(pn, pn->getParentMode());
     460      NullParent::getInstance()->addChild(pn);
    464461      pn = iterator->nextElement();
    465462    }
     
    494491 * @param bias the speed to iterate to this new Positions
    495492 */
    496 void PNode::softReparent(PNode* parentNode, float bias)
    497 {
     493void PNode::setParentSoft(PNode* parentNode, float bias)
     494{
     495  // return if the new parent and the old one match
    498496  if (this->parent == parentNode)
    499497    return;
    500498
     499  // store the Valures to iterate to.
    501500  if (likely(this->toCoordinate == NULL))
    502501  {
     
    517516  parentNode->addChild(this);
    518517
    519  if (this->parentMode & PNODE_ROTATE_MOVEMENT)
    520    this->setRelCoor(this->parent->getAbsDir().inverse().apply(tmpV - this->parent->getAbsCoor()));
     518 if (this->parentMode & PNODE_ROTATE_MOVEMENT && this->parent != NULL)
     519   this->relCoordinate = this->parent->getAbsDir().inverse().apply(tmpV - this->parent->getAbsCoor());
    521520 else
    522    this->setRelCoor(tmpV - parentNode->getAbsCoor());
    523 
    524   this->setRelDir(tmpQ / parentNode->getAbsDir());
     521   this->relCoordinate = tmpV - parentNode->getAbsCoor();
     522
     523 this->relDirection = tmpQ / parentNode->getAbsDir();
    525524}
    526525
     
    530529 * @param bias the speed to iterate to this new Positions
    531530 */
    532 void PNode::softReparent(const char* parentName, float bias)
     531void PNode::setParentSoft(const char* parentName, float bias)
    533532{
    534533  PNode* parentNode = dynamic_cast<PNode*>(ClassList::getObject(parentName, CL_PARENT_NODE));
    535534  if (parentNode != NULL)
    536     this->softReparent(parentNode, bias);
     535    this->setParentSoft(parentNode, bias);
    537536}
    538537
     
    561560      if (unlikely(this->toCoordinate != NULL))
    562561      {
    563         Vector moveVect = (*this->toCoordinate - this->getRelCoor()) *fabsf(dt)*bias;
    564 
     562        Vector moveVect = (*this->toCoordinate - this->relCoordinate) *fabsf(dt)*bias;
    565563        if (likely(moveVect.len() >= PNODE_ITERATION_DELTA))
    566564        {
     
    701699   displays the PNode at its position with its rotation as a cube.
    702700*/
    703 void PNode::debugDraw(unsigned int depth, float size, Vector color) const
     701void PNode::debugDraw(unsigned int depth, float size, const Vector& color) const
    704702{
    705703  glMatrixMode(GL_MODELVIEW);
  • trunk/src/lib/coord/p_node.h

    r5356 r5382  
    9696
    9797
    98   void addChild (PNode* child, int parentingMode = PNODE_PARENT_MODE_DEFAULT);
     98  void addChild (PNode* child);
    9999  void addChild (const char* childName);
    100100  void removeChild (PNode* child);
     
    106106  PNode* getParent () const { return this->parent; };
    107107
    108   void softReparent(PNode* parentNode, float bias = 1.0);
    109   void softReparent(const char* parentName, float bias = 1.0);
     108  void setParentSoft(PNode* parentNode, float bias = 1.0);
     109  void setParentSoft(const char* parentName, float bias = 1.0);
    110110
    111111  /** @param parentMode sets the parentingMode of this Node */
     
    118118
    119119  void debug (unsigned int depth = 1, unsigned int level = 0) const;
    120   void debugDraw(unsigned int depth = 1, float size = 1.0, Vector color = Vector(1,1,1)) const;
     120  void debugDraw(unsigned int depth = 1, float size = 1.0, const Vector& color = Vector(1,1,1)) const;
    121121
    122122
     
    150150  Vector          velocity;           //!< Saves the velocity.
    151151
    152   Vector*         toCoordinate;       //!< a position to which to iterate. (This is used in conjunction with softReparent.and set*CoorSoft)
    153   Quaternion*     toDirection;        //!< a direction to which to iterate. (This is used in conjunction with softReparent and set*DirSoft)
     152  Vector*         toCoordinate;       //!< a position to which to iterate. (This is used in conjunction with setParentSoft.and set*CoorSoft)
     153  Quaternion*     toDirection;        //!< a direction to which to iterate. (This is used in conjunction with setParentSoft and set*DirSoft)
    154154  float           bias;               //!< how fast to iterate to the given position (default is 1)
    155155
  • trunk/src/lib/graphics/render2D/element_2d.cc

    r5378 r5382  
    555555 * @param bias the speed to iterate to this new Positions
    556556 */
    557 void Element2D::softReparent2D(Element2D* parentNode, float bias)
     557void Element2D::setParentSoft2D(Element2D* parentNode, float bias)
    558558{
    559559  if (this->parent == parentNode)
     
    578578  parentNode->addChild2D(this);
    579579
    580   if (this->parentMode & PNODE_ROTATE_MOVEMENT)
     580  if (this->parentMode & PNODE_ROTATE_MOVEMENT) //! @todo implement this.
    581581    ;//this->setRelCoor(this->parent->getAbsDir().inverse().apply(tmpV - this->parent->getAbsCoor()));
    582582  else
    583     this->setRelCoor2D(tmpV - parentNode->getAbsCoor2D());
    584 
    585   this->setRelDir2D(tmpQ - parentNode->getAbsDir2D());
     583    this->relCoordinate = (tmpV - parentNode->getAbsCoor2D());
     584  this->bRelCoorChanged = true;
     585
     586  this->relDirection = (tmpQ - parentNode->getAbsDir2D());
     587  this->bRelDirChanged = true;
    586588}
    587589
     
    591593 * @param bias the speed to iterate to this new Positions
    592594 */
    593 void Element2D::softReparent2D(const char* parentName, float bias)
     595void Element2D::setParentSoft2D(const char* parentName, float bias)
    594596{
    595597  Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D));
    596598  if (parentNode != NULL)
    597     this->softReparent2D(parentNode, bias);
     599    this->setParentSoft2D(parentNode, bias);
    598600}
    599601
     
    852854
    853855
    854 
    855856///////////////////
    856857// NullElement2D //
  • trunk/src/lib/graphics/render2D/element_2d.h

    r5378 r5382  
    155155    Element2D* getParent () const { return this->parent; };
    156156
    157     void softReparent2D(Element2D* parentNode, float bias = 1.0);
    158     void softReparent2D(const char* parentName, float bias = 1.0);
     157    void setParentSoft2D(Element2D* parentNode, float bias = 1.0);
     158    void setParentSoft2D(const char* parentName, float bias = 1.0);
    159159
    160160    /** @param parentMode sets the parentingMode of this Node */
     
    207207    Vector                  lastAbsCoordinate;  //!< this is used for speedcalculation, it stores the last coordinate
    208208    float                   prevRelDirection;   //!< The last Relative Direciton from the last update-Cycle.
    209 //  float                   lastAbsDirection;
    210209
    211210    Vector                  velocity;           //!< Saves the velocity.
    212211
    213     Vector*                 toCoordinate;       //!< a position to which to iterate. (This is used in conjunction with softReparent.and set*CoorSoft)
    214     float*                  toDirection;        //!< a direction to which to iterate. (This is used in conjunction with softReparent and set*DirSoft)
     212    Vector*                 toCoordinate;       //!< a position to which to iterate. (This is used in conjunction with setParentSoft.and set*CoorSoft)
     213    float*                  toDirection;        //!< a direction to which to iterate. (This is used in conjunction with setParentSoft and set*DirSoft)
    215214    float                   bias;               //!< how fast to iterate to the given position (default is 1)
    216215
  • trunk/src/lib/graphics/render2D/render_2d.cc

    r5318 r5382  
    6666void Render2D::registerElement2D(Element2D* element2D)
    6767{
    68   this->element2DList[(int)log2(E2D_DEFAULT_LAYER)]->add(element2D);
     68  if (likely(element2D != NULL))
     69    this->element2DList[(int)log2(E2D_DEFAULT_LAYER)]->add(element2D);
    6970}
     71
    7072
    7173/**
     
    8890void Render2D::moveToLayer(Element2D* element2D, E2D_LAYER to)
    8991{
     92  if (element2D == NULL)
     93    return;
     94
     95  if (unlikely(pow(2, E2D_LAYER_COUNT ) > to))
     96    to = E2D_DEFAULT_LAYER;
    9097  if (element2D->getLayer() != to)
    9198  {
  • trunk/src/lib/shell/shell.cc

    r5377 r5382  
    364364    2:
    365365  */
    366     lastText->setRelDir2D(-90);
    367     lastText->setRelDirSoft2D(0, 10);
     366    lastText->setRelDir2D(-360);
     367    lastText->setRelDirSoft2D(0, 5);
    368368    lastText->setRelCoor2D(this->calculateLinePosition(0)- Vector(-1000,0,0));
    369369    lastText->setRelCoorSoft2D(this->calculateLinePosition(0),10);
  • trunk/src/world_entities/camera.cc

    r5357 r5382  
    120120    case VIEW_NORMAL:
    121121      this->toFovy = 60.0;
    122       this->softReparent("TrackNode");
    123       this->target->softReparent("TrackNode");
     122      this->setParentSoft("TrackNode");
     123      this->target->setParentSoft("TrackNode");
    124124      this->setRelCoorSoft(-10, 5, 0);
    125125      this->target->setRelCoorSoft(0,0,0);
     
    131131
    132132      if (!strcmp(this->target->getParent()->getName(), "Player"))
    133         this->target->softReparent("TrackNode");
     133        this->target->setParentSoft("TrackNode");
    134134      else
    135         this->target->softReparent("Player");
     135        this->target->setParentSoft("Player");
    136136      this->getParent()->debug(0);
    137137
    138138//      this->setParent("main-Turret");
    139139//      this->setParentMode(PNODE_ALL);
    140 //      this->target->softReparent("Player");
     140//      this->target->setParentSoft("Player");
    141141
    142142      break;
    143143    case VIEW_FRONT:
    144144      this->toFovy = 120.0;
    145        this->softReparent("Player");
    146        this->target->softReparent("Player");
     145       this->setParentSoft("Player");
     146       this->target->setParentSoft("Player");
    147147       this->setRelCoorSoft(4, 0, 0, 5);
    148148       this->target->setRelCoorSoft(Vector(10,0,0), 5);
     
    151151    case VIEW_LEFT:
    152152      this->toFovy = 90;
    153       this->softReparent("TrackNode");
    154       this->target->softReparent("TrackNode");
     153      this->setParentSoft("TrackNode");
     154      this->target->setParentSoft("TrackNode");
    155155      this->setRelCoorSoft(0, 1, -10, .5);
    156156      this->target->setRelCoorSoft(0,0,0);
     
    158158    case VIEW_RIGHT:
    159159      this->toFovy = 90;
    160       this->softReparent("TrackNode");
    161       this->target->softReparent("TrackNode");
     160      this->setParentSoft("TrackNode");
     161      this->target->setParentSoft("TrackNode");
    162162      this->setRelCoorSoft(Vector(0, 1, 10));
    163163      this->target->setRelCoorSoft(0,0,0);
     
    165165    case VIEW_TOP:
    166166      this->toFovy= 120;
    167       this->softReparent("TrackNode");
    168       this->target->softReparent("TrackNode");
     167      this->setParentSoft("TrackNode");
     168      this->target->setParentSoft("TrackNode");
    169169      this->setRelCoorSoft(Vector(0, 10, 0));
    170170      this->target->setRelCoorSoft(0,0,0);
     
    215215  // switching back to Modeling Matrix
    216216  glMatrixMode (GL_MODELVIEW);
    217 //  this->target->getParent()->getParent()->debugDraw(0, 2, Vector(1,0,0));
     217  this->target->getParent()->getParent()->debugDraw(0, 2, Vector(1,0,0));
    218218}
    219219
  • trunk/src/world_entities/weapons/test_gun.cc

    r5357 r5382  
    6262  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
    6363  //parent->addChild(this->objectComponent1, PNODE_ALL);
    64   this->addChild(this->objectComponent1, PNODE_ALL);
     64  this->addChild(this->objectComponent1);
    6565
    6666  animation1->setInfinity(ANIM_INF_CONSTANT);
Note: See TracChangeset for help on using the changeset viewer.