Index: /orxonox/branches/parenting/src/track_manager.cc
===================================================================
--- /orxonox/branches/parenting/src/track_manager.cc	(revision 3331)
+++ /orxonox/branches/parenting/src/track_manager.cc	(revision 3332)
@@ -18,4 +18,5 @@
 
 #include "track_manager.h"
+#include <stdarg.h>
 
 
@@ -27,4 +28,5 @@
 TrackElement::TrackElement(void)
 {
+  this->isFresh = true;
   this->isSavePoint = false;
   this->isFork = false;
@@ -36,4 +38,5 @@
   this->nodeCount = 0;
   childCount = 0;
+  this->name = NULL;
   this->curve = NULL;
   this->children = NULL;
@@ -41,9 +44,11 @@
 
 /** 
-    \destroys all alocated memory)
+    \brief destroys all alocated memory)
     \todo eventually when deleting a TrackElement you would not like to delete all its preceding TrackElements
 */
 TrackElement::~TrackElement(void)
 {
+  if (this->name)
+    delete []name;
   if (this->curve)
     delete this->curve;
@@ -55,7 +60,34 @@
 }
 
-
-
-
+/**
+   \brief Searches through all the TrackElements for trackID.
+   \param trackID The ID to search for.
+   \returns The TrackElement if Found, NULL otherwise.
+   
+   \todo make this more modular, to search for different things
+*/
+TrackElement* TrackElement::findByID(unsigned int trackID)
+{
+  // return if Found.
+  if (this->ID == trackID)
+    return this;
+  // search on.
+  if (this->childCount > 0)
+    for (int i=0; i < this->childCount; i++)
+      {
+	TrackElement* tmpElem;
+	if ((tmpElem = this->children[i]->findByID(trackID)))
+	  return tmpElem;
+      }
+  else return NULL;
+}
+
+
+
+
+
+/////////////////////////////////////
+///// TRACKMANAGER //////////////////
+/////////////////////////////////////
 /**
    \brief standard constructor
@@ -109,9 +141,9 @@
    \brief Searches for a given trackID.
    \param trackID the trackID to search for.
-   \returns The TrackElement #trackID if found, NULL otherways.
-*/
-TrackElement TrackManager::findTrackElementByID(int trackID)
-{
-
+   \returns The TrackElement #trackID if found, NULL otherwise.
+*/
+TrackElement* TrackManager::findTrackElementByID(unsigned int trackID) const
+{
+  return firstTrackElem->findByID(trackID);
 }
 
@@ -122,7 +154,7 @@
    \param trackID the trackID we are working on
 */
-void TrackManager::workOn(int trackID)
-{
-
+void TrackManager::workOn(unsigned int trackID)
+{
+  this->currentTrackElem = findTrackElementByID(trackID);
 }
 
@@ -131,7 +163,21 @@
    \brief curveType The Type to set
 */
-void TrackManager::setType(CurveType curveType)
-{
-
+void TrackManager::setCurveType(CurveType curveType)
+{
+  if (!this->currentTrackElem->isFresh)
+    {
+      PRINTF(2)("It is not possible to change the type of a Curve after you have have appended some points to it\n");
+      return;
+    }
+  this->currentTrackElem->curveType = curveType;
+  switch (curveType)
+    {
+    case BEZIERCURVE:
+      this->currentTrackElem->curve = new BezierCurve();
+      break;
+    case UPOINTCURVE:
+      this->currentTrackElem->curve = new UPointCurve();
+      break;
+    }
 }
 
@@ -143,5 +189,5 @@
 void TrackManager::setLength(float time)
 {
-
+  this->currentTrackElem->length = time;
 }
 
@@ -152,5 +198,10 @@
 void TrackManager::addPoint(Vector newPoint)
 {
-
+  if (this->currentTrackElem->isFresh)
+    {
+      this->setCurveType(BEZIERCURVE);
+      this->currentTrackElem->isFresh = false;
+    }
+  this->currentTrackElem->curve->addNode(newPoint);
 }
 
@@ -161,5 +212,12 @@
 void TrackManager::addHotPoint(Vector newPoint)
 {
-
+  if (this->currentTrackElem->isFresh)
+    {
+      this->setCurveType(BEZIERCURVE);
+      this->currentTrackElem->isFresh = false;
+    }
+
+  // \todo HotPoint Handling.
+  this->currentTrackElem->curve->addNode(newPoint);
 }
 
@@ -172,5 +230,9 @@
 void TrackManager::setSavePoint(void)
 {
-  
+  if (this->currentTrackElem->isFork || this->currentTrackElem->isSavePoint)
+    return;
+  this->currentTrackElem->isSavePoint = true;
+
+  this->currentTrackElem->children = new TrackElement*[1];
 }
 
@@ -182,7 +244,16 @@
    If the HotPoint was defined as a savePoint the Point will \b not be set into a fork.
 */
-void TrackManager::fork(int count, ...)
-{
-
+void TrackManager::fork(unsigned int count, ...)
+{
+  int* trackIDs = new int [count];
+  va_list ID;
+  va_start (ID, count);
+  for(int i = 0; i < count; i++)
+    {
+      trackIDs[i] = va_arg (ID, int);
+    }
+  va_end(ID);
+  this->forkV(count, trackIDs);
+  delete []trackIDs;
 }
 
@@ -193,8 +264,14 @@
 
    \see void TrackManager::fork(int count, ...)
-*/
-void TrackManager::forkV(int count, int* trackIDs)
-{
-
+
+   \todo initialisation is wrong!! also in setSavePoint.
+*/
+void TrackManager::forkV(unsigned int count, int* trackIDs)
+{
+  if (this->currentTrackElem->isSavePoint)
+    return;
+  this->currentTrackElem->isFork = true;
+
+  this->currentTrackElem->children = new TrackElement*[count];
 }
 
@@ -204,7 +281,7 @@
    \param cond \todo think about this
 */
-void TrackManager::condition(int groupID, PathCondition cond)
-{
-
+void TrackManager::condition(unsigned int groupID, PathCondition cond)
+{
+  
 }
 
@@ -216,7 +293,16 @@
    Join will join all curves to the first curve.
 */
-void TrackManager::join(int count, ...)
-{
-
+void TrackManager::join(unsigned int count, ...)
+{
+  int* trackIDs = new int [count];
+  va_list ID;
+  va_start (ID, count);
+  for(int i = 0; i < count; i++)
+    {
+      trackIDs[i] = va_arg (ID, int);
+    }
+  va_end(ID);
+  this->joinV(count, trackIDs);
+  delete []trackIDs;
 }
 
@@ -228,7 +314,7 @@
    \see void TrackManager::join(int count, ...)
 */
-void TrackManager::joinV(int count, int* trackIDs)
-{
-
+void TrackManager::joinV(unsigned int count, int* trackIDs)
+{
+  //! \todo this
 }
 
@@ -239,7 +325,7 @@
    \returns the calculated Position
 */
-Vector TrackManager::calcPos()
-{
-
+Vector TrackManager::calcPos() const
+{
+  
 }
 
@@ -248,5 +334,5 @@
    \returns the calculated Rotation
 */
-Vector TrackManager::calcDir()
+Vector TrackManager::calcDir() const
 {
 
@@ -259,5 +345,5 @@
 void TrackManager::tick(float dt)
 {
-
+  this->localTime += dt;
 }
 
@@ -271,5 +357,5 @@
 void TrackManager::jumpTo(float time)
 {
-
+  localTime = time;
 }
 
Index: /orxonox/branches/parenting/src/track_manager.h
===================================================================
--- /orxonox/branches/parenting/src/track_manager.h	(revision 3331)
+++ /orxonox/branches/parenting/src/track_manager.h	(revision 3332)
@@ -33,4 +33,7 @@
   ~TrackElement(void);
 
+  TrackElement* findByID(unsigned int trackID);
+
+  bool isFresh;              //!< If no Points where added until now
   bool isSavePoint;          //!< If the first node is a savePoint
   bool isFork;               //!< If the first node is a Fork
@@ -41,4 +44,5 @@
   CurveType curveType;       //!< The CurveType this will have.
   int nodeCount;             //!< The count of points this TrackElement has.
+  char* name;                //!< A name for the Trac.
   Curve* curve;              //!< The Curve of this TrackElement
   int childCount;            //!< The number of Children This TrackElement has.
@@ -56,5 +60,5 @@
    <b>1. Initialize it, by setting up the Graph. You can do this by using the following Commands.</b>
     \li workOn(): changes the ID that will be altered through the changes.
-    \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).
+    \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).
     \li setLength(): sets the length of the current path in seconds.
     \li addPoint(): adds a point to the Curve.
@@ -65,5 +69,6 @@
     \li setSavePoint(): Sets a HotPoint into a savePoint. A Savepoint can be used as a rollbackpoint if a Player gets shot.
 
-
+    HotPoints and Joins are at the beginning of a TrackElement. \n
+    SavePoints and Forks are at the end of a TrackElement \n
     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
 \n
@@ -90,5 +95,5 @@
   static TrackManager* singletonRef;  //!< There may only be one TrackManager existing.
   TrackElement* firstTrackElem;       //!< The first TrackElement that exists.
-  TrackElement* currentTrackElem;       //!< The TrackElement we are working on.
+  TrackElement* currentTrackElem;     //!< The TrackElement we are working on.
   float localTime;                    //!< The time that has been passed since the traveling the Track.
   float maxTime;                      //!< The maximal time the track has.
@@ -96,5 +101,5 @@
   
 
-  TrackElement findTrackElementByID(int trackID);
+  TrackElement* findTrackElementByID(unsigned int trackID) const;
   
 
@@ -104,19 +109,19 @@
 
   // Methods to change the Path (initialisation)
-  void workOn(int trackID);
-  void setType(CurveType curveType);
+  void workOn(unsigned int trackID);
+  void setCurveType(CurveType curveType);
   void setLength(float time);
   void addPoint(Vector newPoint);
   void addHotPoint(Vector newPoint);
   void setSavePoint(void);
-  void fork(int count, ...);
-  void forkV(int count, int* trackIDs);
-  void condition(int groupID, PathCondition cond); //!< \todo really do this!!
-  void join(int count, ...);
-  void joinV(int count, int* trackIDs);
+  void fork(unsigned int count, ...);
+  void forkV(unsigned int count, int* trackIDs);
+  void condition(unsigned int groupID, PathCondition cond); //!< \todo really do this!!
+  void join(unsigned int count, ...);
+  void joinV(unsigned int count, int* trackIDs);
 
   // Methods to calculate the position on the Path (runtime)
-  Vector calcPos();
-  Vector calcDir();
+  Vector calcPos(void) const;
+  Vector calcDir(void) const;
   void tick(float dt);
   void jumpTo(float time);
