Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 11, 2005, 2:55:27 PM (19 years ago)
Author:
chris
Message:

orxonox/branches/levelloader: merged updated trunk structure into levelloader branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/levelloader/src/track_manager.cc

    r3365 r3499  
    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*/
     
    1816
    1917#include "track_manager.h"
     18
     19#include "p_node.h"
     20
    2021#include <stdarg.h>
    21 
    2222
    2323using namespace std;
     
    3838  this->startingTime = 0; //!< \todo eventually set this to the max time of TrackManager.
    3939  this->duration = 1;
     40  this->endTime = 1;
     41  this->jumpTime = 0;
    4042  this->curveType = BEZIERCURVE;
    4143  this->nodeCount = 0;
    4244  this->childCount = 0;
    4345  this->name = NULL;
    44   this->startPoint = Vector(0,0,0);
    45   this->startTangentPoint = Vector(0,0,0);
    4646  this->curve = NULL;
    4747  this->children = NULL;
     
    111111  this->maxTime = 0;
    112112  this->trackElemCount = 1;
     113  this->bindSlave = NULL;
    113114}
    114115
     
    151152{
    152153  this->currentTrackElem->childCount = childCount;
     154  this->currentTrackElem->mainJoin = true;
    153155  this->currentTrackElem->children = new TrackElement*[childCount];
    154156  for (int i=0; i<childCount; i++)
     
    156158      this->currentTrackElem->children[i] = new TrackElement();
    157159      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);
     160      this->currentTrackElem->children[i]->startingTime = this->currentTrackElem->endTime + this->currentTrackElem->jumpTime;
     161      this->addPoint(this->currentTrackElem->curve->getNode(this->currentTrackElem->curve->getNodeCount()), this->currentTrackElem->children[i]);
    161162    }
    162163}
     
    193194   \brief curveType The Type to set
    194195*/
    195 void TrackManager::setCurveType(CurveType curveType)
    196 {
    197   if (!this->currentTrackElem->isFresh)
     196void TrackManager::setCurveType(CurveType curveType, TrackElement* trackElem)
     197{
     198  if (!trackElem->isFresh)
    198199    {
    199200      PRINTF(2)("It is not possible to change the type of a Curve after you have have appended some points to it\n");
    200201      return;
    201202    }
    202   this->currentTrackElem->curveType = curveType;
     203  trackElem->curveType = curveType;
    203204  switch (curveType)
    204205    {
    205206    case BEZIERCURVE:
    206       this->currentTrackElem->curve = new BezierCurve();
     207      trackElem->curve = new BezierCurve();
    207208      break;
    208209    case UPOINTCURVE:
    209       this->currentTrackElem->curve = new UPointCurve();
     210      trackElem->curve = new UPointCurve();
    210211      break;
    211212    }
     
    220221{
    221222  this->currentTrackElem->duration = time;
     223  this->currentTrackElem->endTime = this->currentTrackElem->startingTime + time;
    222224}
    223225
     
    240242  if (trackElem->isFresh)
    241243    {
    242       this->setCurveType(BEZIERCURVE);
     244      this->setCurveType(BEZIERCURVE, trackElem);
    243245      trackElem->isFresh = false;
    244       if(trackElem != this->firstTrackElem)
    245         {
    246           this->addPoint(trackElem->startPoint);
    247           this->addPoint(trackElem->startTangentPoint);
    248         }
    249246    }
    250247  trackElem->curve->addNode(newPoint);
     
    374371void TrackManager::joinV(unsigned int count, int* trackIDs)
    375372{
    376   printf("Joining %d tracks to Track %d\n", count, trackIDs[0]);
     373  printf("Joining %d tracks and merging to Track %d\n", count, trackIDs[0]);
    377374
    378375  // chanching work-on to temporary value. going back at the end.
    379376  int tmpCurrentWorkingID = this->currentTrackElem->ID;
    380377  this->workOn(trackIDs[0]);
    381 
    382378  TrackElement* firstJoint = this->currentTrackElem;
     379  float tmpLatestTime = firstJoint->endTime;
     380
    383381  Vector tmpEndPoint = firstJoint->curve->getNode(firstJoint->curve->getNodeCount());
    384   Vector tmpTangentPoint = firstJoint->curve->getNode(firstJoint->curve->getNodeCount()-1);
     382  Vector tmpTangentPoint = firstJoint->curve->getNode(firstJoint->curve->getNodeCount()-1);
     383  Vector tmpc2Point = firstJoint->curve->getNode(firstJoint->curve->getNodeCount()-2);
    385384  firstJoint->isJoined = true;
    386   firstJoint->mainJoin = true;
     385  //  firstJoint->mainJoin = true;
    387386  if(!firstJoint->isHotPoint)
    388387    this->setSavePoint();
    389 
     388  // Timing:
     389  for (int i = 0; i < count; i++)
     390    {
     391      TrackElement* tmpJoinElem = this->findTrackElementByID(trackIDs[i]);
     392      if (tmpJoinElem->childCount == 0
     393          && tmpJoinElem->endTime > tmpLatestTime)
     394        tmpLatestTime = tmpJoinElem->endTime;
     395    }
     396  // time the main Join.
     397  firstJoint->jumpTime = tmpLatestTime - firstJoint->endTime;
     398 
     399  // Joining:
    390400  for (int i = 1; i < count; i++)
    391401    {
     
    395405      else
    396406        {
     407          this->addPoint(tmpc2Point, tmpJoinElem);
    397408          this->addPoint(tmpTangentPoint, tmpJoinElem);
    398409          this->addPoint(tmpEndPoint, tmpJoinElem);
     410          // time all other Joins
     411          tmpJoinElem->jumpTime = tmpLatestTime - tmpJoinElem->endTime;
    399412         
    400413          //Copying Joint-Info
     
    403416          tmpJoinElem->isSavePoint = firstJoint->isSavePoint;
    404417          tmpJoinElem->isFork = firstJoint->isFork;
    405          
     418
    406419          tmpJoinElem->isJoined = true;
    407420        }
    408421    }
     422  if(firstJoint->childCount > 0)
     423    for(int i = 0; i < firstJoint->childCount; i++)
     424      {
     425        printf("Setting startingTime of %d to %f.\n", firstJoint->children[i]->ID, tmpLatestTime);
     426        firstJoint->children[i]->startingTime = tmpLatestTime;
     427        firstJoint->children[i]->endTime = tmpLatestTime+firstJoint->children[i]->duration;
     428      }
     429
    409430  // returning to the TrackElement we were working on.
    410431  this->workOn(tmpCurrentWorkingID);
    411432}
    412433
     434/**
     435   \brief finalizes the TrackSystem. after this it will not be editable anymore
     436
     437   \todo check for any inconsistencies, output errors
     438*/
     439void TrackManager::finalize(void)
     440{
     441  for (int i = 1; i<= trackElemCount ;i++)
     442    {
     443      TrackElement* tmpElem = findTrackElementByID(i);
     444      if (tmpElem->childCount>0 && tmpElem->mainJoin)
     445        {
     446          for (int j = 0; j < tmpElem->childCount; j++)
     447            {
     448             
     449              // c1-continuity
     450              tmpElem->children[j]->curve->addNode(tmpElem->children[j]->curve->getNode(0) +
     451                                                   ((tmpElem->children[j]->curve->getNode(0) -
     452                                                    tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1))
     453                                                    ),2);
     454              tmpElem->children[j]->nodeCount++;
     455              // c2-continuity
     456              tmpElem->children[j]->curve->addNode((tmpElem->curve->getNode(tmpElem->curve->getNodeCount())-
     457                                                    tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1)) * 4 +
     458                                                   tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-2), 3);
     459              tmpElem->children[j]->nodeCount++;                                                   
     460              printf("accelerations: %d-in: count: %d, %f, %f, %f\n                  %d-out: count: %d %f, %f, %f\n",
     461                     tmpElem->ID, tmpElem->nodeCount,
     462                     tmpElem->curve->calcAcc(0.999).x, tmpElem->curve->calcAcc(0.999).y, tmpElem->curve->calcAcc(0.999).z,
     463                     tmpElem->children[j]->ID, tmpElem->children[j]->nodeCount,
     464                     tmpElem->children[j]->curve->calcAcc(0).x, tmpElem->children[j]->curve->calcAcc(0).y, tmpElem->children[j]->curve->calcAcc(0).z);
     465            }
     466        }
     467    }
     468}
     469
     470
    413471// RUNTIME //
    414472
     
    429487Vector TrackManager::calcDir() const
    430488{
    431   return this->currentTrackElem->curve->calcDir((this->localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration);
     489  return this->currentTrackElem->curve->calcDir((this->localTime - this->currentTrackElem->startingTime)/this->currentTrackElem->duration);
    432490}
    433491
     
    440498void TrackManager::tick(float dt)
    441499{
     500  dt /= 1000;
     501  printf("CurrentTrackID: %d, LocalTime is: %f, timestep is: %f\n", this->currentTrackElem->ID, this->localTime, dt);
    442502  if (this->localTime <= this->firstTrackElem->duration)
    443503    this->jumpTo(this->localTime);
    444504  this->localTime += dt;
    445   if (this->localTime > this->currentTrackElem->startingTime + this->currentTrackElem->duration && this->currentTrackElem->childCount > 0)
    446     this->currentTrackElem = this->currentTrackElem->children[0];
     505  if (this->localTime > this->currentTrackElem->endTime
     506      && this->currentTrackElem->children)
     507    {
     508      if (this->currentTrackElem->jumpTime > 0)
     509        this->jumpTo(this->localTime + this->currentTrackElem->jumpTime);
     510      this->currentTrackElem = this->currentTrackElem->children[0];
     511    }
     512  if (this->bindSlave)
     513    {
     514      Vector tmp = this->calcPos();
     515      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));
     516      this->bindSlave->setAbsCoor(&tmp);
     517      this->bindSlave->setAbsDir(&quat);
     518    }
    447519}
    448520
     
    471543}
    472544
     545/**
     546   \brief Sets the PNode, that should be moved along the Tack
     547   \param bindSlave the PNode to set
     548*/
     549void TrackManager::setBindSlave(PNode* bindSlave)
     550{
     551  if (!this->bindSlave)
     552    this->bindSlave = bindSlave;
     553}
    473554
    474555
     
    500581}
    501582
     583/**
     584   \brief outputs debug information about the trackManager
     585   \param level how much debug
     586*/
    502587void TrackManager::debug(unsigned int level) const
    503588{
     
    516601          if(tmpElem->isFresh)
    517602            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);
     603          printf("\n   TimeTable: startingTime=%f; endTime=%f; duration=%f; jumpTime=%f\n", tmpElem->startingTime, tmpElem->endTime, tmpElem->duration, tmpElem->jumpTime);
    519604          printf("   consists of %d Points\n", tmpElem->nodeCount);
    520605          if (tmpElem->childCount == 0)
     
    536621          if(tmpElem->isFork)
    537622            {
    538               printf("    is A Fork with with %d children.", tmpElem->childCount);
     623              printf("    is A Fork with with %d children.\n", tmpElem->childCount);
    539624            }
    540625          if(tmpElem->isJoined)
Note: See TracChangeset for help on using the changeset viewer.