Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4987 in orxonox.OLD for orxonox/trunk/src


Ignore:
Timestamp:
Aug 12, 2005, 4:12:15 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: introducing smooth-PNode

Location:
orxonox/trunk/src
Files:
5 edited

Legend:

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

    r4955 r4987  
    111111  this->bAbsDirChanged = false;
    112112  this->parent = parent;
     113
     114  this->toPosition = NULL;
    113115}
    114116
     
    179181}
    180182
     183void PNode::setRelCoorSoft(const Vector& relCoordSoft)
     184{
     185  if (likely(this->toPosition == NULL))
     186    this->toPosition = new Vector();
     187
     188  *this->toPosition = relCoordSoft;
     189
     190  this->toPosition->debug();
     191  printf("=-==============\n");
     192}
     193
    181194/**
    182195 * @param absCoord set absolute coordinate
     
    196209 * @param y y-coordinate.
    197210 * @param z z-coordinate.
    198  * \see void PNode::setAbsCoor (const Vector& absCoord)
     211 * @see void PNode::setAbsCoor (const Vector& absCoord)
    199212 */
    200213void PNode::setAbsCoor(float x, float y, float z)
     
    221234
    222235   yea right... shorter...
     236 *
     237 * @todo this is ambiguous, from the outside one does not know it absCoor has been changed
     238 * this might lead to strange artefacts !!
    223239
    224240*/
     
    404420    parentNode->addChild(this);
    405421}
     422
     423void PNode::softReparent(PNode* parentNode)
     424{
     425  if (likely(this->toPosition == NULL))
     426    this->toPosition = new Vector();
     427
     428  *this->toPosition = parentNode->getAbsCoor() + this->getRelCoor();
     429
     430  Vector tmp = this->getAbsCoor();
     431
     432  parentNode->addChild(this);
     433
     434  this->setRelCoor(tmp - parentNode->getAbsCoor());
     435}
     436
     437void PNode::softReparent(const char* parentName)
     438{
     439  PNode* parentNode = dynamic_cast<PNode*>(ClassList::getObject(parentName, CL_PARENT_NODE));
     440  if (parentNode != NULL)
     441    this->softReparent(parentNode);
     442}
     443
    406444
    407445/**
     
    456494void PNode::update (float dt)
    457495{
     496
     497
    458498  if( likely(this->parent != NULL))
    459499    {
     500      // movement for nodes with smoothMove enabled
     501      if (unlikely(this->toPosition != NULL))
     502      {
     503        Vector moveVect = (*this->toPosition - this->getRelCoor()) *dt;
     504
     505        if (likely(moveVect.len() >= .001))
     506        {
     507          this->shiftCoor(moveVect);
     508          moveVect.debug();
     509        }
     510        else
     511        {
     512          delete this->toPosition;
     513          this->toPosition = NULL;
     514          PRINTF(0)("SmoothMove of %s finished\n", this->getName());
     515        }
     516      }
     517
    460518      this->lastAbsCoordinate = this->absCoordinate;
    461519
    462       PRINTF(4)("PNode::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
    463 
     520      PRINTF(5)("PNode::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
    464521
    465522      if( likely(this->parentMode & PNODE_MOVEMENT))
    466523        {
    467           if( unlikely(this->bAbsCoorChanged) /*&& this->timeStamp != DataTank::timeStamp*/)
     524          if( unlikely(this->bAbsCoorChanged))
    468525            {
    469526              /* if you have set the absolute coordinates this overrides all other changes */
    470527              this->relCoordinate = this->absCoordinate - parent->getAbsCoor ();
    471528            }
    472           if( likely(this->bRelCoorChanged) /*&& this->timeStamp != DataTank::timeStamp*/)
    473 
     529          if( likely(this->bRelCoorChanged))
    474530            {
    475               /*this is bad style... must be deleted later - just for testing*/
    476 
    477               /*
    478                 if( unlikely(this->parent == NULL))
    479                 {
    480                 *this->absCoordinate = *this->relCoordinate;
    481                 }
    482                 else */
    483               this->absCoordinate = parent->getAbsCoor() + this->relCoordinate;       /* update the current absCoordinate */
     531              /* update the current absCoordinate */
     532              this->absCoordinate = parent->getAbsCoor() + this->relCoordinate;
    484533            }
    485534        }
     
    487536      if( this->parentMode & PNODE_LOCAL_ROTATE)
    488537        {
    489           if( unlikely(this->bAbsDirChanged) /*&& this->timeStamp != DataTank::timeStamp*/)
     538          if( unlikely(this->bAbsDirChanged))
    490539            {
    491540              /* if you have set the absolute coordinates this overrides all other changes */
    492541              this->relDirection = this->absDirection - parent->getAbsDir();
    493542            }
    494           else if( likely(this->bRelDirChanged) /*&& this->timeStamp != DataTank::timeStamp*/)
     543          else if( likely(this->bRelDirChanged))
    495544            {
    496545              /* update the current absDirection - remember * means rotation around sth.*/
     
    501550      if( this->parentMode & PNODE_ROTATE_MOVEMENT)
    502551        {
    503           if( unlikely(this->bAbsCoorChanged) /*&& this->timeStamp != DataTank::timeStamp*/)
     552          if( unlikely(this->bAbsCoorChanged))
    504553            {
    505554              /* if you have set the absolute coordinates this overrides all other changes */
    506555              this->relCoordinate = this->absCoordinate - parent->getAbsCoor ();
    507556            }
    508           else if( likely(this->bRelCoorChanged) /*&& this->timeStamp != DataTank::timeStamp*/)
     557          else if( likely(this->bRelCoorChanged))
    509558            {
    510               /*this is bad style... must be deleted later - just for testing*/
    511               /*if( this->parent == NULL)
    512                *this->absCoordinate = *this->relCoordinate;
    513                else*/
    514               this->absCoordinate = parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate);            /* update the current absCoordinate */
     559              /* update the current absCoordinate */
     560              this->absCoordinate = parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate);
    515561            }
    516562        }
     
    518564
    519565      tIterator<PNode>* iterator = this->children->getIterator();
    520       //PNode* pn = this->children->enumerate();
    521566      PNode* pn = iterator->nextElement();
    522567      while( pn != NULL)
  • orxonox/trunk/src/lib/coord/p_node.h

    r4966 r4987  
    6262  void setRelCoor (const Vector& relCoord);
    6363  void setRelCoor (float x, float y, float z);
     64  void setRelCoorSoft(const Vector& softRelCoord);
    6465  /** @returns the relative position */
    6566  inline const Vector& getRelCoor () const { return this->relCoordinate; };
     
    9697
    9798  void setParent (PNode* parent);
    98   void setParent (const char* name);
     99  void setParent (const char* parentName);
    99100  /** @returns the parent of this PNode */
    100101  PNode* getParent () const { return this->parent; };
     102
     103  void softReparent(PNode* parentNode);
     104  void softReparent(const char* parentName);
    101105
    102106  void setParentMode (PARENT_MODE parentMode);
     
    112116 private:
    113117  void init(PNode* parent);
    114   /** \brief tells the child that the parent's Coordinate has changed */
     118  /** tells the child that the parent's Coordinate has changed */
    115119  inline void parentCoorChanged () { this->bRelCoorChanged = true; }
    116   /** \brief tells the child that the parent's Direction has changed */
     120  /** tells the child that the parent's Direction has changed */
    117121  inline void parentDirChanged () { this->bRelDirChanged = true; }
    118122  /** @returns the last calculated coordinate */
     
    134138  Vector          lastAbsCoordinate;  //!< this is used for speedcalculation, it stores the last coordinate
    135139
     140
     141  Vector*         toPosition;         //!< a position to wich to iterate. (This is used in conjunction with softReparent.)
     142
    136143  PNode*          parent;             //!< a pointer to the parent node
    137   tList<PNode>*   children;           //!< list of the children
     144  tList<PNode>*   children;           //!< list of the children of this PNode
    138145
    139146  unsigned int    parentMode;         //!< the mode of the binding
  • orxonox/trunk/src/lib/math/vector.cc

    r4966 r4987  
    5656void Vector::debug() const
    5757{
    58   PRINT(0)("Vector Debug information\n");
    5958  PRINT(0)("x: %f; y: %f; z: %f", x, y, z);
    60   PRINT(3)(" lenght: %f", len());
     59  PRINT(0)(" lenght: %f", len());
    6160  PRINT(0)("\n");
    6261}
  • orxonox/trunk/src/world_entities/camera.cc

    r4986 r4987  
    3636{
    3737  this->setClassID(CL_CAMERA, "Camera");
     38  this->setName("camera");
    3839  this->target = new CameraTarget();
    3940
     
    5051
    5152  this->setViewMode(VIEW_NORMAL);
     53
     54  this->setParentMode(PNODE_MOVEMENT);
    5255}
    5356
     
    116119    case VIEW_NORMAL:
    117120      this->toFovy = 60.0;
    118       this->toRelCoor = Vector(-10, 5, 0);
     121      this->setRelCoorSoft(Vector(-10, 5, 0));
     122      this->target->setRelCoorSoft(Vector(0,0,0));
    119123      break;
    120124    case VIEW_BEHIND:
    121       this->toFovy = 120.0;
    122       this->toRelCoor = Vector(3.5, 0, 0);
    123       this->target->setRelCoor(4,0,0);
    124 /*      this->setParent("main-Turret");
     125//      this->toFovy = 120.0;
     126      this->setRelCoorSoft(Vector(3.5, 0, 0));
     127      this->target->setRelCoorSoft(Vector(10,0,0));
     128
     129      /*this->target->softReparent("main-Turret");
     130      this->setParent("main-Turret");
    125131      this->setParentMode(PNODE_ALL);
    126132      this->target->setParent("Crosshair");*/
     
    128134    case VIEW_FRONT:
    129135      this->toFovy = 95.0;
    130       this->toRelCoor = Vector(12, 5, 0);
     136      this->setRelCoorSoft(Vector(10, 2, 0));
     137      this->target->setRelCoorSoft(Vector(0,0,0));
    131138      break;
    132139    case VIEW_LEFT:
    133140      this->toFovy = 90;
    134       this->toRelCoor = Vector(0, 2, -10);
     141      this->setRelCoorSoft(Vector(0, 1, -10));
     142      this->target->setRelCoorSoft(Vector(0,0,0));
    135143      break;
    136144    case VIEW_RIGHT:
    137145      this->toFovy = 90;
    138       this->toRelCoor = Vector(0, 2, 10);
     146      this->setRelCoorSoft(Vector(0, 1, 10));
     147      this->target->setRelCoorSoft(Vector(0,0,0));
    139148      break;
    140149    case VIEW_TOP:
    141150      this->toFovy= 120;
    142       this->toRelCoor = Vector(0, 4, 0);
     151      this->setRelCoorSoft(Vector(0, 10, 0));
     152      this->target->setRelCoorSoft(Vector(0,0,0));
    143153    }
    144154}
     
    154164  if (tmpFovy > .001)
    155165    this->fovy += (this->toFovy - this->fovy) * dt;
    156   Vector tmpPos = (this->toRelCoor - this->getRelCoor()) * dt;
    157   if (tmpPos.len() >= .001)
    158     {
    159       tmpPos = tmpPos + this->getRelCoor();
    160       this->setRelCoor(tmpPos);
    161     }
    162166}
    163167
  • orxonox/trunk/src/world_entities/camera.h

    r4986 r4987  
    5757  float             farClip;         //!< The far clipping plane.
    5858
    59   Vector            toRelCoor;       //!< The relativeCoordinate to move the camera to.
    6059  float             toFovy;          //!< The fovy-mode to iterate to.
    6160};
Note: See TracChangeset for help on using the changeset viewer.