Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 18, 2006, 1:28:49 AM (17 years ago)
Author:
patrick
Message:

added the track subsystem to the buildprocess again, integrated it into the new basobject framework and commented out big regions of code because it didn't compile.
@beni: your work now can begin :D

File:
1 edited

Legend:

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

    r10085 r10088  
    1313   This is anohter installment of the infamous track system. It serves for
    1414   temporary use only and is mainly a slimmed version of the old track.
    15    
     15
    1616   The track is used to steer the spaceship. In this case the track will have
    1717   to control a PNode. The spaceship will be able to fly around this node.
    1818   The camera will always be focused on that point.
    19    
     19
    2020   As we do this we have exactly the verticalscroller feeling we want.
    21    
     21
    2222   main-programmer: Benjamin Knecht
    2323*/
    2424
    2525#include "util/loading/load_param.h"
    26 
    27 #include "class_id_DEPRECATED.h"
     26#include "track/track.h"
     27
     28#include "track/track_manager.h"
     29#include "p_node.h"
     30
     31#include "debug.h"
    2832
    2933ObjectListDefinition(Track);
    30 CREATE_FACTORY(Track);
     34// CREATE_FACTORY(Track);
     35
    3136
    3237/**
     
    3540Track::Track()
    3641{
    37       this->firstTrackElem = new TrackElement();
    38       this->firstTrackElem->ID = 1;
    39       this->firstTrackElem->setName("root");
    40      
    41       this->currentTrackElem = firstTrackElem;
    42      
    43       this->curveType = CURVE_BEZIER;
    44       this->trackElemCount = 1;
    45      
    46       this->trackNode = new PNode(PNode::getNullParent(), PNODE_ALL);
     42  this->init();
     43}
     44
     45
     46/**
     47 * this is a constructor for use with the xml loading file
     48 * @param root xml root element for this object
     49 */
     50Track::Track(const TiXmlElement* root)
     51{
     52  this->init();
     53}
     54
     55
     56/**
     57 * initializes this class
     58 */
     59void Track::init()
     60{
     61  // resetting all elements
     62  this->firstTrackElem = NULL;
     63
     64
     65  // make a debug track
     66  this->firstTrackElem = new TrackElement();
     67  this->firstTrackElem->ID = 1;
     68  this->firstTrackElem->setName("root");
     69
     70  this->currentTrackElem = firstTrackElem;
     71
     72  this->curveType = CURVE_BEZIER;
     73  this->trackElemCount = 1;
     74
     75  this->trackNode = new PNode(PNode::getNullParent(), PNODE_ALL);
    4776}
    4877
     
    5281Track::~Track()
    5382{
    54   delete this->firstTrackElem;
    55 }
     83  if( this->firstTrackElem)
     84    delete this->firstTrackElem;
     85}
     86
    5687
    5788void Track::loadParams(const TiXmlElement* root)
     
    6192           LoadParam_CYCLE(element, "Point", this, Track, addPoint)
    6293             .describe("Adds a new Point to the currently selected TrackElement");
    63            
     94
    6495     }
    6596     LOAD_PARAM_END_CYCLE(element);
    6697}
    6798
     99
     100
     101/**
     102 *
     103 * @param x
     104 * @param y
     105 * @param z
     106 */
    68107void Track::addPoint(float x, float y, float z)
    69108{
     
    71110}
    72111
     112
     113/**
     114 *
     115 * @param newPoint
     116 */
    73117void Track::addPoint(Vector newPoint)
    74118{
    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 
     119//   if (this->currentTrackElem->isFresh)
     120//     {
     121//       this->setCurveType(CURVE_BEZIER, this->currentTrackElem);
     122//       this->currentTrackElem->isFresh = false;
     123//     }
     124//   trackElem->curve->addNode(newPoint);
     125//   trackElem->nodeCount++;
     126}
     127
     128/**
     129 *
     130 */
    84131void Track::finalize()
    85132{
    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     }
     133//   for (int i = 1; i<= trackElemCount ;i++)
     134//     {
     135//       TrackElement* tmpElem = this->firstTrackElem->findByID(i);
     136//       if( tmpElem->childCount > 0)
     137//         {
     138//           tIterator<TrackElement>* iterator = tmpElem->children->getIterator();
     139//           TrackElement* enumElem = iterator->firstElement();
     140//           //TrackElement* enumElem = tmpElem->children->enumerate();
     141//           while (enumElem)
     142//             {
     143//
     144//               // c1-continuity
     145//               enumElem->curve->addNode(enumElem->curve->getNode(0) +
     146//                                                    ((enumElem->curve->getNode(0) -
     147//                                                     tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1))
     148//                                                     ),2);
     149//               enumElem->nodeCount++;
     150//               // c2-continuity
     151//               enumElem->curve->addNode((tmpElem->curve->getNode(tmpElem->curve->getNodeCount())-
     152//                                                     tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1)) * 4 +
     153//                                                    tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-2), 3);
     154//               enumElem->nodeCount++;
     155//               PRINTF(5)("accelerations: %d-in: count: %d, %f, %f, %f\n                  %d-out: count: %d %f, %f, %f\n",
     156//                      tmpElem->ID, tmpElem->nodeCount,
     157//                      tmpElem->curve->calcAcc(0.999).x, tmpElem->curve->calcAcc(0.999).y, tmpElem->curve->calcAcc(0.999).z,
     158//                      enumElem->ID, enumElem->nodeCount,
     159//                      enumElem->curve->calcAcc(0).x, enumElem->curve->calcAcc(0).y, enumElem->curve->calcAcc(0).z);
     160//
     161//               enumElem = iterator->nextElement();
     162//             }
     163//           delete iterator;
     164//         }
     165//     }
     166
     167
     168
    119169  /*for (int i = 1; i <= trackElemCount;i++)
    120170    if (this->firstTrackElem->findByID(i)->endTime > this->maxTime)
     
    135185void Track::tick(float dt)
    136186{
    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     }
     187//   PRINTF(4)("CurrentTrackID: %d, LocalTime is: %f, timestep is: %f\n", this->currentTrackElem->ID, this->localTime, dt);
     188//   if (this->localTime <= this->firstTrackElem->duration)
     189//     this->jumpTo(this->localTime);
     190//   if (this->localTime <= this->maxTime)
     191//     this->localTime += dt;
     192//   if (this->localTime > this->currentTrackElem->endTime
     193//       && this->currentTrackElem->children)
     194//     {
     195//       if (this->currentTrackElem->jumpTime != 0.0)
     196//         this->jumpTo(this->localTime + this->currentTrackElem->jumpTime);
     197//       // jump to the next TrackElement and also set the history of the new Element to the old one.
     198//       TrackElement* tmpHistoryElem = this->currentTrackElem;
     199//       this->currentTrackElem = this->currentTrackElem->getChild(this->choosePath(this->currentTrackElem));
     200//       this->currentTrackElem->history = tmpHistoryElem;
     201//       if (this->currentTrackElem->getName())
     202//         {
     203//           this->trackText->setText(this->currentTrackElem->getName());
     204//           this->textAnimation->replay();
     205//         }
     206//     }
     207//   if (this->bindSlave)
     208//     {
     209//       Vector tmp = this->calcPos();
     210//       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));
     211//
     212//       Vector v(0.0, 1.0, 0.0);
     213//       Quaternion q(-PI/2, v);
     214//       quat = quat * q;
     215//
     216//       this->bindSlave->setAbsCoor(tmp);
     217//       this->bindSlave->setAbsDir(quat);
     218//     }
    169219}
    170220
Note: See TracChangeset for help on using the changeset viewer.