Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3348 in orxonox.OLD for orxonox/branches/parenting


Ignore:
Timestamp:
Jan 6, 2005, 3:03:54 AM (20 years ago)
Author:
bensch
Message:

orxonox/branches/parenting: fixed major flaw in BezierCurve-calculation. before all BezierCurves started in the Origin. Now they are realy bezier-curves.

Location:
orxonox/branches/parenting/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/parenting/src/curve.cc

    r3330 r3348  
    2424#include "curve.h"
    2525#include "matrix.h"
     26#include "debug.h"
    2627
    2728#include <math.h>
     
    113114
    114115  // rebuilding the Curve itself
    115   int k=0;
    116   int binCoef = 1;
    117   while(tmpNode)
    118     {
    119       if (k+1 < nodeCount-k)
    120         binCoef *=(nodeCount-k)/(k+1);
    121       else
    122         binCoef /= (k+1)/(nodeCount-k);
    123       ++k;
     116  float k=0;
     117  float n = nodeCount -1;
     118  float binCoef = 1;
     119  printf("n=%f\n", n);
     120  while(tmpNode)
     121    {
    124122      tmpNode->factor = binCoef;
    125       tmpNode = tmpNode->next;
     123      printf("bincoef: %f\n", binCoef);
     124      if (tmpNode =tmpNode->next)
     125        {
     126          binCoef *=(n-k)/(k+1);
     127          ++k;
     128        }
    126129    }
    127130
     
    149152   \param t The position on the Curve (0<=t<=1)
    150153   \return the Position on the Path
     154   \todo implement nodeCount 0,1,2,3
    151155*/
    152156Vector BezierCurve::calcPos(float t)
    153157{
    154   if (nodeCount <=4)
     158  if (nodeCount < 4)
    155159    {
    156160      //    if (verbose >= 1)
     
    160164  PathNode* tmpNode = firstNode;
    161165  Vector ret = Vector(0.0,0.0,0.0);
    162   float factor = 1.0*pow(1.0-t,nodeCount);
    163   while(tmpNode)
    164     {
    165       factor *= t/(1.0-t); // same as pow but much faster.
     166  double factor = pow(1.0-t,nodeCount-1);
     167  while(tmpNode)
     168    {
    166169      ret.x += tmpNode->factor * factor * tmpNode->position.x;
    167170      ret.y += tmpNode->factor * factor * tmpNode->position.y;
    168171      ret.z += tmpNode->factor * factor * tmpNode->position.z;
     172      factor *= t/(1.0-t); // same as pow but much faster.
    169173
    170174      tmpNode = tmpNode->next;
  • orxonox/branches/parenting/src/track_manager.cc

    r3335 r3348  
    3535  this->ID = -1;
    3636  this->startingTime = 0; //!< \todo eventually set this to the max time of TrackManager.
    37   this->duration =0;
     37  this->duration = 1;
    3838  this->curveType = BEZIERCURVE;
    3939  this->nodeCount = 0;
    40   childCount = 0;
     40  this->childCount = 0;
    4141  this->name = NULL;
    4242  this->curve = NULL;
     
    102102
    103103  PRINTF(3)("Initializing the TrackManager\n");
    104   this->firstTrackElem = new TrackElement;
     104  this->firstTrackElem = new TrackElement();
     105  this->firstTrackElem->ID = 1;
    105106  this->currentTrackElem = firstTrackElem;
    106107  this->localTime = 0;
    107108  this->maxTime = 0;
    108   this->trackElemCount = 0;
     109  this->trackElemCount = 1;
    109110}
    110111
     
    146147void TrackManager::initChildren(unsigned int childCount)
    147148{
    148   trackElemCount = 0;
    149149  this->currentTrackElem->childCount = childCount;
    150150  this->currentTrackElem->children = new TrackElement*[childCount];
    151151  for (int i=0; i<childCount; i++)
    152     this->currentTrackElem->children[i] = new TrackElement();
     152    {
     153      this->currentTrackElem->children[i] = new TrackElement();
     154      this->currentTrackElem->children[i]->ID = ++trackElemCount;
     155      this->currentTrackElem->children[i]->startingTime = this->currentTrackElem->startingTime+this->currentTrackElem->duration;
     156    }
    153157}
    154158
     
    252256
    253257  this->initChildren(1);
     258  this->currentTrackElem = this->currentTrackElem->children[0];
    254259}
    255260
     
    344349Vector TrackManager::calcPos() const
    345350{
    346   return this->currentTrackElem->curve->calcPos(this->localTime);
     351  //  PRINTF(0)("TrackElement:%d, localTime: %f\n",this->currentTrackElem->ID, this->localTime);
     352  return this->currentTrackElem->curve->calcPos((this->localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration);
    347353}
    348354
     
    353359Vector TrackManager::calcDir() const
    354360{
    355   return this->currentTrackElem->curve->calcDir(this->localTime);
     361  return this->currentTrackElem->curve->calcDir((this->localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration);
    356362}
    357363
     
    364370void TrackManager::tick(float dt)
    365371{
     372  if (this->localTime <= this->firstTrackElem->duration)
     373    this->jumpTo(this->localTime);
    366374  this->localTime += dt;
     375  if (this->localTime > this->currentTrackElem->startingTime + this->currentTrackElem->duration && this->currentTrackElem->childCount > 0)
     376    this->currentTrackElem = this->currentTrackElem->children[0];
    367377}
    368378
     
    376386void TrackManager::jumpTo(float time)
    377387{
    378   localTime = time;
     388  if (time == 0)
     389    this->currentTrackElem = this->firstTrackElem;
     390  this->localTime = time;
    379391}
    380392
  • orxonox/branches/parenting/src/world.cc

    r3345 r3348  
    220220void World::load()
    221221{
     222  //  BezierCurve* tmpCurve = new BezierCurve();
    222223  if(this->debugWorldNr != -1)
    223224    {
    224225      trackManager = TrackManager::getInstance();
     226      trackManager->addPoint(Vector(0,-5,0));
     227      trackManager->addPoint(Vector(10,0,5));
     228      trackManager->addPoint(Vector(20,0,-5));
     229      trackManager->addPoint(Vector(30,0,5));
     230      trackManager->addPoint(Vector(40,0,5));
     231      trackManager->setDuration(.5);
     232      trackManager->setSavePoint();
     233      trackManager->addPoint(Vector(50,10,10));
     234      trackManager->addPoint(Vector(60,0, 10));
     235      trackManager->addPoint(Vector(70,0, 10));
     236      trackManager->addPoint(Vector(80,0,-10));
     237      trackManager->addPoint(Vector(90,0,-10));
     238      trackManager->setDuration(.5);
     239     
     240      /*
     241      tmpCurve->addNode(Vector(10,0,-10));
     242      tmpCurve->addNode(Vector(10,2,5));
     243      tmpCurve->addNode(Vector(10,3,-5));
     244      tmpCurve->addNode(Vector(10,1,5));
     245      tmpCurve->addNode(Vector(10,0,5));
     246      */
    225247      switch(this->debugWorldNr)
    226248        {
     
    526548    }
    527549  glEnd();
    528 
     550  float i;
     551  glBegin(GL_LINES);
     552  for(i = 0.0; i<1; i+=.01)
     553    {
     554      trackManager->tick (.01);
     555      printf("%f, %f, %f\n",trackManager->calcPos().x, trackManager->calcPos().y, trackManager->calcPos().z);
     556      glVertex3f(trackManager->calcPos().x, trackManager->calcPos().y, trackManager->calcPos().z);
     557    }
     558  /*
     559  for(i = 0.0; i<1; i+=.01)
     560    {
     561      printf("%f, %f, %f\n",tmpCurve->calcPos(i).x, tmpCurve->calcPos(i).y, tmpCurve->calcPos(i).z);
     562      glVertex3f(tmpCurve->calcPos(i).x, tmpCurve->calcPos(i).y, tmpCurve->calcPos(i).z);
     563    }
     564  */
     565  glEnd();
    529566  glEndList();
    530567}
Note: See TracChangeset for help on using the changeset viewer.