Changeset 3433 in orxonox.OLD for orxonox/trunk/src/track_manager.cc
- Timestamp:
- Mar 1, 2005, 2:36:56 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/track_manager.cc
r3365 r3433 1 2 3 1 /* 4 2 orxonox - the future of 3D-vertical-scrollers … … 12 10 13 11 ### File Specific: 14 main-programmer: Patrick Boenzli12 main-programmer: Benjamin Grauer 15 13 co-programmer: ... 16 14 */ … … 19 17 #include "track_manager.h" 20 18 #include <stdarg.h> 21 19 #include "p_node.h" 22 20 23 21 using namespace std; … … 38 36 this->startingTime = 0; //!< \todo eventually set this to the max time of TrackManager. 39 37 this->duration = 1; 38 this->endTime = 1; 39 this->jumpTime = 0; 40 40 this->curveType = BEZIERCURVE; 41 41 this->nodeCount = 0; 42 42 this->childCount = 0; 43 43 this->name = NULL; 44 this->startPoint = Vector(0,0,0);45 this->startTangentPoint = Vector(0,0,0);46 44 this->curve = NULL; 47 45 this->children = NULL; … … 111 109 this->maxTime = 0; 112 110 this->trackElemCount = 1; 111 this->bindSlave = NULL; 113 112 } 114 113 … … 151 150 { 152 151 this->currentTrackElem->childCount = childCount; 152 this->currentTrackElem->mainJoin = true; 153 153 this->currentTrackElem->children = new TrackElement*[childCount]; 154 154 for (int i=0; i<childCount; i++) … … 156 156 this->currentTrackElem->children[i] = new TrackElement(); 157 157 this->currentTrackElem->children[i]->ID = ++trackElemCount; 158 this->currentTrackElem->children[i]->startingTime = this->currentTrackElem->startingTime+this->currentTrackElem->duration; 159 this->currentTrackElem->children[i]->startPoint = this->currentTrackElem->curve->getNode(this->currentTrackElem->curve->getNodeCount()); 160 this->currentTrackElem->children[i]->startTangentPoint = (this->currentTrackElem->children[i]->startPoint *2) - this->currentTrackElem->curve->getNode(this->currentTrackElem->curve->getNodeCount()-1); 158 this->currentTrackElem->children[i]->startingTime = this->currentTrackElem->endTime + this->currentTrackElem->jumpTime; 159 this->addPoint(this->currentTrackElem->curve->getNode(this->currentTrackElem->curve->getNodeCount()), this->currentTrackElem->children[i]); 161 160 } 162 161 } … … 193 192 \brief curveType The Type to set 194 193 */ 195 void TrackManager::setCurveType(CurveType curveType )196 { 197 if (!t his->currentTrackElem->isFresh)194 void TrackManager::setCurveType(CurveType curveType, TrackElement* trackElem) 195 { 196 if (!trackElem->isFresh) 198 197 { 199 198 PRINTF(2)("It is not possible to change the type of a Curve after you have have appended some points to it\n"); 200 199 return; 201 200 } 202 t his->currentTrackElem->curveType = curveType;201 trackElem->curveType = curveType; 203 202 switch (curveType) 204 203 { 205 204 case BEZIERCURVE: 206 t his->currentTrackElem->curve = new BezierCurve();205 trackElem->curve = new BezierCurve(); 207 206 break; 208 207 case UPOINTCURVE: 209 t his->currentTrackElem->curve = new UPointCurve();208 trackElem->curve = new UPointCurve(); 210 209 break; 211 210 } … … 220 219 { 221 220 this->currentTrackElem->duration = time; 221 this->currentTrackElem->endTime = this->currentTrackElem->startingTime + time; 222 222 } 223 223 … … 240 240 if (trackElem->isFresh) 241 241 { 242 this->setCurveType(BEZIERCURVE );242 this->setCurveType(BEZIERCURVE, trackElem); 243 243 trackElem->isFresh = false; 244 if(trackElem != this->firstTrackElem)245 {246 this->addPoint(trackElem->startPoint);247 this->addPoint(trackElem->startTangentPoint);248 }249 244 } 250 245 trackElem->curve->addNode(newPoint); … … 374 369 void TrackManager::joinV(unsigned int count, int* trackIDs) 375 370 { 376 printf("Joining %d tracks to Track %d\n", count, trackIDs[0]);371 printf("Joining %d tracks and merging to Track %d\n", count, trackIDs[0]); 377 372 378 373 // chanching work-on to temporary value. going back at the end. 379 374 int tmpCurrentWorkingID = this->currentTrackElem->ID; 380 375 this->workOn(trackIDs[0]); 381 382 376 TrackElement* firstJoint = this->currentTrackElem; 377 float tmpLatestTime = firstJoint->endTime; 378 383 379 Vector tmpEndPoint = firstJoint->curve->getNode(firstJoint->curve->getNodeCount()); 384 Vector tmpTangentPoint = firstJoint->curve->getNode(firstJoint->curve->getNodeCount()-1); 380 Vector tmpTangentPoint = firstJoint->curve->getNode(firstJoint->curve->getNodeCount()-1); 381 Vector tmpc2Point = firstJoint->curve->getNode(firstJoint->curve->getNodeCount()-2); 385 382 firstJoint->isJoined = true; 386 firstJoint->mainJoin = true;383 // firstJoint->mainJoin = true; 387 384 if(!firstJoint->isHotPoint) 388 385 this->setSavePoint(); 389 386 // Timing: 387 for (int i = 0; i < count; i++) 388 { 389 TrackElement* tmpJoinElem = this->findTrackElementByID(trackIDs[i]); 390 if (tmpJoinElem->childCount == 0 391 && tmpJoinElem->endTime > tmpLatestTime) 392 tmpLatestTime = tmpJoinElem->endTime; 393 } 394 // time the main Join. 395 firstJoint->jumpTime = tmpLatestTime - firstJoint->endTime; 396 397 // Joining: 390 398 for (int i = 1; i < count; i++) 391 399 { … … 395 403 else 396 404 { 405 this->addPoint(tmpc2Point, tmpJoinElem); 397 406 this->addPoint(tmpTangentPoint, tmpJoinElem); 398 407 this->addPoint(tmpEndPoint, tmpJoinElem); 408 // time all other Joins 409 tmpJoinElem->jumpTime = tmpLatestTime - tmpJoinElem->endTime; 399 410 400 411 //Copying Joint-Info … … 403 414 tmpJoinElem->isSavePoint = firstJoint->isSavePoint; 404 415 tmpJoinElem->isFork = firstJoint->isFork; 405 416 406 417 tmpJoinElem->isJoined = true; 407 418 } 408 419 } 420 if(firstJoint->childCount > 0) 421 for(int i = 0; i < firstJoint->childCount; i++) 422 { 423 printf("Setting startingTime of %d to %f.\n", firstJoint->children[i]->ID, tmpLatestTime); 424 firstJoint->children[i]->startingTime = tmpLatestTime; 425 firstJoint->children[i]->endTime = tmpLatestTime+firstJoint->children[i]->duration; 426 } 427 409 428 // returning to the TrackElement we were working on. 410 429 this->workOn(tmpCurrentWorkingID); 411 430 } 412 431 432 /** 433 \brief finalizes the TrackSystem. after this it will not be editable anymore 434 435 \todo check for any inconsistencies, output errors 436 */ 437 void TrackManager::finalize(void) 438 { 439 for (int i = 1; i<= trackElemCount ;i++) 440 { 441 TrackElement* tmpElem = findTrackElementByID(i); 442 if (tmpElem->childCount>0 && tmpElem->mainJoin) 443 { 444 for (int j = 0; j < tmpElem->childCount; j++) 445 { 446 447 // c1-continuity 448 tmpElem->children[j]->curve->addNode(tmpElem->children[j]->curve->getNode(0) + 449 ((tmpElem->children[j]->curve->getNode(0) - 450 tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1)) 451 ),2); 452 tmpElem->children[j]->nodeCount++; 453 // c2-continuity 454 tmpElem->children[j]->curve->addNode((tmpElem->curve->getNode(tmpElem->curve->getNodeCount())- 455 tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-1)) * 4 + 456 tmpElem->curve->getNode(tmpElem->curve->getNodeCount()-2), 3); 457 tmpElem->children[j]->nodeCount++; 458 printf("accelerations: %d-in: count: %d, %f, %f, %f\n %d-out: count: %d %f, %f, %f\n", 459 tmpElem->ID, tmpElem->nodeCount, 460 tmpElem->curve->calcAcc(0.999).x, tmpElem->curve->calcAcc(0.999).y, tmpElem->curve->calcAcc(0.999).z, 461 tmpElem->children[j]->ID, tmpElem->children[j]->nodeCount, 462 tmpElem->children[j]->curve->calcAcc(0).x, tmpElem->children[j]->curve->calcAcc(0).y, tmpElem->children[j]->curve->calcAcc(0).z); 463 } 464 } 465 } 466 } 467 468 413 469 // RUNTIME // 414 470 … … 429 485 Vector TrackManager::calcDir() const 430 486 { 431 return this->currentTrackElem->curve->calcDir((this->localTime -this->currentTrackElem->startingTime)/this->currentTrackElem->duration);487 return this->currentTrackElem->curve->calcDir((this->localTime - this->currentTrackElem->startingTime)/this->currentTrackElem->duration); 432 488 } 433 489 … … 440 496 void TrackManager::tick(float dt) 441 497 { 498 dt /= 1000; 499 printf("CurrentTrackID: %d, LocalTime is: %f, timestep is: %f\n", this->currentTrackElem->ID, this->localTime, dt); 442 500 if (this->localTime <= this->firstTrackElem->duration) 443 501 this->jumpTo(this->localTime); 444 502 this->localTime += dt; 445 if (this->localTime > this->currentTrackElem->startingTime + this->currentTrackElem->duration && this->currentTrackElem->childCount > 0) 446 this->currentTrackElem = this->currentTrackElem->children[0]; 503 if (this->localTime > this->currentTrackElem->endTime 504 && this->currentTrackElem->children) 505 { 506 if (this->currentTrackElem->jumpTime > 0) 507 this->jumpTo(this->localTime + this->currentTrackElem->jumpTime); 508 this->currentTrackElem = this->currentTrackElem->children[0]; 509 } 510 if (this->bindSlave) 511 { 512 Vector tmp = this->calcPos(); 513 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)); 514 this->bindSlave->setAbsCoor(&tmp); 515 this->bindSlave->setAbsDir(&quat); 516 } 447 517 } 448 518 … … 471 541 } 472 542 543 /** 544 \brief Sets the PNode, that should be moved along the Tack 545 \param bindSlave the PNode to set 546 */ 547 void TrackManager::setBindSlave(PNode* bindSlave) 548 { 549 if (!this->bindSlave) 550 this->bindSlave = bindSlave; 551 } 473 552 474 553 … … 500 579 } 501 580 581 /** 582 \brief outputs debug information about the trackManager 583 \param level how much debug 584 */ 502 585 void TrackManager::debug(unsigned int level) const 503 586 { … … 516 599 if(tmpElem->isFresh) 517 600 printf(" has not jet eddited in any way\n"); 518 printf("\n TimeTable: starting at = %f; ends at = %f; duration = %f\n", tmpElem->startingTime, tmpElem->startingTime+tmpElem->duration, tmpElem->duration);601 printf("\n TimeTable: startingTime=%f; endTime=%f; duration=%f; jumpTime=%f\n", tmpElem->startingTime, tmpElem->endTime, tmpElem->duration, tmpElem->jumpTime); 519 602 printf(" consists of %d Points\n", tmpElem->nodeCount); 520 603 if (tmpElem->childCount == 0) … … 536 619 if(tmpElem->isFork) 537 620 { 538 printf(" is A Fork with with %d children. ", tmpElem->childCount);621 printf(" is A Fork with with %d children.\n", tmpElem->childCount); 539 622 } 540 623 if(tmpElem->isJoined)
Note: See TracChangeset
for help on using the changeset viewer.