Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3332 in orxonox.OLD for orxonox/branches


Ignore:
Timestamp:
Jan 4, 2005, 3:51:32 PM (20 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
Location:
orxonox/branches/parenting/src
Files:
2 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
  • orxonox/branches/parenting/src/track_manager.h

    r3331 r3332  
    3333  ~TrackElement(void);
    3434
     35  TrackElement* findByID(unsigned int trackID);
     36
     37  bool isFresh;              //!< If no Points where added until now
    3538  bool isSavePoint;          //!< If the first node is a savePoint
    3639  bool isFork;               //!< If the first node is a Fork
     
    4144  CurveType curveType;       //!< The CurveType this will have.
    4245  int nodeCount;             //!< The count of points this TrackElement has.
     46  char* name;                //!< A name for the Trac.
    4347  Curve* curve;              //!< The Curve of this TrackElement
    4448  int childCount;            //!< The number of Children This TrackElement has.
     
    5660   <b>1. Initialize it, by setting up the Graph. You can do this by using the following Commands.</b>
    5761    \li workOn(): changes the ID that will be altered through the changes.
    58     \li setType: lets you set the CurveType of the Curve we are Working on. (default is BezierCurve, set this as early as possible, for this uses resources).
     62    \li setCurveType(): lets you set the CurveType of the Curve we are Working on. (default is BezierCurve, set this as early as possible, for this uses resources).
    5963    \li setLength(): sets the length of the current path in seconds.
    6064    \li addPoint(): adds a point to the Curve.
     
    6569    \li setSavePoint(): Sets a HotPoint into a savePoint. A Savepoint can be used as a rollbackpoint if a Player gets shot.
    6670
    67 
     71    HotPoints and Joins are at the beginning of a TrackElement. \n
     72    SavePoints and Forks are at the end of a TrackElement \n
    6873    look out: <b>SAVEPOINTS CAN NOT BE FORKS</b> (but joins), because the condition is really hard to guess if you do not give some impuls. \n
    6974\n
     
    9095  static TrackManager* singletonRef;  //!< There may only be one TrackManager existing.
    9196  TrackElement* firstTrackElem;       //!< The first TrackElement that exists.
    92   TrackElement* currentTrackElem;       //!< The TrackElement we are working on.
     97  TrackElement* currentTrackElem;     //!< The TrackElement we are working on.
    9398  float localTime;                    //!< The time that has been passed since the traveling the Track.
    9499  float maxTime;                      //!< The maximal time the track has.
     
    96101 
    97102
    98   TrackElement findTrackElementByID(int trackID);
     103  TrackElement* findTrackElementByID(unsigned int trackID) const;
    99104 
    100105
     
    104109
    105110  // Methods to change the Path (initialisation)
    106   void workOn(int trackID);
    107   void setType(CurveType curveType);
     111  void workOn(unsigned int trackID);
     112  void setCurveType(CurveType curveType);
    108113  void setLength(float time);
    109114  void addPoint(Vector newPoint);
    110115  void addHotPoint(Vector newPoint);
    111116  void setSavePoint(void);
    112   void fork(int count, ...);
    113   void forkV(int count, int* trackIDs);
    114   void condition(int groupID, PathCondition cond); //!< \todo really do this!!
    115   void join(int count, ...);
    116   void joinV(int count, int* trackIDs);
     117  void fork(unsigned int count, ...);
     118  void forkV(unsigned int count, int* trackIDs);
     119  void condition(unsigned int groupID, PathCondition cond); //!< \todo really do this!!
     120  void join(unsigned int count, ...);
     121  void joinV(unsigned int count, int* trackIDs);
    117122
    118123  // Methods to calculate the position on the Path (runtime)
    119   Vector calcPos();
    120   Vector calcDir();
     124  Vector calcPos(void) const;
     125  Vector calcDir(void) const;
    121126  void tick(float dt);
    122127  void jumpTo(float time);
Note: See TracChangeset for help on using the changeset viewer.