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