Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/util/track/track.cc @ 10088

Last change on this file since 10088 was 10088, checked in by patrick, 18 years ago

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 size: 6.9 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2006 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12
13   This is anohter installment of the infamous track system. It serves for
14   temporary use only and is mainly a slimmed version of the old track.
15
16   The track is used to steer the spaceship. In this case the track will have
17   to control a PNode. The spaceship will be able to fly around this node.
18   The camera will always be focused on that point.
19
20   As we do this we have exactly the verticalscroller feeling we want.
21
22   main-programmer: Benjamin Knecht
23*/
24
25#include "util/loading/load_param.h"
26#include "track/track.h"
27
28#include "track/track_manager.h"
29#include "p_node.h"
30
31#include "debug.h"
32
33ObjectListDefinition(Track);
34// CREATE_FACTORY(Track);
35
36
37/**
38 *  standard constructor
39*/
40Track::Track()
41{
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);
76}
77
78/**
79 *  standard destructor
80*/
81Track::~Track()
82{
83  if( this->firstTrackElem)
84    delete this->firstTrackElem;
85}
86
87
88void Track::loadParams(const TiXmlElement* root)
89{
90     LOAD_PARAM_START_CYCLE(root, element);
91     {
92           LoadParam_CYCLE(element, "Point", this, Track, addPoint)
93             .describe("Adds a new Point to the currently selected TrackElement");
94
95     }
96     LOAD_PARAM_END_CYCLE(element);
97}
98
99
100
101/**
102 *
103 * @param x
104 * @param y
105 * @param z
106 */
107void Track::addPoint(float x, float y, float z)
108{
109     this->addPoint(Vector (x,y,z));
110}
111
112
113/**
114 *
115 * @param newPoint
116 */
117void Track::addPoint(Vector newPoint)
118{
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 */
131void Track::finalize()
132{
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
169  /*for (int i = 1; i <= trackElemCount;i++)
170    if (this->firstTrackElem->findByID(i)->endTime > this->maxTime)
171      this->maxTime = this->firstTrackElem->findByID(i)->endTime; // very bad implemented :/
172      */
173}
174
175Vector TrackManager::calcPos() const
176{
177  return this->currentTrackElem->curve->calcPos((this->localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration);
178}
179
180Vector TrackManager::calcDir() const
181{
182  return this->currentTrackElem->curve->calcDir((this->localTime - this->currentTrackElem->startingTime)/this->currentTrackElem->duration);
183}
184
185void Track::tick(float dt)
186{
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//     }
219}
220
221/**
222 * @returns the main TrackNode
223*/
224PNode* TrackManager::getTrackNode()
225{
226  return this->trackNode;
227}
Note: See TracBrowser for help on using the repository browser.