Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10085 in orxonox.OLD for branches/playability/src/util


Ignore:
Timestamp:
Dec 17, 2006, 6:27:52 PM (18 years ago)
Author:
bknecht
Message:

filled the files with half of the needed methods and stuff

Location:
branches/playability/src/util/track
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/playability/src/util/track/track.cc

    r10084 r10085  
    2323*/
    2424
     25#include "util/loading/load_param.h"
     26
     27#include "class_id_DEPRECATED.h"
     28
     29ObjectListDefinition(Track);
     30CREATE_FACTORY(Track);
     31
    2532/**
    2633 *  standard constructor
     
    2835Track::Track()
    2936{
     37      this->firstTrackElem = new TrackElement();
     38      this->firstTrackElem->ID = 1;
     39      this->firstTrackElem->setName("root");
    3040     
     41      this->currentTrackElem = firstTrackElem;
     42     
     43      this->curveType = CURVE_BEZIER;
     44      this->trackElemCount = 1;
     45     
     46      this->trackNode = new PNode(PNode::getNullParent(), PNODE_ALL);
    3147}
     48
     49/**
     50 *  standard destructor
     51*/
     52Track::~Track()
     53{
     54  delete this->firstTrackElem;
     55}
     56
     57void Track::loadParams(const TiXmlElement* root)
     58{
     59     LOAD_PARAM_START_CYCLE(root, element);
     60     {
     61           LoadParam_CYCLE(element, "Point", this, Track, addPoint)
     62             .describe("Adds a new Point to the currently selected TrackElement");
     63           
     64     }
     65     LOAD_PARAM_END_CYCLE(element);
     66}
     67
     68void Track::addPoint(float x, float y, float z)
     69{
     70     this->addPoint(Vector (x,y,z));
     71}
     72
     73void Track::addPoint(Vector newPoint)
     74{
     75  if (this->currentTrackElem->isFresh)
     76    {
     77      this->setCurveType(CURVE_BEZIER, this->currentTrackElem);
     78      this->currentTrackElem->isFresh = false;
     79    }
     80  trackElem->curve->addNode(newPoint);
     81  trackElem->nodeCount++;
     82}
     83
     84void Track::finalize()
     85{
     86  for (int i = 1; i<= trackElemCount ;i++)
     87    {
     88      TrackElement* tmpElem = this->firstTrackElem->findByID(i);
     89      if( tmpElem->childCount > 0)
     90        {
     91          tIterator<TrackElement>* iterator = tmpElem->children->getIterator();
     92          TrackElement* enumElem = iterator->firstElement();
     93          //TrackElement* enumElem = tmpElem->children->enumerate();
     94          while (enumElem)
     95            {
     96
     97              // c1-continuity
     98              enumElem->curve->addNode(enumElem->curve->getNode(0) +
     99                                                   ((enumElem->curve->getNode(0) -
     100                                                    tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1))
     101                                                    ),2);
     102              enumElem->nodeCount++;
     103              // c2-continuity
     104              enumElem->curve->addNode((tmpElem->curve->getNode(tmpElem->curve->getNodeCount())-
     105                                                    tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1)) * 4 +
     106                                                   tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-2), 3);
     107              enumElem->nodeCount++;
     108              PRINTF(5)("accelerations: %d-in: count: %d, %f, %f, %f\n                  %d-out: count: %d %f, %f, %f\n",
     109                     tmpElem->ID, tmpElem->nodeCount,
     110                     tmpElem->curve->calcAcc(0.999).x, tmpElem->curve->calcAcc(0.999).y, tmpElem->curve->calcAcc(0.999).z,
     111                     enumElem->ID, enumElem->nodeCount,
     112                     enumElem->curve->calcAcc(0).x, enumElem->curve->calcAcc(0).y, enumElem->curve->calcAcc(0).z);
     113
     114              enumElem = iterator->nextElement();
     115            }
     116          delete iterator;
     117        }
     118    }
     119  /*for (int i = 1; i <= trackElemCount;i++)
     120    if (this->firstTrackElem->findByID(i)->endTime > this->maxTime)
     121      this->maxTime = this->firstTrackElem->findByID(i)->endTime; // very bad implemented :/
     122      */
     123}
     124
     125Vector TrackManager::calcPos() const
     126{
     127  return this->currentTrackElem->curve->calcPos((this->localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration);
     128}
     129
     130Vector TrackManager::calcDir() const
     131{
     132  return this->currentTrackElem->curve->calcDir((this->localTime - this->currentTrackElem->startingTime)/this->currentTrackElem->duration);
     133}
     134
     135void Track::tick(float dt)
     136{
     137  PRINTF(4)("CurrentTrackID: %d, LocalTime is: %f, timestep is: %f\n", this->currentTrackElem->ID, this->localTime, dt);
     138  if (this->localTime <= this->firstTrackElem->duration)
     139    this->jumpTo(this->localTime);
     140  if (this->localTime <= this->maxTime)
     141    this->localTime += dt;
     142  if (this->localTime > this->currentTrackElem->endTime
     143      && this->currentTrackElem->children)
     144    {
     145      if (this->currentTrackElem->jumpTime != 0.0)
     146        this->jumpTo(this->localTime + this->currentTrackElem->jumpTime);
     147      // jump to the next TrackElement and also set the history of the new Element to the old one.
     148      TrackElement* tmpHistoryElem = this->currentTrackElem;
     149      this->currentTrackElem = this->currentTrackElem->getChild(this->choosePath(this->currentTrackElem));
     150      this->currentTrackElem->history = tmpHistoryElem;
     151      if (this->currentTrackElem->getName())
     152        {
     153          this->trackText->setText(this->currentTrackElem->getName());
     154          this->textAnimation->replay();
     155        }
     156    }
     157  if (this->bindSlave)
     158    {
     159      Vector tmp = this->calcPos();
     160      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));
     161
     162      Vector v(0.0, 1.0, 0.0);
     163      Quaternion q(-PI/2, v);
     164      quat = quat * q;
     165
     166      this->bindSlave->setAbsCoor(tmp);
     167      this->bindSlave->setAbsDir(quat);
     168    }
     169}
     170
     171/**
     172 * @returns the main TrackNode
     173*/
     174PNode* TrackManager::getTrackNode()
     175{
     176  return this->trackNode;
     177}
  • branches/playability/src/util/track/track.h

    r10084 r10085  
    99#include "base_object.h"
    1010
     11// Forward Definition
     12class PNode;
     13class TiXmlElement;
     14
    1115class Track : public BaseObject
    1216{
     17 public:
     18      virtual void loadParams(const TiXmlElement* root);
     19      void addPoint(float x, float y, float z);
     20      void addPoint(Vector newPoint);
    1321     
     22      void finalize();
     23      inline Vector calcPos() const;
     24      inline Vector calcDir() const;
     25      void tick(float dt);
    1426     
     27      PNode* getTrackNode();
     28 
     29 private:
     30      TrackElement*        firstTrackElem;         //!< The first TrackElement that exists.
     31      TrackElement*        currentTrackElem;       //!< The TrackElement we are working on.
     32      CurveType            curveType;              //!< The CurveType the entire TrackSystem will have.
     33      int                  trackElemCount;         //!< The count of TrackElements that exist.
    1534     
    16      
    17 }
     35      PNode*               trackNode;              //!< The node that is slave to the Track. This node will be moved while update the Track, and must NOT move itself.
     36};
     37
     38#endif /* _TRACK_H */
Note: See TracChangeset for help on using the changeset viewer.