Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/track_manager.cc @ 3542

Last change on this file since 3542 was 3540, checked in by patrick, 20 years ago

orxonox/trunk: now, the flyer follows the track exactly (almost).

File size: 23.2 KB
RevLine 
[3311]1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
[3433]12   main-programmer: Benjamin Grauer
[3311]13   co-programmer: ...
14*/
15
16
17#include "track_manager.h"
[3495]18
[3433]19#include "p_node.h"
[3311]20
[3528]21#include "track_node.h"
22
[3495]23#include <stdarg.h>
24
[3311]25using namespace std;
26
[3331]27/**
28   \brief initializes a TrackElement (sets the default values)
29*/
30TrackElement::TrackElement(void)
31{
[3332]32  this->isFresh = true;
[3354]33  this->isHotPoint = false;
[3331]34  this->isSavePoint = false;
35  this->isFork = false;
36  this->isJoined = false;
[3356]37  this->mainJoin = false;
[3331]38  this->ID = -1;
[3333]39  this->startingTime = 0; //!< \todo eventually set this to the max time of TrackManager.
[3348]40  this->duration = 1;
[3433]41  this->endTime = 1;
42  this->jumpTime = 0;
[3331]43  this->curveType = BEZIERCURVE;
44  this->nodeCount = 0;
[3348]45  this->childCount = 0;
[3332]46  this->name = NULL;
[3331]47  this->curve = NULL;
48  this->children = NULL;
[3527]49
50  this->history = NULL;
51
[3522]52  this->condFunc = &TrackElement::random;
[3331]53}
[3311]54
[3331]55/**
[3332]56    \brief destroys all alocated memory)
[3331]57    \todo eventually when deleting a TrackElement you would not like to delete all its preceding TrackElements
58*/
59TrackElement::~TrackElement(void)
60{
[3332]61  if (this->name)
62    delete []name;
[3331]63  if (this->curve)
64    delete this->curve;
[3356]65  if ((!this->isJoined &&this->childCount > 0) || (this->isJoined && this->mainJoin))
[3331]66    {
67      for (int i=0; i < this->childCount; i++)
68        delete this->children[i];
[3356]69      delete this->children;
[3331]70    }
71}
72
[3332]73/**
74   \brief Searches through all the TrackElements for trackID.
75   \param trackID The ID to search for.
76   \returns The TrackElement if Found, NULL otherwise.
77   
78   \todo make this more modular, to search for different things
79*/
80TrackElement* TrackElement::findByID(unsigned int trackID)
81{
82  // return if Found.
83  if (this->ID == trackID)
84    return this;
85  // search on.
86  if (this->childCount > 0)
87    for (int i=0; i < this->childCount; i++)
88      {
89        TrackElement* tmpElem;
90        if ((tmpElem = this->children[i]->findByID(trackID)))
91          return tmpElem;
92      }
93  else return NULL;
94}
[3331]95
96
[3522]97/**
98   \brief checks if there are any BackLoops in the Track
99   \param trackElem the trackElement to check about
100   it simply does this by looking if the current trackElem is found again somewhere else in the Track
101*/
102bool TrackElement::backLoopCheck(TrackElement* trackElem)
103{
104  if (this->childCount == 0)
105    return true;
106  else
107    {
108      for (int i = 0; i < this->childCount; i++)
109        if(!this->children[i]->backLoopCheck(trackElem))
110          return false;
111     
112      return true;
113    }
114}
[3331]115
[3522]116/**
117   \brief CONDITION that chooses the first child for the decision (static)
118   \param nothing Nothing in this function
119   \returns the chosen child
120*/
121int TrackElement::lowest(void* nothing)
122{
123  return 0;
124}
[3332]125
[3522]126/**
127   \brief CONDITION that chooses the last child for the decision (static)
128   \param nothing Nothing in this function
129   \returns the chosen child
130*/
131int TrackElement::highest(void* nothing)
132{ 
133  return this->childCount-1;
134}
[3332]135
[3522]136/**
137   \brief CONDITION that chooses a random child for the decision (static)
138   \param nothing Nothing in this function
139   \returns the chosen child
140*/
141int TrackElement::random(void* nothing)
142{
143  int i = (int)floor ((float)rand()/(float)RAND_MAX * (float)this->childCount);
144  if (i >= this->childCount)
145    return this->childCount-1;
146  else 
147    return i;
148}
149
150/**
151   \brief CONDITION that chooses child 0, if the node(probably Player)
152   is left of its parent (z<0)) and 1/right otherwise.
153   \param node The node to act upon.
154   \returns the chosen child
155*/
156int TrackElement::leftRight(void* node)
157{
158  PNode* tmpNode = (PNode*)node;
159
160  if (tmpNode->getRelCoor().z < 0)
161    return 0;
162  else 
163    return 1;
164}
165
166
167/**
168   \brief CONDITION that chooses the child, that has the nearest distance to the node (probably player).
169   \param node The node to act upon.
170   \returns the chosen child
171
172   This is rather dangerous, because one must carefully set the points on the curve.
173   The best Way is to set the nodes as wide away of each other as possible,
174   but take into consideration, that if the nodes are to far from a center node, the center will be chosen.
175   (play with this!!).
176*/
177int TrackElement::nearest(void* node)
178{
179  PNode* tmpNode = (PNode*)node;
180
181  Vector nodeRelCoord = tmpNode->getRelCoor();
182  float minDist = 100000000;
183  int nodeNumber = 0;
184  for (int i = 0; i < this->childCount; i++)
185    {
186      float dist = (nodeRelCoord - this->children[i]->curve->getNode(4)).len();
187      if (dist < minDist)
188        {
189          minDist = dist;
190          nodeNumber = i;
191        }
192    }
193  PRINTF(3)("PathDecision with nearest algorithm: %d\n", nodeNumber);
194  return nodeNumber;
195}
196
197
198
[3332]199/////////////////////////////////////
200///// TRACKMANAGER //////////////////
201/////////////////////////////////////
[3311]202/**
203   \brief standard constructor
204
205*/
[3354]206TrackManager::TrackManager(void)
[3311]207{
[3331]208  this->setClassName ("TrackManager");
[3528]209 
210  singletonRef = this;
[3331]211
212  PRINTF(3)("Initializing the TrackManager\n");
[3348]213  this->firstTrackElem = new TrackElement();
214  this->firstTrackElem->ID = 1;
[3331]215  this->currentTrackElem = firstTrackElem;
216  this->localTime = 0;
217  this->maxTime = 0;
[3348]218  this->trackElemCount = 1;
[3528]219  this->bindSlave = TrackNode::getInstance();
[3311]220}
221
222
223/**
[3331]224   \brief standard destructor
[3311]225
226*/
[3354]227TrackManager::~TrackManager(void)
[3330]228{
[3331]229  PRINTF(3)("Destruct TrackManager\n");
[3311]230
[3331]231  PRINTF(3)("Deleting all the TrackElements\n");
232  delete this->firstTrackElem;
[3335]233
[3331]234  // we do not have a TrackManager anymore
235  singletonRef = NULL;
[3330]236}
237
[3331]238TrackManager* TrackManager::singletonRef = NULL;
239
[3330]240/**
[3331]241   \returns The reference on the TrackManager.
242
243   If the TrackManager does not exist, it will be created.
244*/
245TrackManager* TrackManager::getInstance(void) 
246{
[3528]247  if (!singletonRef)
248    singletonRef = new TrackManager();
249  return singletonRef;
[3331]250}
251
252/**
[3335]253   \brief reserves Space for childCount children
254   \param childCount The Count of children to make space for.
255*/
256void TrackManager::initChildren(unsigned int childCount)
257{
258  this->currentTrackElem->childCount = childCount;
[3433]259  this->currentTrackElem->mainJoin = true;
[3335]260  this->currentTrackElem->children = new TrackElement*[childCount];
261  for (int i=0; i<childCount; i++)
[3348]262    {
263      this->currentTrackElem->children[i] = new TrackElement();
264      this->currentTrackElem->children[i]->ID = ++trackElemCount;
[3433]265      this->currentTrackElem->children[i]->startingTime = this->currentTrackElem->endTime + this->currentTrackElem->jumpTime;
266      this->addPoint(this->currentTrackElem->curve->getNode(this->currentTrackElem->curve->getNodeCount()), this->currentTrackElem->children[i]);
[3348]267    }
[3335]268}
269
270/**
[3330]271   \brief Searches for a given trackID.
272   \param trackID the trackID to search for.
[3332]273   \returns The TrackElement #trackID if found, NULL otherwise.
[3330]274*/
[3332]275TrackElement* TrackManager::findTrackElementByID(unsigned int trackID) const
[3330]276{
[3332]277  return firstTrackElem->findByID(trackID);
[3330]278}
279
280// INITIALIZE //
281
282/**
283   \brief Sets the trackID we are working on.
284   \param trackID the trackID we are working on
285*/
[3332]286void TrackManager::workOn(unsigned int trackID)
[3330]287{
[3355]288  TrackElement* tmpElem = findTrackElementByID(trackID);
289  if (tmpElem)
290    this->currentTrackElem = tmpElem;
291  else
292    printf("TrackElement not Found, leaving unchanged\n");
293  printf("now Working on %d\n", this->currentTrackElem->ID);
294
[3330]295}
296
297/**
298   \brief Sets the Type of the Curve
[3522]299   \param curveType The Type to set
300   \param trackElem the TrackElement that should get a new Curve.
[3330]301*/
[3433]302void TrackManager::setCurveType(CurveType curveType, TrackElement* trackElem)
[3330]303{
[3433]304  if (!trackElem->isFresh)
[3332]305    {
306      PRINTF(2)("It is not possible to change the type of a Curve after you have have appended some points to it\n");
307      return;
308    }
[3433]309  trackElem->curveType = curveType;
[3332]310  switch (curveType)
311    {
312    case BEZIERCURVE:
[3433]313      trackElem->curve = new BezierCurve();
[3332]314      break;
315    case UPOINTCURVE:
[3433]316      trackElem->curve = new UPointCurve();
[3332]317      break;
318    }
[3330]319}
320
321/**
[3333]322   \brief Sets the duration of the current path in seconds.
323   \param time The duration in seconds.
[3330]324*/
325
[3333]326void TrackManager::setDuration(float time)
[3330]327{
[3333]328  this->currentTrackElem->duration = time;
[3433]329  this->currentTrackElem->endTime = this->currentTrackElem->startingTime + time;
[3330]330}
331
332/**
333   \brief adds a point to the current TrackElement
334   \param newPoint The point to add.
335*/
[3333]336bool TrackManager::addPoint(Vector newPoint)
[3330]337{
[3352]338  return this->addPoint(newPoint, this->currentTrackElem);
339}
340
341/**
342   \brief adds a point to trackElem
343   \param newPoint The point to add.
344   \param trackElem The TrackElement to add the Point to
345*/
346bool TrackManager::addPoint(Vector newPoint, TrackElement* trackElem)
347{
348  if (trackElem->isFresh)
[3332]349    {
[3433]350      this->setCurveType(BEZIERCURVE, trackElem);
[3352]351      trackElem->isFresh = false;
[3332]352    }
[3352]353  trackElem->curve->addNode(newPoint);
354  trackElem->nodeCount++;
[3330]355}
356
357/**
358   \brief adds save/splitpoint.
359   \param newPoint The point to add.
[3333]360   \returns A Pointer to a newly appended Curve
[3330]361*/
[3333]362int TrackManager::addHotPoint(Vector newPoint)
[3330]363{
[3354]364  printf("setting up a HotPoint\n");
[3332]365  if (this->currentTrackElem->isFresh)
366    {
367      this->setCurveType(BEZIERCURVE);
368      this->currentTrackElem->isFresh = false;
369    }
[3330]370
[3332]371  // \todo HotPoint Handling.
372  this->currentTrackElem->curve->addNode(newPoint);
[3351]373  this->currentTrackElem->nodeCount++;
[3354]374  this->initChildren(1);
375  this->currentTrackElem = this->currentTrackElem->children[0];
[3330]376}
377
378/**
379   \brief Sets the last HotPoint into a savePoint.
[3333]380   \returns A Pointer to a newly appended Curve
[3330]381   
382   If no HotPoint was defined the last added Point will be rendered into a savePoint. \n
383   If the HotPoint was defined as a fork the Point will \b not be set into a savePoint.
384*/
[3333]385int TrackManager::setSavePoint(void)
[3330]386{
[3354]387  printf("setting up a SavePoint.\n");
[3332]388  if (this->currentTrackElem->isFork || this->currentTrackElem->isSavePoint)
[3333]389    return this->currentTrackElem->children[1]->ID;
[3332]390  this->currentTrackElem->isSavePoint = true;
[3354]391  this->currentTrackElem->isHotPoint = true;
[3332]392
[3335]393  this->initChildren(1);
[3348]394  this->currentTrackElem = this->currentTrackElem->children[0];
[3330]395}
396
397/**
398   \brief adds some interessting non-linear movments through the level.
399   \param count The Count of childrens the current HotPoint will have.
400
401   If no HotPoint was defined the last added Point will be rendered into a fork. \n
402   If the HotPoint was defined as a savePoint the Point will \b not be set into a fork.
403*/
[3332]404void TrackManager::fork(unsigned int count, ...)
[3330]405{
[3351]406  int* trackIDs = new int[count];
407  this->forkV(count, trackIDs);
[3332]408  va_list ID;
409  va_start (ID, count);
410  for(int i = 0; i < count; i++)
411    {
[3351]412      *va_arg (ID, int*) = trackIDs[i];
[3332]413    }
[3351]414  va_end(ID); 
[3332]415  delete []trackIDs;
[3330]416}
417
418/**
419   \brief adds some interessting non-linear movments through the level.
420   \param count The Count of childrens the current HotPoint will have.
421   \param trackIDs A Pointer to an Array of ints which will hold the trackID's (the user will have to reserve space for this).
422
423   \see void TrackManager::fork(int count, ...)
[3332]424
425   \todo initialisation is wrong!! also in setSavePoint.
[3330]426*/
[3332]427void TrackManager::forkV(unsigned int count, int* trackIDs)
[3330]428{
[3354]429  printf("Forking with %d children\n", count);
[3332]430  if (this->currentTrackElem->isSavePoint)
431    return;
432  this->currentTrackElem->isFork = true;
[3354]433  this->currentTrackElem->isHotPoint = true;
[3351]434  for(int i = 0; i < count; i++)
435    trackIDs[i]=this->trackElemCount+1+i;
[3335]436  this->initChildren(count);
[3330]437}
438
439/**
440   \brief decides under what condition a certain Path will be chosen.
[3522]441   \param cond the CONDITION of the decision
442   \param subject the Subject that will be decided upon with CONDITION cond.
443*/
444void TrackManager::condition(CONDITION cond, void* subject)
445{
446  this->condition(this->currentTrackElem->ID, cond, subject);
447}
448/**
449   \brief decides under what condition a certain Path will be chosen.
[3330]450   \param groupID the ID on which to choose the preceding move
[3522]451   \param cond the CONDITION of the decision
452   \param subject the Subject that will be decided upon with CONDITION cond.
[3330]453*/
[3522]454void TrackManager::condition(unsigned int groupID, CONDITION cond, void* subject)
[3330]455{
[3522]456  TrackElement* tmpElem = this->findTrackElementByID(groupID);
[3332]457 
[3522]458  switch (cond)
459    {
460    case LOWEST:
461      tmpElem->condFunc = &TrackElement::lowest;
462      break;
463    case HIGHEST:
464      tmpElem->condFunc = &TrackElement::highest;
465      break;
466    case RANDOM: 
467      tmpElem->condFunc = &TrackElement::random;
468      break;
469    case LEFTRIGHT:
470      tmpElem->condFunc = &TrackElement::leftRight;
471      break;
472    case NEAREST:
473      tmpElem->condFunc = &TrackElement::nearest;
474      break;
475    case ENEMYKILLED:
476      break;
477    }
478  tmpElem->subject=subject;
[3330]479}
480
[3522]481
[3330]482/**
483   \brief joins some tracks together again.
484   \param count The count of Paths to join.
485
486   Join will set the localTime to the longest time a Path has to get to this Point. \n
[3354]487   Join will join all curves to the first curve, meaning that all the tangents will be matched.
[3330]488*/
[3332]489void TrackManager::join(unsigned int count, ...)
[3330]490{
[3332]491  int* trackIDs = new int [count];
492  va_list ID;
493  va_start (ID, count);
494  for(int i = 0; i < count; i++)
495    {
496      trackIDs[i] = va_arg (ID, int);
497    }
498  va_end(ID);
499  this->joinV(count, trackIDs);
500  delete []trackIDs;
[3330]501}
502
503/**
504   \brief joins some tracks together again.
505   \param count The count of Paths to join.
506   \param trackIDs an Array with the trackID's to join
507
508   \see void TrackManager::join(int count, ...)
509*/
[3332]510void TrackManager::joinV(unsigned int count, int* trackIDs)
[3330]511{
[3433]512  printf("Joining %d tracks and merging to Track %d\n", count, trackIDs[0]);
[3354]513
[3522]514  // checking if there is a back-loop-connection and ERROR if it is.
515  TrackElement* tmpTrackElem = this->findTrackElementByID(trackIDs[0]);
516  if (!tmpTrackElem->backLoopCheck(tmpTrackElem))
517    PRINTF(1)("Backloop connection detected at joining trackElements\n");
518
[3354]519  // chanching work-on to temporary value. going back at the end.
520  int tmpCurrentWorkingID = this->currentTrackElem->ID;
521  this->workOn(trackIDs[0]);
[3433]522  TrackElement* firstJoint = this->currentTrackElem;
523  float tmpLatestTime = firstJoint->endTime;
[3354]524
525  Vector tmpEndPoint = firstJoint->curve->getNode(firstJoint->curve->getNodeCount());
[3433]526  Vector tmpTangentPoint = firstJoint->curve->getNode(firstJoint->curve->getNodeCount()-1);
527  Vector tmpc2Point = firstJoint->curve->getNode(firstJoint->curve->getNodeCount()-2);
[3354]528  firstJoint->isJoined = true;
[3433]529  //  firstJoint->mainJoin = true;
[3354]530  if(!firstJoint->isHotPoint)
531    this->setSavePoint();
[3433]532  // Timing:
533  for (int i = 0; i < count; i++)
534    {
535      TrackElement* tmpJoinElem = this->findTrackElementByID(trackIDs[i]);
536      if (tmpJoinElem->childCount == 0
537          && tmpJoinElem->endTime > tmpLatestTime)
538        tmpLatestTime = tmpJoinElem->endTime;
539    }
540  // time the main Join.
541  firstJoint->jumpTime = tmpLatestTime - firstJoint->endTime;
542 
543  // Joining:
[3354]544  for (int i = 1; i < count; i++)
[3352]545    {
546      TrackElement* tmpJoinElem = this->findTrackElementByID(trackIDs[i]);
[3354]547      if (tmpJoinElem->childCount > 0)
548        printf("!!This Curve has children, and as such will not be joined!!\n You can try joining other childless TrackElements to this one!");
549      else
550        {
[3433]551          this->addPoint(tmpc2Point, tmpJoinElem);
[3354]552          this->addPoint(tmpTangentPoint, tmpJoinElem);
553          this->addPoint(tmpEndPoint, tmpJoinElem);
[3433]554          // time all other Joins
555          tmpJoinElem->jumpTime = tmpLatestTime - tmpJoinElem->endTime;
[3354]556         
557          //Copying Joint-Info
558          tmpJoinElem->children = firstJoint->children;
559          tmpJoinElem->childCount = firstJoint->childCount;
560          tmpJoinElem->isSavePoint = firstJoint->isSavePoint;
561          tmpJoinElem->isFork = firstJoint->isFork;
[3433]562
[3354]563          tmpJoinElem->isJoined = true;
564        }
[3352]565    }
[3433]566  if(firstJoint->childCount > 0)
567    for(int i = 0; i < firstJoint->childCount; i++)
568      {
569        printf("Setting startingTime of %d to %f.\n", firstJoint->children[i]->ID, tmpLatestTime);
570        firstJoint->children[i]->startingTime = tmpLatestTime;
571        firstJoint->children[i]->endTime = tmpLatestTime+firstJoint->children[i]->duration;
572      } 
573
[3354]574  // returning to the TrackElement we were working on.
575  this->workOn(tmpCurrentWorkingID);
[3330]576}
577
[3433]578/**
579   \brief finalizes the TrackSystem. after this it will not be editable anymore
580
581   \todo check for any inconsistencies, output errors
582*/
583void TrackManager::finalize(void)
584{
585  for (int i = 1; i<= trackElemCount ;i++)
586    {
587      TrackElement* tmpElem = findTrackElementByID(i);
588      if (tmpElem->childCount>0 && tmpElem->mainJoin)
589        {
590          for (int j = 0; j < tmpElem->childCount; j++)
591            {
592             
593              // c1-continuity
594              tmpElem->children[j]->curve->addNode(tmpElem->children[j]->curve->getNode(0) +
595                                                   ((tmpElem->children[j]->curve->getNode(0) - 
596                                                    tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1))
597                                                    ),2);
598              tmpElem->children[j]->nodeCount++;
599              // c2-continuity
600              tmpElem->children[j]->curve->addNode((tmpElem->curve->getNode(tmpElem->curve->getNodeCount())-
601                                                    tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1)) * 4 +
602                                                   tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-2), 3);
603              tmpElem->children[j]->nodeCount++;                                                   
604              printf("accelerations: %d-in: count: %d, %f, %f, %f\n                  %d-out: count: %d %f, %f, %f\n",
605                     tmpElem->ID, tmpElem->nodeCount,
606                     tmpElem->curve->calcAcc(0.999).x, tmpElem->curve->calcAcc(0.999).y, tmpElem->curve->calcAcc(0.999).z,
607                     tmpElem->children[j]->ID, tmpElem->children[j]->nodeCount,
608                     tmpElem->children[j]->curve->calcAcc(0).x, tmpElem->children[j]->curve->calcAcc(0).y, tmpElem->children[j]->curve->calcAcc(0).z);
609            }
610        }
611    }
612}
613
614
[3330]615// RUNTIME //
616
617/**
618   \brief calculates the Position for the localTime of the Track.
619   \returns the calculated Position
620*/
[3332]621Vector TrackManager::calcPos() const
[3330]622{
[3348]623  //  PRINTF(0)("TrackElement:%d, localTime: %f\n",this->currentTrackElem->ID, this->localTime);
624  return this->currentTrackElem->curve->calcPos((this->localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration);
[3330]625}
626
627/**
628   \brief calculates the Rotation for the localTime of the Track.
629   \returns the calculated Rotation
630*/
[3332]631Vector TrackManager::calcDir() const
[3330]632{
[3433]633  return this->currentTrackElem->curve->calcDir((this->localTime - this->currentTrackElem->startingTime)/this->currentTrackElem->duration);
[3330]634}
635
636/**
637   \brief Advances the local-time of the Track around dt
638   \param dt The time about which to advance.
[3333]639
640   This function also checks, if the TrackElement has to be changed.
[3330]641*/
642void TrackManager::tick(float dt)
643{
[3433]644  dt /= 1000;
645  printf("CurrentTrackID: %d, LocalTime is: %f, timestep is: %f\n", this->currentTrackElem->ID, this->localTime, dt);
[3348]646  if (this->localTime <= this->firstTrackElem->duration)
647    this->jumpTo(this->localTime);
[3332]648  this->localTime += dt;
[3433]649  if (this->localTime > this->currentTrackElem->endTime
650      && this->currentTrackElem->children)
651    {
[3527]652      if (this->currentTrackElem->jumpTime != 0.0)
[3433]653        this->jumpTo(this->localTime + this->currentTrackElem->jumpTime);
[3527]654      // jump to the next TrackElement and also set the history of the new Element to the old one.
655      TrackElement* tmpHistoryElem = this->currentTrackElem;
[3522]656      this->currentTrackElem = this->currentTrackElem->children[this->choosePath(this->currentTrackElem)];
[3527]657      this->currentTrackElem->history = tmpHistoryElem;
[3433]658    }
659  if (this->bindSlave)
660    {
661      Vector tmp = this->calcPos();
662      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)); 
[3539]663
664      Vector v(0.0, 1.0, 0.0);
[3540]665      Quaternion q(-1.57, v);
[3539]666      //this->relDirection = this->relDirection * q;
667      quat = quat * q;
668
[3433]669      this->bindSlave->setAbsCoor(&tmp);
670      this->bindSlave->setAbsDir(&quat);
671    }
[3330]672}
673
674/**
[3331]675   \brief Jumps to a certain point on the Track.
676   \param time The time on the Track to jump to.
677
678   This should be used to Jump backwards on a Track, because moving forward means to change between the Path. (it then tries to choose the default.)
679   Max is trackLengthMax.
680*/
681void TrackManager::jumpTo(float time)
682{
[3348]683  if (time == 0)
684    this->currentTrackElem = this->firstTrackElem;
685  this->localTime = time;
[3331]686}
687
688/**
[3330]689   \brief a Function that decides which Path we should follow.
[3522]690   \param trackElem The Path to choose.
[3330]691   
692*/
[3522]693int TrackManager::choosePath(TrackElement* trackElem)
[3330]694{
[3522]695  return (trackElem->*(trackElem->condFunc))(trackElem->subject);
[3330]696}
697
[3433]698/**
699   \brief Sets the PNode, that should be moved along the Tack
700   \param bindSlave the PNode to set
701*/
702void TrackManager::setBindSlave(PNode* bindSlave)
703{
[3528]704  if (this->bindSlave == TrackNode::getInstance() || bindSlave == TrackNode::getInstance())
[3433]705    this->bindSlave = bindSlave;
[3528]706  else
707    PRINTF(2)("Already a Bindslave set that is not the TrackNode itself. Not updating\n");
[3433]708}
[3350]709
710
711// DEBUG //
712
713/**
714   \brief Imports a model of the Graph into the OpenGL-environment.
715   \param dt The Iterator used in seconds for Painting the Graph.
716
717   This is for testing facility only. Do this if you want to see the Path inside the Level.
718   eventually this will all be packed into a gl-list.
719*/
720void TrackManager::drawGraph(float dt) const
721{
[3352]722
[3350]723  for (int i = 1; i <= trackElemCount; i++)
724    {
[3352]725      glBegin(GL_LINE_STRIP);
[3350]726      TrackElement* tmpElem = this->findTrackElementByID(i);
727      if (tmpElem->curve)
728        for(float f = 0.0; f < 1.0; f+=dt)
729          {
730            //      printf("%f, %f, %f\n",trackManager->calcPos().x, trackManager->calcPos().y, trackManager->calcPos().z);
731            Vector tmpVector = tmpElem->curve->calcPos(f);
732            glVertex3f(tmpVector.x, tmpVector.y, tmpVector.z);
733          }
[3352]734  glEnd();
[3350]735    }
736}
737
[3433]738/**
739   \brief outputs debug information about the trackManager
740   \param level how much debug
741*/
[3350]742void TrackManager::debug(unsigned int level) const
743{
[3522]744  PRINT(0)("=========================================\n");
745  PRINT(0)("= CLASS TRACKMANAGER::debug information =\n");
746  PRINT(0)("=========================================\n");
747  //  PRINT(0)("Status is: %
748  PRINT(0)(" Consists of %d elements\n", this->trackElemCount);
749  PRINT(0)(" localTime is: %f\n", this->localTime);
[3350]750  if (level >= 2)
751    {
752      for (int i = 1; i <= trackElemCount; i++)
753        {
754          TrackElement* tmpElem = this->findTrackElementByID(i);
[3522]755          PRINT(0)("--== TrackElement:%i ==--", tmpElem->ID);
[3350]756          if(tmpElem->name)
[3522]757            PRINT(0)("Name: %s::", tmpElem->name);
[3354]758          if(tmpElem->isFresh)
[3522]759            PRINT(0)("  -- has not jet eddited in any way --\n");
760          PRINT(0)("\n   TimeTable: startingTime=%f; endTime=%f; duration=%f; jumpTime=%f\n", tmpElem->startingTime, tmpElem->endTime, tmpElem->duration, tmpElem->jumpTime);
761          PRINT(0)("   consists of %d Points\n", tmpElem->nodeCount);
[3354]762          if (tmpElem->childCount == 0)
[3522]763            PRINT(0)("   has no child\n");
[3354]764          else if (tmpElem->childCount == 1)
[3522]765            PRINT(0)("   has 1 child: =%d=\n", tmpElem->children[0]->ID);
[3354]766          else if (tmpElem->childCount > 1)
[3351]767            {
[3522]768              PRINT(0)("   has %d children: ", tmpElem->childCount);
[3351]769              for(int i = 0; i < tmpElem->childCount; i++)
[3522]770                PRINT(0)("=%d= ", tmpElem->children[i]->ID);
771              PRINT(0)("\n");
[3351]772            }
[3354]773
774          if(tmpElem->isHotPoint)
[3522]775            PRINT(0)("   is a special Point:\n");
[3354]776          if(tmpElem->isSavePoint)
[3522]777            PRINT(0)("    is a SavePoint\n");
[3354]778          if(tmpElem->isFork)
779            {
[3522]780              PRINT(0)("    is A Fork with with %d children.\n", tmpElem->childCount);
[3354]781            }
[3350]782          if(tmpElem->isJoined)
[3522]783            PRINT(0)("   is Joined at the End\n");
784
785          if(!tmpElem->backLoopCheck(tmpElem)) /* this should not happen */
786            PRINT(2)(" THERE IS A BACKLOOP TO THIS ELEMENT\n");
[3350]787        }
788    }
[3522]789  PRINT(0)("-----------------------------------------\n");
[3350]790}
Note: See TracBrowser for help on using the repository browser.