Changeset 3332 in orxonox.OLD for orxonox/branches/parenting/src
- Timestamp:
- Jan 4, 2005, 3:51:32 PM (20 years ago)
- Location:
- orxonox/branches/parenting/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/parenting/src/track_manager.cc
r3331 r3332 18 18 19 19 #include "track_manager.h" 20 #include <stdarg.h> 20 21 21 22 … … 27 28 TrackElement::TrackElement(void) 28 29 { 30 this->isFresh = true; 29 31 this->isSavePoint = false; 30 32 this->isFork = false; … … 36 38 this->nodeCount = 0; 37 39 childCount = 0; 40 this->name = NULL; 38 41 this->curve = NULL; 39 42 this->children = NULL; … … 41 44 42 45 /** 43 \ destroys all alocated memory)46 \brief destroys all alocated memory) 44 47 \todo eventually when deleting a TrackElement you would not like to delete all its preceding TrackElements 45 48 */ 46 49 TrackElement::~TrackElement(void) 47 50 { 51 if (this->name) 52 delete []name; 48 53 if (this->curve) 49 54 delete this->curve; … … 55 60 } 56 61 57 58 59 62 /** 63 \brief Searches through all the TrackElements for trackID. 64 \param trackID The ID to search for. 65 \returns The TrackElement if Found, NULL otherwise. 66 67 \todo make this more modular, to search for different things 68 */ 69 TrackElement* TrackElement::findByID(unsigned int trackID) 70 { 71 // return if Found. 72 if (this->ID == trackID) 73 return this; 74 // search on. 75 if (this->childCount > 0) 76 for (int i=0; i < this->childCount; i++) 77 { 78 TrackElement* tmpElem; 79 if ((tmpElem = this->children[i]->findByID(trackID))) 80 return tmpElem; 81 } 82 else return NULL; 83 } 84 85 86 87 88 89 ///////////////////////////////////// 90 ///// TRACKMANAGER ////////////////// 91 ///////////////////////////////////// 60 92 /** 61 93 \brief standard constructor … … 109 141 \brief Searches for a given trackID. 110 142 \param trackID the trackID to search for. 111 \returns The TrackElement #trackID if found, NULL otherw ays.112 */ 113 TrackElement TrackManager::findTrackElementByID(int trackID)114 { 115 143 \returns The TrackElement #trackID if found, NULL otherwise. 144 */ 145 TrackElement* TrackManager::findTrackElementByID(unsigned int trackID) const 146 { 147 return firstTrackElem->findByID(trackID); 116 148 } 117 149 … … 122 154 \param trackID the trackID we are working on 123 155 */ 124 void TrackManager::workOn( int trackID)125 { 126 156 void TrackManager::workOn(unsigned int trackID) 157 { 158 this->currentTrackElem = findTrackElementByID(trackID); 127 159 } 128 160 … … 131 163 \brief curveType The Type to set 132 164 */ 133 void TrackManager::setType(CurveType curveType) 134 { 135 165 void TrackManager::setCurveType(CurveType curveType) 166 { 167 if (!this->currentTrackElem->isFresh) 168 { 169 PRINTF(2)("It is not possible to change the type of a Curve after you have have appended some points to it\n"); 170 return; 171 } 172 this->currentTrackElem->curveType = curveType; 173 switch (curveType) 174 { 175 case BEZIERCURVE: 176 this->currentTrackElem->curve = new BezierCurve(); 177 break; 178 case UPOINTCURVE: 179 this->currentTrackElem->curve = new UPointCurve(); 180 break; 181 } 136 182 } 137 183 … … 143 189 void TrackManager::setLength(float time) 144 190 { 145 191 this->currentTrackElem->length = time; 146 192 } 147 193 … … 152 198 void TrackManager::addPoint(Vector newPoint) 153 199 { 154 200 if (this->currentTrackElem->isFresh) 201 { 202 this->setCurveType(BEZIERCURVE); 203 this->currentTrackElem->isFresh = false; 204 } 205 this->currentTrackElem->curve->addNode(newPoint); 155 206 } 156 207 … … 161 212 void TrackManager::addHotPoint(Vector newPoint) 162 213 { 163 214 if (this->currentTrackElem->isFresh) 215 { 216 this->setCurveType(BEZIERCURVE); 217 this->currentTrackElem->isFresh = false; 218 } 219 220 // \todo HotPoint Handling. 221 this->currentTrackElem->curve->addNode(newPoint); 164 222 } 165 223 … … 172 230 void TrackManager::setSavePoint(void) 173 231 { 174 232 if (this->currentTrackElem->isFork || this->currentTrackElem->isSavePoint) 233 return; 234 this->currentTrackElem->isSavePoint = true; 235 236 this->currentTrackElem->children = new TrackElement*[1]; 175 237 } 176 238 … … 182 244 If the HotPoint was defined as a savePoint the Point will \b not be set into a fork. 183 245 */ 184 void TrackManager::fork(int count, ...) 185 { 186 246 void TrackManager::fork(unsigned int count, ...) 247 { 248 int* trackIDs = new int [count]; 249 va_list ID; 250 va_start (ID, count); 251 for(int i = 0; i < count; i++) 252 { 253 trackIDs[i] = va_arg (ID, int); 254 } 255 va_end(ID); 256 this->forkV(count, trackIDs); 257 delete []trackIDs; 187 258 } 188 259 … … 193 264 194 265 \see void TrackManager::fork(int count, ...) 195 */ 196 void TrackManager::forkV(int count, int* trackIDs) 197 { 198 266 267 \todo initialisation is wrong!! also in setSavePoint. 268 */ 269 void TrackManager::forkV(unsigned int count, int* trackIDs) 270 { 271 if (this->currentTrackElem->isSavePoint) 272 return; 273 this->currentTrackElem->isFork = true; 274 275 this->currentTrackElem->children = new TrackElement*[count]; 199 276 } 200 277 … … 204 281 \param cond \todo think about this 205 282 */ 206 void TrackManager::condition( int groupID, PathCondition cond)207 { 208 283 void TrackManager::condition(unsigned int groupID, PathCondition cond) 284 { 285 209 286 } 210 287 … … 216 293 Join will join all curves to the first curve. 217 294 */ 218 void TrackManager::join(int count, ...) 219 { 220 295 void TrackManager::join(unsigned int count, ...) 296 { 297 int* trackIDs = new int [count]; 298 va_list ID; 299 va_start (ID, count); 300 for(int i = 0; i < count; i++) 301 { 302 trackIDs[i] = va_arg (ID, int); 303 } 304 va_end(ID); 305 this->joinV(count, trackIDs); 306 delete []trackIDs; 221 307 } 222 308 … … 228 314 \see void TrackManager::join(int count, ...) 229 315 */ 230 void TrackManager::joinV( int count, int* trackIDs)231 { 232 316 void TrackManager::joinV(unsigned int count, int* trackIDs) 317 { 318 //! \todo this 233 319 } 234 320 … … 239 325 \returns the calculated Position 240 326 */ 241 Vector TrackManager::calcPos() 242 { 243 327 Vector TrackManager::calcPos() const 328 { 329 244 330 } 245 331 … … 248 334 \returns the calculated Rotation 249 335 */ 250 Vector TrackManager::calcDir() 336 Vector TrackManager::calcDir() const 251 337 { 252 338 … … 259 345 void TrackManager::tick(float dt) 260 346 { 261 347 this->localTime += dt; 262 348 } 263 349 … … 271 357 void TrackManager::jumpTo(float time) 272 358 { 273 359 localTime = time; 274 360 } 275 361 -
orxonox/branches/parenting/src/track_manager.h
r3331 r3332 33 33 ~TrackElement(void); 34 34 35 TrackElement* findByID(unsigned int trackID); 36 37 bool isFresh; //!< If no Points where added until now 35 38 bool isSavePoint; //!< If the first node is a savePoint 36 39 bool isFork; //!< If the first node is a Fork … … 41 44 CurveType curveType; //!< The CurveType this will have. 42 45 int nodeCount; //!< The count of points this TrackElement has. 46 char* name; //!< A name for the Trac. 43 47 Curve* curve; //!< The Curve of this TrackElement 44 48 int childCount; //!< The number of Children This TrackElement has. … … 56 60 <b>1. Initialize it, by setting up the Graph. You can do this by using the following Commands.</b> 57 61 \li workOn(): changes the ID that will be altered through the changes. 58 \li set Type: 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).62 \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). 59 63 \li setLength(): sets the length of the current path in seconds. 60 64 \li addPoint(): adds a point to the Curve. … … 65 69 \li setSavePoint(): Sets a HotPoint into a savePoint. A Savepoint can be used as a rollbackpoint if a Player gets shot. 66 70 67 71 HotPoints and Joins are at the beginning of a TrackElement. \n 72 SavePoints and Forks are at the end of a TrackElement \n 68 73 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 69 74 \n … … 90 95 static TrackManager* singletonRef; //!< There may only be one TrackManager existing. 91 96 TrackElement* firstTrackElem; //!< The first TrackElement that exists. 92 TrackElement* currentTrackElem; 97 TrackElement* currentTrackElem; //!< The TrackElement we are working on. 93 98 float localTime; //!< The time that has been passed since the traveling the Track. 94 99 float maxTime; //!< The maximal time the track has. … … 96 101 97 102 98 TrackElement findTrackElementByID(int trackID);103 TrackElement* findTrackElementByID(unsigned int trackID) const; 99 104 100 105 … … 104 109 105 110 // Methods to change the Path (initialisation) 106 void workOn( int trackID);107 void set Type(CurveType curveType);111 void workOn(unsigned int trackID); 112 void setCurveType(CurveType curveType); 108 113 void setLength(float time); 109 114 void addPoint(Vector newPoint); 110 115 void addHotPoint(Vector newPoint); 111 116 void setSavePoint(void); 112 void fork( int count, ...);113 void forkV( int count, int* trackIDs);114 void condition( int groupID, PathCondition cond); //!< \todo really do this!!115 void join( int count, ...);116 void joinV( int count, int* trackIDs);117 void fork(unsigned int count, ...); 118 void forkV(unsigned int count, int* trackIDs); 119 void condition(unsigned int groupID, PathCondition cond); //!< \todo really do this!! 120 void join(unsigned int count, ...); 121 void joinV(unsigned int count, int* trackIDs); 117 122 118 123 // Methods to calculate the position on the Path (runtime) 119 Vector calcPos( );120 Vector calcDir( );124 Vector calcPos(void) const; 125 Vector calcDir(void) const; 121 126 void tick(float dt); 122 127 void jumpTo(float time);
Note: See TracChangeset
for help on using the changeset viewer.