Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3433 in orxonox.OLD for orxonox/trunk/src/track_manager.cc


Ignore:
Timestamp:
Mar 1, 2005, 2:36:56 PM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: merged back the trackManager to the trunk.
merged with command:
svn merge -r 3369:HEAD branches/trackManager trunk
resolved conflicts in world.cc additive differences.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/track_manager.cc

    r3365 r3433  
    1 
    2 
    31/*
    42   orxonox - the future of 3D-vertical-scrollers
     
    1210
    1311   ### File Specific:
    14    main-programmer: Patrick Boenzli
     12   main-programmer: Benjamin Grauer
    1513   co-programmer: ...
    1614*/
     
    1917#include "track_manager.h"
    2018#include <stdarg.h>
    21 
     19#include "p_node.h"
    2220
    2321using namespace std;
     
    3836  this->startingTime = 0; //!< \todo eventually set this to the max time of TrackManager.
    3937  this->duration = 1;
     38  this->endTime = 1;
     39  this->jumpTime = 0;
    4040  this->curveType = BEZIERCURVE;
    4141  this->nodeCount = 0;
    4242  this->childCount = 0;
    4343  this->name = NULL;
    44   this->startPoint = Vector(0,0,0);
    45   this->startTangentPoint = Vector(0,0,0);
    4644  this->curve = NULL;
    4745  this->children = NULL;
     
    111109  this->maxTime = 0;
    112110  this->trackElemCount = 1;
     111  this->bindSlave = NULL;
    113112}
    114113
     
    151150{
    152151  this->currentTrackElem->childCount = childCount;
     152  this->currentTrackElem->mainJoin = true;
    153153  this->currentTrackElem->children = new TrackElement*[childCount];
    154154  for (int i=0; i<childCount; i++)
     
    156156      this->currentTrackElem->children[i] = new TrackElement();
    157157      this->currentTrackElem->children[i]->ID = ++trackElemCount;
    158       this->currentTrackElem->children[i]->startingTime = this->currentTrackElem->startingTime+this->currentTrackElem->duration;
    159       this->currentTrackElem->children[i]->startPoint = this->currentTrackElem->curve->getNode(this->currentTrackElem->curve->getNodeCount());
    160       this->currentTrackElem->children[i]->startTangentPoint = (this->currentTrackElem->children[i]->startPoint *2) - this->currentTrackElem->curve->getNode(this->currentTrackElem->curve->getNodeCount()-1);
     158      this->currentTrackElem->children[i]->startingTime = this->currentTrackElem->endTime + this->currentTrackElem->jumpTime;
     159      this->addPoint(this->currentTrackElem->curve->getNode(this->currentTrackElem->curve->getNodeCount()), this->currentTrackElem->children[i]);
    161160    }
    162161}
     
    193192   \brief curveType The Type to set
    194193*/
    195 void TrackManager::setCurveType(CurveType curveType)
    196 {
    197   if (!this->currentTrackElem->isFresh)
     194void TrackManager::setCurveType(CurveType curveType, TrackElement* trackElem)
     195{
     196  if (!trackElem->isFresh)
    198197    {
    199198      PRINTF(2)("It is not possible to change the type of a Curve after you have have appended some points to it\n");
    200199      return;
    201200    }
    202   this->currentTrackElem->curveType = curveType;
     201  trackElem->curveType = curveType;
    203202  switch (curveType)
    204203    {
    205204    case BEZIERCURVE:
    206       this->currentTrackElem->curve = new BezierCurve();
     205      trackElem->curve = new BezierCurve();
    207206      break;
    208207    case UPOINTCURVE:
    209       this->currentTrackElem->curve = new UPointCurve();
     208      trackElem->curve = new UPointCurve();
    210209      break;
    211210    }
     
    220219{
    221220  this->currentTrackElem->duration = time;
     221  this->currentTrackElem->endTime = this->currentTrackElem->startingTime + time;
    222222}
    223223
     
    240240  if (trackElem->isFresh)
    241241    {
    242       this->setCurveType(BEZIERCURVE);
     242      this->setCurveType(BEZIERCURVE, trackElem);
    243243      trackElem->isFresh = false;
    244       if(trackElem != this->firstTrackElem)
    245         {
    246           this->addPoint(trackElem->startPoint);
    247           this->addPoint(trackElem->startTangentPoint);
    248         }
    249244    }
    250245  trackElem->curve->addNode(newPoint);
     
    374369void TrackManager::joinV(unsigned int count, int* trackIDs)
    375370{
    376   printf("Joining %d tracks to Track %d\n", count, trackIDs[0]);
     371  printf("Joining %d tracks and merging to Track %d\n", count, trackIDs[0]);
    377372
    378373  // chanching work-on to temporary value. going back at the end.
    379374  int tmpCurrentWorkingID = this->currentTrackElem->ID;
    380375  this->workOn(trackIDs[0]);
    381 
    382376  TrackElement* firstJoint = this->currentTrackElem;
     377  float tmpLatestTime = firstJoint->endTime;
     378
    383379  Vector tmpEndPoint = firstJoint->curve->getNode(firstJoint->curve->getNodeCount());
    384   Vector tmpTangentPoint = firstJoint->curve->getNode(firstJoint->curve->getNodeCount()-1);
     380  Vector tmpTangentPoint = firstJoint->curve->getNode(firstJoint->curve->getNodeCount()-1);
     381  Vector tmpc2Point = firstJoint->curve->getNode(firstJoint->curve->getNodeCount()-2);
    385382  firstJoint->isJoined = true;
    386   firstJoint->mainJoin = true;
     383  //  firstJoint->mainJoin = true;
    387384  if(!firstJoint->isHotPoint)
    388385    this->setSavePoint();
    389 
     386  // Timing:
     387  for (int i = 0; i < count; i++)
     388    {
     389      TrackElement* tmpJoinElem = this->findTrackElementByID(trackIDs[i]);
     390      if (tmpJoinElem->childCount == 0
     391          && tmpJoinElem->endTime > tmpLatestTime)
     392        tmpLatestTime = tmpJoinElem->endTime;
     393    }
     394  // time the main Join.
     395  firstJoint->jumpTime = tmpLatestTime - firstJoint->endTime;
     396 
     397  // Joining:
    390398  for (int i = 1; i < count; i++)
    391399    {
     
    395403      else
    396404        {
     405          this->addPoint(tmpc2Point, tmpJoinElem);
    397406          this->addPoint(tmpTangentPoint, tmpJoinElem);
    398407          this->addPoint(tmpEndPoint, tmpJoinElem);
     408          // time all other Joins
     409          tmpJoinElem->jumpTime = tmpLatestTime - tmpJoinElem->endTime;
    399410         
    400411          //Copying Joint-Info
     
    403414          tmpJoinElem->isSavePoint = firstJoint->isSavePoint;
    404415          tmpJoinElem->isFork = firstJoint->isFork;
    405          
     416
    406417          tmpJoinElem->isJoined = true;
    407418        }
    408419    }
     420  if(firstJoint->childCount > 0)
     421    for(int i = 0; i < firstJoint->childCount; i++)
     422      {
     423        printf("Setting startingTime of %d to %f.\n", firstJoint->children[i]->ID, tmpLatestTime);
     424        firstJoint->children[i]->startingTime = tmpLatestTime;
     425        firstJoint->children[i]->endTime = tmpLatestTime+firstJoint->children[i]->duration;
     426      }
     427
    409428  // returning to the TrackElement we were working on.
    410429  this->workOn(tmpCurrentWorkingID);
    411430}
    412431
     432/**
     433   \brief finalizes the TrackSystem. after this it will not be editable anymore
     434
     435   \todo check for any inconsistencies, output errors
     436*/
     437void TrackManager::finalize(void)
     438{
     439  for (int i = 1; i<= trackElemCount ;i++)
     440    {
     441      TrackElement* tmpElem = findTrackElementByID(i);
     442      if (tmpElem->childCount>0 && tmpElem->mainJoin)
     443        {
     444          for (int j = 0; j < tmpElem->childCount; j++)
     445            {
     446             
     447              // c1-continuity
     448              tmpElem->children[j]->curve->addNode(tmpElem->children[j]->curve->getNode(0) +
     449                                                   ((tmpElem->children[j]->curve->getNode(0) -
     450                                                    tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1))
     451                                                    ),2);
     452              tmpElem->children[j]->nodeCount++;
     453              // c2-continuity
     454              tmpElem->children[j]->curve->addNode((tmpElem->curve->getNode(tmpElem->curve->getNodeCount())-
     455                                                    tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1)) * 4 +
     456                                                   tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-2), 3);
     457              tmpElem->children[j]->nodeCount++;                                                   
     458              printf("accelerations: %d-in: count: %d, %f, %f, %f\n                  %d-out: count: %d %f, %f, %f\n",
     459                     tmpElem->ID, tmpElem->nodeCount,
     460                     tmpElem->curve->calcAcc(0.999).x, tmpElem->curve->calcAcc(0.999).y, tmpElem->curve->calcAcc(0.999).z,
     461                     tmpElem->children[j]->ID, tmpElem->children[j]->nodeCount,
     462                     tmpElem->children[j]->curve->calcAcc(0).x, tmpElem->children[j]->curve->calcAcc(0).y, tmpElem->children[j]->curve->calcAcc(0).z);
     463            }
     464        }
     465    }
     466}
     467
     468
    413469// RUNTIME //
    414470
     
    429485Vector TrackManager::calcDir() const
    430486{
    431   return this->currentTrackElem->curve->calcDir((this->localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration);
     487  return this->currentTrackElem->curve->calcDir((this->localTime - this->currentTrackElem->startingTime)/this->currentTrackElem->duration);
    432488}
    433489
     
    440496void TrackManager::tick(float dt)
    441497{
     498  dt /= 1000;
     499  printf("CurrentTrackID: %d, LocalTime is: %f, timestep is: %f\n", this->currentTrackElem->ID, this->localTime, dt);
    442500  if (this->localTime <= this->firstTrackElem->duration)
    443501    this->jumpTo(this->localTime);
    444502  this->localTime += dt;
    445   if (this->localTime > this->currentTrackElem->startingTime + this->currentTrackElem->duration && this->currentTrackElem->childCount > 0)
    446     this->currentTrackElem = this->currentTrackElem->children[0];
     503  if (this->localTime > this->currentTrackElem->endTime
     504      && this->currentTrackElem->children)
     505    {
     506      if (this->currentTrackElem->jumpTime > 0)
     507        this->jumpTo(this->localTime + this->currentTrackElem->jumpTime);
     508      this->currentTrackElem = this->currentTrackElem->children[0];
     509    }
     510  if (this->bindSlave)
     511    {
     512      Vector tmp = this->calcPos();
     513      Quaternion quat = Quaternion(this->calcDir(), Vector(this->currentTrackElem->curve->calcAcc((localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration).x,1,this->currentTrackElem->curve->calcAcc((localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration).z));
     514      this->bindSlave->setAbsCoor(&tmp);
     515      this->bindSlave->setAbsDir(&quat);
     516    }
    447517}
    448518
     
    471541}
    472542
     543/**
     544   \brief Sets the PNode, that should be moved along the Tack
     545   \param bindSlave the PNode to set
     546*/
     547void TrackManager::setBindSlave(PNode* bindSlave)
     548{
     549  if (!this->bindSlave)
     550    this->bindSlave = bindSlave;
     551}
    473552
    474553
     
    500579}
    501580
     581/**
     582   \brief outputs debug information about the trackManager
     583   \param level how much debug
     584*/
    502585void TrackManager::debug(unsigned int level) const
    503586{
     
    516599          if(tmpElem->isFresh)
    517600            printf("   has not jet eddited in any way\n");
    518           printf("\n   TimeTable: starting at = %f; ends at = %f; duration = %f\n", tmpElem->startingTime, tmpElem->startingTime+tmpElem->duration, tmpElem->duration);
     601          printf("\n   TimeTable: startingTime=%f; endTime=%f; duration=%f; jumpTime=%f\n", tmpElem->startingTime, tmpElem->endTime, tmpElem->duration, tmpElem->jumpTime);
    519602          printf("   consists of %d Points\n", tmpElem->nodeCount);
    520603          if (tmpElem->childCount == 0)
     
    536619          if(tmpElem->isFork)
    537620            {
    538               printf("    is A Fork with with %d children.", tmpElem->childCount);
     621              printf("    is A Fork with with %d children.\n", tmpElem->childCount);
    539622            }
    540623          if(tmpElem->isJoined)
Note: See TracChangeset for help on using the changeset viewer.