Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 4, 2005, 3:51:32 PM (19 years ago)
Author:
bensch
Message:

orxonox/branches/parenting: TrackManager: wrote raw material for most Functions. It compiles, but there still is a lot to do.

  1. Forking and Joining.
  2. Initialisation of TrackElement
  3. Condition
  4. much more
File:
1 edited

Legend:

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

    r3331 r3332  
    1818
    1919#include "track_manager.h"
     20#include <stdarg.h>
    2021
    2122
     
    2728TrackElement::TrackElement(void)
    2829{
     30  this->isFresh = true;
    2931  this->isSavePoint = false;
    3032  this->isFork = false;
     
    3638  this->nodeCount = 0;
    3739  childCount = 0;
     40  this->name = NULL;
    3841  this->curve = NULL;
    3942  this->children = NULL;
     
    4144
    4245/**
    43     \destroys all alocated memory)
     46    \brief destroys all alocated memory)
    4447    \todo eventually when deleting a TrackElement you would not like to delete all its preceding TrackElements
    4548*/
    4649TrackElement::~TrackElement(void)
    4750{
     51  if (this->name)
     52    delete []name;
    4853  if (this->curve)
    4954    delete this->curve;
     
    5560}
    5661
    57 
    58 
    59 
     62/**
     63   \brief Searches through all the TrackElements for trackID.
     64   \param trackID The ID to search for.
     65   \returns The TrackElement if Found, NULL otherwise.
     66   
     67   \todo make this more modular, to search for different things
     68*/
     69TrackElement* TrackElement::findByID(unsigned int trackID)
     70{
     71  // return if Found.
     72  if (this->ID == trackID)
     73    return this;
     74  // search on.
     75  if (this->childCount > 0)
     76    for (int i=0; i < this->childCount; i++)
     77      {
     78        TrackElement* tmpElem;
     79        if ((tmpElem = this->children[i]->findByID(trackID)))
     80          return tmpElem;
     81      }
     82  else return NULL;
     83}
     84
     85
     86
     87
     88
     89/////////////////////////////////////
     90///// TRACKMANAGER //////////////////
     91/////////////////////////////////////
    6092/**
    6193   \brief standard constructor
     
    109141   \brief Searches for a given trackID.
    110142   \param trackID the trackID to search for.
    111    \returns The TrackElement #trackID if found, NULL otherways.
    112 */
    113 TrackElement TrackManager::findTrackElementByID(int trackID)
    114 {
    115 
     143   \returns The TrackElement #trackID if found, NULL otherwise.
     144*/
     145TrackElement* TrackManager::findTrackElementByID(unsigned int trackID) const
     146{
     147  return firstTrackElem->findByID(trackID);
    116148}
    117149
     
    122154   \param trackID the trackID we are working on
    123155*/
    124 void TrackManager::workOn(int trackID)
    125 {
    126 
     156void TrackManager::workOn(unsigned int trackID)
     157{
     158  this->currentTrackElem = findTrackElementByID(trackID);
    127159}
    128160
     
    131163   \brief curveType The Type to set
    132164*/
    133 void TrackManager::setType(CurveType curveType)
    134 {
    135 
     165void TrackManager::setCurveType(CurveType curveType)
     166{
     167  if (!this->currentTrackElem->isFresh)
     168    {
     169      PRINTF(2)("It is not possible to change the type of a Curve after you have have appended some points to it\n");
     170      return;
     171    }
     172  this->currentTrackElem->curveType = curveType;
     173  switch (curveType)
     174    {
     175    case BEZIERCURVE:
     176      this->currentTrackElem->curve = new BezierCurve();
     177      break;
     178    case UPOINTCURVE:
     179      this->currentTrackElem->curve = new UPointCurve();
     180      break;
     181    }
    136182}
    137183
     
    143189void TrackManager::setLength(float time)
    144190{
    145 
     191  this->currentTrackElem->length = time;
    146192}
    147193
     
    152198void TrackManager::addPoint(Vector newPoint)
    153199{
    154 
     200  if (this->currentTrackElem->isFresh)
     201    {
     202      this->setCurveType(BEZIERCURVE);
     203      this->currentTrackElem->isFresh = false;
     204    }
     205  this->currentTrackElem->curve->addNode(newPoint);
    155206}
    156207
     
    161212void TrackManager::addHotPoint(Vector newPoint)
    162213{
    163 
     214  if (this->currentTrackElem->isFresh)
     215    {
     216      this->setCurveType(BEZIERCURVE);
     217      this->currentTrackElem->isFresh = false;
     218    }
     219
     220  // \todo HotPoint Handling.
     221  this->currentTrackElem->curve->addNode(newPoint);
    164222}
    165223
     
    172230void TrackManager::setSavePoint(void)
    173231{
    174  
     232  if (this->currentTrackElem->isFork || this->currentTrackElem->isSavePoint)
     233    return;
     234  this->currentTrackElem->isSavePoint = true;
     235
     236  this->currentTrackElem->children = new TrackElement*[1];
    175237}
    176238
     
    182244   If the HotPoint was defined as a savePoint the Point will \b not be set into a fork.
    183245*/
    184 void TrackManager::fork(int count, ...)
    185 {
    186 
     246void TrackManager::fork(unsigned int count, ...)
     247{
     248  int* trackIDs = new int [count];
     249  va_list ID;
     250  va_start (ID, count);
     251  for(int i = 0; i < count; i++)
     252    {
     253      trackIDs[i] = va_arg (ID, int);
     254    }
     255  va_end(ID);
     256  this->forkV(count, trackIDs);
     257  delete []trackIDs;
    187258}
    188259
     
    193264
    194265   \see void TrackManager::fork(int count, ...)
    195 */
    196 void TrackManager::forkV(int count, int* trackIDs)
    197 {
    198 
     266
     267   \todo initialisation is wrong!! also in setSavePoint.
     268*/
     269void TrackManager::forkV(unsigned int count, int* trackIDs)
     270{
     271  if (this->currentTrackElem->isSavePoint)
     272    return;
     273  this->currentTrackElem->isFork = true;
     274
     275  this->currentTrackElem->children = new TrackElement*[count];
    199276}
    200277
     
    204281   \param cond \todo think about this
    205282*/
    206 void TrackManager::condition(int groupID, PathCondition cond)
    207 {
    208 
     283void TrackManager::condition(unsigned int groupID, PathCondition cond)
     284{
     285 
    209286}
    210287
     
    216293   Join will join all curves to the first curve.
    217294*/
    218 void TrackManager::join(int count, ...)
    219 {
    220 
     295void TrackManager::join(unsigned int count, ...)
     296{
     297  int* trackIDs = new int [count];
     298  va_list ID;
     299  va_start (ID, count);
     300  for(int i = 0; i < count; i++)
     301    {
     302      trackIDs[i] = va_arg (ID, int);
     303    }
     304  va_end(ID);
     305  this->joinV(count, trackIDs);
     306  delete []trackIDs;
    221307}
    222308
     
    228314   \see void TrackManager::join(int count, ...)
    229315*/
    230 void TrackManager::joinV(int count, int* trackIDs)
    231 {
    232 
     316void TrackManager::joinV(unsigned int count, int* trackIDs)
     317{
     318  //! \todo this
    233319}
    234320
     
    239325   \returns the calculated Position
    240326*/
    241 Vector TrackManager::calcPos()
    242 {
    243 
     327Vector TrackManager::calcPos() const
     328{
     329 
    244330}
    245331
     
    248334   \returns the calculated Rotation
    249335*/
    250 Vector TrackManager::calcDir()
     336Vector TrackManager::calcDir() const
    251337{
    252338
     
    259345void TrackManager::tick(float dt)
    260346{
    261 
     347  this->localTime += dt;
    262348}
    263349
     
    271357void TrackManager::jumpTo(float time)
    272358{
    273 
     359  localTime = time;
    274360}
    275361
Note: See TracChangeset for help on using the changeset viewer.