Changeset 3605 in orxonox.OLD for orxonox/branches/levelloader/src/lib/math/curve.cc
- Timestamp:
- Mar 18, 2005, 11:52:15 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/levelloader/src/lib/math/curve.cc
r3499 r3605 19 19 local-Time implementation 20 20 NURBS 21 tList implementation 21 22 22 23 */ 23 24 25 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_MATH 26 24 27 #include "curve.h" 25 #include "matrix.h" 28 26 29 #include "debug.h" 27 30 28 31 #include <math.h> 29 32 #include <stdio.h> 33 34 35 /** 36 \brief default constructor for a Curve 37 */ 38 Curve::Curve(void) 39 { 40 nodeCount = 0; 41 firstNode = new PathNode; 42 currentNode = firstNode; 43 44 firstNode->position = Vector (.0, .0, .0); 45 firstNode->number = 0; 46 firstNode->next = 0; // not sure if this really points to NULL!! 47 } 30 48 31 49 /** … … 131 149 this->derivation = 0; 132 150 dirCurve = new BezierCurve(1); 133 this->init();134 151 } 135 152 … … 141 158 this->derivation = derivation; 142 159 dirCurve=NULL; 143 this->init();144 160 } 145 161 … … 161 177 if (dirCurve) 162 178 delete dirCurve; 163 }164 165 /**166 \brief Initializes a BezierCurve167 */168 void BezierCurve::init(void)169 {170 nodeCount = 0;171 firstNode = new PathNode;172 currentNode = firstNode;173 174 firstNode->position = Vector (.0, .0, .0);175 firstNode->number = 0;176 firstNode->next = 0; // not sure if this really points to NULL!!177 178 return;179 179 } 180 180 … … 285 285 return curvePoint; 286 286 } 287 288 289 290 ///////////////////////////////////291 //// Uniform Point curve /////////292 ///////////////////////////////////293 /**294 \brief Creates a new UPointCurve295 */296 UPointCurve::UPointCurve (void)297 {298 this->derivation = 0;299 this->init();300 }301 302 /**303 \brief Creates a new UPointCurve-Derivation-Curve of deriavation'th degree304 */305 UPointCurve::UPointCurve (int derivation)306 {307 this->derivation = derivation;308 dirCurve=NULL;309 this->init();310 }311 312 /**313 \brief Deletes a UPointCurve.314 315 It does this by freeing all the space taken over from the nodes316 */317 UPointCurve::~UPointCurve(void)318 {319 PathNode* tmpNode;320 currentNode = firstNode;321 while (tmpNode != 0)322 {323 tmpNode = currentNode;324 currentNode = currentNode->next;325 delete tmpNode;326 }327 if (dirCurve)328 delete dirCurve;329 }330 331 /**332 \brief Initializes a UPointCurve333 */334 void UPointCurve::init(void)335 {336 nodeCount = 0;337 firstNode = new PathNode;338 currentNode = firstNode;339 340 firstNode->position = Vector (.0, .0, .0);341 firstNode->number = 0;342 firstNode->next = 0; // not sure if this really points to NULL!!343 344 return;345 }346 347 /**348 \brief Rebuilds a UPointCurve349 350 \todo very bad algorithm351 */352 void UPointCurve::rebuild(void)353 {354 // rebuilding the Curve itself355 PathNode* tmpNode = this->firstNode;356 int i=0;357 Matrix xTmpMat = Matrix(this->nodeCount, this->nodeCount);358 Matrix yTmpMat = Matrix(this->nodeCount, this->nodeCount);359 Matrix zTmpMat = Matrix(this->nodeCount, this->nodeCount);360 Matrix xValMat = Matrix(this->nodeCount, 3);361 Matrix yValMat = Matrix(this->nodeCount, 3);362 Matrix zValMat = Matrix(this->nodeCount, 3);363 while(tmpNode)364 {365 Vector fac = Vector(1,1,1);366 for (int j = 0; j < this->nodeCount; j++)367 {368 xTmpMat(i,j) = fac.x; fac.x *= (float)i/(float)this->nodeCount;//tmpNode->position.x;369 yTmpMat(i,j) = fac.y; fac.y *= (float)i/(float)this->nodeCount;//tmpNode->position.y;370 zTmpMat(i,j) = fac.z; fac.z *= (float)i/(float)this->nodeCount;//tmpNode->position.z;371 }372 xValMat(i,0) = tmpNode->position.x;373 yValMat(i,0) = tmpNode->position.y;374 zValMat(i,0) = tmpNode->position.z;375 ++i;376 tmpNode = tmpNode->next;377 }378 tmpNode = this->firstNode;379 xValMat = xTmpMat.Inv() *= xValMat;380 yValMat = yTmpMat.Inv() *= yValMat;381 zValMat = zTmpMat.Inv() *= zValMat;382 i = 0;383 while(tmpNode)384 {385 tmpNode->vFactor.x = xValMat(i,0);386 tmpNode->vFactor.y = yValMat(i,0);387 tmpNode->vFactor.z = zValMat(i,0);388 389 i++;390 tmpNode = tmpNode->next;391 }392 }393 394 /**395 \brief calculates the Position on the curve396 \param t The position on the Curve (0<=t<=1)397 \return the Position on the Path398 */399 Vector UPointCurve::calcPos(float t)400 {401 PathNode* tmpNode = firstNode;402 Vector ret = Vector(0.0,0.0,0.0);403 float factor = 1.0;404 while(tmpNode)405 {406 ret.x += tmpNode->vFactor.x * factor;407 ret.y += tmpNode->vFactor.y * factor;408 ret.z += tmpNode->vFactor.z * factor;409 factor *= t;410 411 tmpNode = tmpNode->next;412 }413 return ret;414 }415 416 /**417 \brief Calulates the direction of the Curve at time t.418 \param The time at which to evaluate the curve.419 \returns The vvaluated Vector.420 */421 Vector UPointCurve::calcDir (float t)422 {423 PathNode* tmpNode = firstNode;424 Vector ret = Vector(0.0,0.0,0.0);425 float factor = 1.0/t;426 int k=0;427 while(tmpNode)428 {429 ret.x += tmpNode->vFactor.x * factor *k;430 ret.y += tmpNode->vFactor.y * factor *k;431 ret.z += tmpNode->vFactor.z * factor *k;432 factor *= t;433 k++;434 tmpNode = tmpNode->next;435 }436 ret.normalize();437 return ret;438 }439 440 Vector UPointCurve::calcAcc (float t)441 {442 }443 444 /**445 \brief Calculates the Quaternion needed for our rotations446 \param t The time at which to evaluate the cuve.447 \returns The evaluated Quaternion.448 */449 Quaternion UPointCurve::calcQuat (float t)450 {451 return Quaternion (calcDir(t), Vector(0,0,1));452 }453 454 455 /**456 \brief returns the Position of the point calculated on the Curve457 \return a Vector to the calculated position458 */459 Vector UPointCurve::getPos(void) const460 {461 return curvePoint;462 }
Note: See TracChangeset
for help on using the changeset viewer.