Changeset 3348 in orxonox.OLD for orxonox/branches/parenting
- Timestamp:
- Jan 6, 2005, 3:03:54 AM (20 years ago)
- Location:
- orxonox/branches/parenting/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/parenting/src/curve.cc
r3330 r3348 24 24 #include "curve.h" 25 25 #include "matrix.h" 26 #include "debug.h" 26 27 27 28 #include <math.h> … … 113 114 114 115 // rebuilding the Curve itself 115 int k=0; 116 int binCoef = 1; 117 while(tmpNode) 118 { 119 if (k+1 < nodeCount-k) 120 binCoef *=(nodeCount-k)/(k+1); 121 else 122 binCoef /= (k+1)/(nodeCount-k); 123 ++k; 116 float k=0; 117 float n = nodeCount -1; 118 float binCoef = 1; 119 printf("n=%f\n", n); 120 while(tmpNode) 121 { 124 122 tmpNode->factor = binCoef; 125 tmpNode = tmpNode->next; 123 printf("bincoef: %f\n", binCoef); 124 if (tmpNode =tmpNode->next) 125 { 126 binCoef *=(n-k)/(k+1); 127 ++k; 128 } 126 129 } 127 130 … … 149 152 \param t The position on the Curve (0<=t<=1) 150 153 \return the Position on the Path 154 \todo implement nodeCount 0,1,2,3 151 155 */ 152 156 Vector BezierCurve::calcPos(float t) 153 157 { 154 if (nodeCount < =4)158 if (nodeCount < 4) 155 159 { 156 160 // if (verbose >= 1) … … 160 164 PathNode* tmpNode = firstNode; 161 165 Vector ret = Vector(0.0,0.0,0.0); 162 float factor = 1.0*pow(1.0-t,nodeCount); 163 while(tmpNode) 164 { 165 factor *= t/(1.0-t); // same as pow but much faster. 166 double factor = pow(1.0-t,nodeCount-1); 167 while(tmpNode) 168 { 166 169 ret.x += tmpNode->factor * factor * tmpNode->position.x; 167 170 ret.y += tmpNode->factor * factor * tmpNode->position.y; 168 171 ret.z += tmpNode->factor * factor * tmpNode->position.z; 172 factor *= t/(1.0-t); // same as pow but much faster. 169 173 170 174 tmpNode = tmpNode->next; -
orxonox/branches/parenting/src/track_manager.cc
r3335 r3348 35 35 this->ID = -1; 36 36 this->startingTime = 0; //!< \todo eventually set this to the max time of TrackManager. 37 this->duration = 0;37 this->duration = 1; 38 38 this->curveType = BEZIERCURVE; 39 39 this->nodeCount = 0; 40 childCount = 0;40 this->childCount = 0; 41 41 this->name = NULL; 42 42 this->curve = NULL; … … 102 102 103 103 PRINTF(3)("Initializing the TrackManager\n"); 104 this->firstTrackElem = new TrackElement; 104 this->firstTrackElem = new TrackElement(); 105 this->firstTrackElem->ID = 1; 105 106 this->currentTrackElem = firstTrackElem; 106 107 this->localTime = 0; 107 108 this->maxTime = 0; 108 this->trackElemCount = 0;109 this->trackElemCount = 1; 109 110 } 110 111 … … 146 147 void TrackManager::initChildren(unsigned int childCount) 147 148 { 148 trackElemCount = 0;149 149 this->currentTrackElem->childCount = childCount; 150 150 this->currentTrackElem->children = new TrackElement*[childCount]; 151 151 for (int i=0; i<childCount; i++) 152 this->currentTrackElem->children[i] = new TrackElement(); 152 { 153 this->currentTrackElem->children[i] = new TrackElement(); 154 this->currentTrackElem->children[i]->ID = ++trackElemCount; 155 this->currentTrackElem->children[i]->startingTime = this->currentTrackElem->startingTime+this->currentTrackElem->duration; 156 } 153 157 } 154 158 … … 252 256 253 257 this->initChildren(1); 258 this->currentTrackElem = this->currentTrackElem->children[0]; 254 259 } 255 260 … … 344 349 Vector TrackManager::calcPos() const 345 350 { 346 return this->currentTrackElem->curve->calcPos(this->localTime); 351 // PRINTF(0)("TrackElement:%d, localTime: %f\n",this->currentTrackElem->ID, this->localTime); 352 return this->currentTrackElem->curve->calcPos((this->localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration); 347 353 } 348 354 … … 353 359 Vector TrackManager::calcDir() const 354 360 { 355 return this->currentTrackElem->curve->calcDir( this->localTime);361 return this->currentTrackElem->curve->calcDir((this->localTime-this->currentTrackElem->startingTime)/this->currentTrackElem->duration); 356 362 } 357 363 … … 364 370 void TrackManager::tick(float dt) 365 371 { 372 if (this->localTime <= this->firstTrackElem->duration) 373 this->jumpTo(this->localTime); 366 374 this->localTime += dt; 375 if (this->localTime > this->currentTrackElem->startingTime + this->currentTrackElem->duration && this->currentTrackElem->childCount > 0) 376 this->currentTrackElem = this->currentTrackElem->children[0]; 367 377 } 368 378 … … 376 386 void TrackManager::jumpTo(float time) 377 387 { 378 localTime = time; 388 if (time == 0) 389 this->currentTrackElem = this->firstTrackElem; 390 this->localTime = time; 379 391 } 380 392 -
orxonox/branches/parenting/src/world.cc
r3345 r3348 220 220 void World::load() 221 221 { 222 // BezierCurve* tmpCurve = new BezierCurve(); 222 223 if(this->debugWorldNr != -1) 223 224 { 224 225 trackManager = TrackManager::getInstance(); 226 trackManager->addPoint(Vector(0,-5,0)); 227 trackManager->addPoint(Vector(10,0,5)); 228 trackManager->addPoint(Vector(20,0,-5)); 229 trackManager->addPoint(Vector(30,0,5)); 230 trackManager->addPoint(Vector(40,0,5)); 231 trackManager->setDuration(.5); 232 trackManager->setSavePoint(); 233 trackManager->addPoint(Vector(50,10,10)); 234 trackManager->addPoint(Vector(60,0, 10)); 235 trackManager->addPoint(Vector(70,0, 10)); 236 trackManager->addPoint(Vector(80,0,-10)); 237 trackManager->addPoint(Vector(90,0,-10)); 238 trackManager->setDuration(.5); 239 240 /* 241 tmpCurve->addNode(Vector(10,0,-10)); 242 tmpCurve->addNode(Vector(10,2,5)); 243 tmpCurve->addNode(Vector(10,3,-5)); 244 tmpCurve->addNode(Vector(10,1,5)); 245 tmpCurve->addNode(Vector(10,0,5)); 246 */ 225 247 switch(this->debugWorldNr) 226 248 { … … 526 548 } 527 549 glEnd(); 528 550 float i; 551 glBegin(GL_LINES); 552 for(i = 0.0; i<1; i+=.01) 553 { 554 trackManager->tick (.01); 555 printf("%f, %f, %f\n",trackManager->calcPos().x, trackManager->calcPos().y, trackManager->calcPos().z); 556 glVertex3f(trackManager->calcPos().x, trackManager->calcPos().y, trackManager->calcPos().z); 557 } 558 /* 559 for(i = 0.0; i<1; i+=.01) 560 { 561 printf("%f, %f, %f\n",tmpCurve->calcPos(i).x, tmpCurve->calcPos(i).y, tmpCurve->calcPos(i).z); 562 glVertex3f(tmpCurve->calcPos(i).x, tmpCurve->calcPos(i).y, tmpCurve->calcPos(i).z); 563 } 564 */ 565 glEnd(); 529 566 glEndList(); 530 567 }
Note: See TracChangeset
for help on using the changeset viewer.