Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3836 in orxonox.OLD


Ignore:
Timestamp:
Apr 15, 2005, 5:51:17 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: TrackManager: nicer fuctionality… more to come

Location:
orxonox/trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/math/curve.h

    r3595 r3836  
    1313
    1414//! An Enumerator that defines what sort of Curves are availible
    15 enum CurveType {BEZIERCURVE};
     15enum CurveType {CURVE_BEZIER};
    1616
    1717
  • orxonox/trunk/src/track_manager.cc

    r3835 r3836  
    372372  this->setClassName("TrackManager");
    373373 
    374   TrackManager::singletonRef = this;
     374  TrackManager::singletonRef = this; // do this because otherwise the TrackNode cannot get The instance of the TrackManager
    375375
    376376  PRINTF(3)("Initializing the TrackManager\n");
     377  // setting up the First TrackElement
    377378  this->firstTrackElem = new TrackElement();
    378379  this->firstTrackElem->ID = 1;
    379380  this->currentTrackElem = firstTrackElem;
     381
     382  this->curveType = CURVE_BEZIER;
    380383  this->localTime = 0;
    381384  this->maxTime = 0;
    382385  this->trackElemCount = 1;
    383   this->setBindSlave(this->trackNode = new TrackNode());
    384 }
    385 
     386  this->trackNode = new TrackNode();
     387  this->setBindSlave(this->trackNode);
     388}
    386389
    387390/**
     
    394397  PRINTF(4)("Deleting all the TrackElements\n");
    395398  delete this->firstTrackElem;
     399
     400  // the tracknode should be deleted here, but is deleted by pNode: -> null_parent
    396401
    397402  // we do not have a TrackManager anymore
     
    414419}
    415420
     421
     422// INITIALIZE //
    416423/**
    417424   \brief reserves Space for childCount children
    418425   \param childCount The Count of children to make space for.
    419 */
    420 void TrackManager::initChildren(unsigned int childCount)
    421 {
    422   this->currentTrackElem->childCount = childCount;
    423   this->currentTrackElem->mainJoin = true;
    424   this->currentTrackElem->children =  new tList<TrackElement>();
     426   \param trackElem The TrackElement to appy this to. (if NULL chose this->currentTrackElement)
     427*/
     428void TrackManager::initChildren(unsigned int childCount, TrackElement* trackElem)
     429{
     430  if (!trackElem)
     431    trackElem = this->currentTrackElem;
     432
     433  trackElem->childCount = childCount;
     434  trackElem->mainJoin = true;  // this tells join, that this one is the Main Join, if it tries to join multiple Tracks
     435  trackElem->children =  new tList<TrackElement>();
    425436  for (int i = 0; i < childCount; i++)
    426437    {
     438      // create a new Element
    427439      TrackElement* newElem = new TrackElement();
    428       this->currentTrackElem->children->add(newElem);
     440      // setting up the new ID
    429441      newElem->ID = ++trackElemCount;
    430       newElem->startingTime = this->currentTrackElem->endTime + this->currentTrackElem->jumpTime;
    431       this->addPoint(this->currentTrackElem->curve->getNode(this->currentTrackElem->curve->getNodeCount()), this->currentTrackElem->getChild(i));
    432     }
     442      // setting up the Time
     443      newElem->startingTime = trackElem->endTime + trackElem->jumpTime;
     444      // adds the conection Point
     445      this->addPoint(trackElem->curve->getNode(trackElem->curve->getNodeCount()),
     446                     newElem);
     447      // add the new child to the childList.
     448      trackElem->children->add(newElem);
     449    }
     450
     451  // setting the Name of the new TrackElement to the name of the last one, if the childCount is one
    433452  if (childCount == 1)
    434     this->currentTrackElem->getChild(0)->setName(this->currentTrackElem->getName());
    435 }
    436 
    437 /**
    438    \brief Searches for a given trackID.
    439    \param trackID the trackID to search for.
    440    \returns The TrackElement #trackID if found, NULL otherwise.
    441 */
    442 TrackElement* TrackManager::findTrackElementByID(unsigned int trackID) const
    443 {
    444   return firstTrackElem->findByID(trackID);
    445 }
    446 
    447 // INITIALIZE //
     453    trackElem->getChild(0)->setName(trackElem->getName());
     454}
     455
    448456
    449457/**
     
    453461void TrackManager::workOn(unsigned int trackID)
    454462{
    455   TrackElement* tmpElem = findTrackElementByID(trackID);
     463  TrackElement* tmpElem = this->firstTrackElem->findByID(trackID);
    456464  if (tmpElem)
    457465    this->currentTrackElem = tmpElem;
    458466  else
    459     PRINTF(2)("TrackElement not Found, leaving unchanged\n");
     467    PRINTF(2)("TrackElement %d not Found, leaving unchanged\n", trackID);
    460468  PRINTF(4)("now Working on %d\n", this->currentTrackElem->ID);
    461 
     469}
     470
     471/**
     472   \brief Sets the TrackElement to work on
     473   \param trackName the Name of the Track to work on
     474*/
     475void TrackManager::workOn(const char* trackName)
     476{
     477  TrackElement* tmpElem = this->firstTrackElem->findByName(trackName);
     478  if (tmpElem)
     479    this->currentTrackElem = tmpElem;
     480  else
     481    PRINTF(2)("TrackElement %s not Found, leaving unchanged\n", trackName);
     482  PRINTF(4)("now Working on %d\n", this->currentTrackElem->ID);
    462483}
    463484
     
    466487   \param curveType The Type to set
    467488   \param trackElem the TrackElement that should get a new Curve.
     489
     490   \brief this will possibly get obsolete during the process.
    468491*/
    469492void TrackManager::setCurveType(CurveType curveType, TrackElement* trackElem)
     
    477500  switch (curveType)
    478501    {
    479     case BEZIERCURVE:
     502    case CURVE_BEZIER:
    480503      trackElem->curve = new BezierCurve();
    481504      break;
    482 
    483505    }
    484506}
     
    486508/**
    487509   \brief Sets the duration of the current path in seconds.
    488    \param time The duration in seconds.
    489 */
    490 
    491 void TrackManager::setDuration(float time)
    492 {
    493   this->currentTrackElem->duration = time;
    494   this->currentTrackElem->endTime = this->currentTrackElem->startingTime + time;
    495 }
    496 
    497 /**
    498    \brief adds a point to the current TrackElement
    499    \param newPoint The point to add.
    500 */
    501 bool TrackManager::addPoint(Vector newPoint)
    502 {
    503   return this->addPoint(newPoint, this->currentTrackElem);
     510   \param duration The duration in seconds.
     511   \param trackElem The TrackElement to apply this to.
     512*/
     513void TrackManager::setDuration(float duration, TrackElement* trackElem)
     514{
     515  if (!trackElem)
     516    trackElem = this->currentTrackElem;
     517
     518  trackElem->duration = duration;
     519  trackElem->endTime = trackElem->startingTime + duration;
    504520}
    505521
     
    511527bool TrackManager::addPoint(Vector newPoint, TrackElement* trackElem)
    512528{
     529  if (!trackElem)
     530    trackElem = this->currentTrackElem;
     531
    513532  if (trackElem->isFresh)
    514533    {
     
    525544   \returns A Pointer to a newly appended Curve
    526545*/
    527 int TrackManager::addHotPoint(Vector newPoint)
    528 {
     546int TrackManager::addHotPoint(Vector newPoint, TrackElement* trackElem)
     547{
     548  if (!trackElem)
     549    trackElem = this->currentTrackElem;
     550
    529551  PRINTF(4)("setting up a HotPoint\n");
    530   if (this->currentTrackElem->isFresh)
    531     {
    532       this->setCurveType(BEZIERCURVE);
    533       this->currentTrackElem->isFresh = false;
     552  if (trackElem->isFresh)
     553    {
     554      trackElem->isFresh = false;
    534555    }
    535556
    536557  // \todo HotPoint Handling.
    537   this->currentTrackElem->curve->addNode(newPoint);
    538   this->currentTrackElem->nodeCount++;
     558  trackElem->curve->addNode(newPoint);
     559  trackElem->nodeCount++;
    539560  this->initChildren(1);
    540561  this->currentTrackElem = this->currentTrackElem->getChild(0);
     
    622643void TrackManager::condition(unsigned int groupID, CONDITION cond, void* subject)
    623644{
    624   TrackElement* tmpElem = this->findTrackElementByID(groupID);
     645  TrackElement* tmpElem = this->firstTrackElem->findByID(groupID);
    625646  if (!tmpElem->isFork)
    626647    {
     
    688709
    689710  // checking if there is a back-loop-connection and ERROR if it is.
    690   TrackElement* tmpTrackElem = this->findTrackElementByID(trackIDs[0]);
     711  TrackElement* tmpTrackElem = this->firstTrackElem->findByID(trackIDs[0]);
    691712  if (!tmpTrackElem->backLoopCheck(tmpTrackElem))
    692713    PRINTF(2)("Backloop connection detected at joining trackElements\n");
     
    708729  for (int i = 0; i < count; i++)
    709730    {
    710       TrackElement* tmpJoinElem = this->findTrackElementByID(trackIDs[i]);
     731      TrackElement* tmpJoinElem = this->firstTrackElem->findByID(trackIDs[i]);
    711732      if (tmpJoinElem->childCount == 0
    712733          && tmpJoinElem->endTime > tmpLatestTime)
     
    719740  for (int i = 1; i < count; i++)
    720741    {
    721       TrackElement* tmpJoinElem = this->findTrackElementByID(trackIDs[i]);
     742      TrackElement* tmpJoinElem = this->firstTrackElem->findByID(trackIDs[i]);
    722743      if (tmpJoinElem->childCount > 0)
    723744        printf("!!This Curve has children, and as such will not be joined!!\n You can try joining other childless TrackElements to this one!");
     
    767788  for (int i = 1; i<= trackElemCount ;i++)
    768789    {
    769       TrackElement* tmpElem = findTrackElementByID(i);
     790      TrackElement* tmpElem = this->firstTrackElem->findByID(i);
    770791      if( tmpElem->childCount > 0 && tmpElem->mainJoin)
    771792        {
     
    799820    }
    800821  for (int i = 1; i <=trackElemCount;i++)
    801     if (this->findTrackElementByID(i)->endTime > this->maxTime)
    802       this->maxTime = findTrackElementByID(i)->endTime; // very bad implemented :/
     822    if (this->firstTrackElem->findByID(i)->endTime > this->maxTime)
     823      this->maxTime = this->firstTrackElem->findByID(i)->endTime; // very bad implemented :/
    803824}
    804825
     
    925946    {
    926947      glBegin(GL_LINE_STRIP);
    927       TrackElement* tmpElem = this->findTrackElementByID(i);
     948      TrackElement* tmpElem = this->firstTrackElem->findByID(i);
    928949      if (tmpElem->curve)
    929950        for(float f = 0.0; f < 1.0; f+=dt)
     
    953974      for (int i = 1; i <= trackElemCount; i++)
    954975        {
    955           TrackElement* tmpElem = this->findTrackElementByID(i);
     976          TrackElement* tmpElem = this->firstTrackElem->findByID(i);
    956977          tmpElem->debug();
    957978        }
  • orxonox/trunk/src/track_manager.h

    r3835 r3836  
    2121
    2222//! The Default Curve-Type to set for the whole path (if not chosen otherwise).
    23 #define TMAN_DEFAULT_CURVETYPE BEZIERCURVE
     23#define TMAN_DEFAULT_CURVETYPE CURVE_BEZIER
    2424#define TMAN_DEFAULT_DURATION 10
    2525#define TMAN_DEFAULT_WIDTH    10
     
    139139  PNode* trackNode;                   //!< The main TrackNode of this Track.
    140140 
    141   void initChildren(unsigned int childCount);
     141  void initChildren(unsigned int childCount, TrackElement* trackElem = NULL);
    142142
    143   TrackElement* findTrackElementByID(unsigned int trackID) const;
    144  
    145143 public:
    146144  virtual ~TrackManager(void);
     
    150148  // Methods to change the Path (initialisation)
    151149  void workOn(unsigned int trackID);
     150  void workOn(const char* trackName);
     151
    152152  /** \see setCurveType(CurveType curveType, TrackElement* trackElem); \param curveType the type of the Curve */
    153153  inline void setCurveType(CurveType curveType) { this->setCurveType (curveType, this->currentTrackElem);};
    154154  void setCurveType(CurveType curveType, TrackElement* trackElem);
    155   void setDuration(float time);
    156   bool addPoint(Vector newPoint);
    157   bool addPoint(Vector newPoint, TrackElement* trackElem);
    158   int addHotPoint(Vector newPoint);
     155  void setDuration(float duration, TrackElement* trackElem = NULL);
     156  bool addPoint(Vector newPoint, TrackElement* trackElem = NULL);
     157  int addHotPoint(Vector newPoint, TrackElement* trackElem = NULL);
    159158  int setSavePoint(void);
    160159  void fork(unsigned int count, ...);
  • orxonox/trunk/src/track_node.h

    r3556 r3836  
    1717class TrackManager;
    1818
    19 class TrackNode : public PNode {
     19class TrackNode : public PNode
     20{
    2021
    2122 public:
Note: See TracChangeset for help on using the changeset viewer.