Changeset 3595 in orxonox.OLD for orxonox/trunk/src/lib/math/curve.cc
- Timestamp:
- Mar 17, 2005, 5:44:56 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/math/curve.cc
r3593 r3595 26 26 27 27 #include "curve.h" 28 #include "matrix.h" 28 29 29 #include "debug.h" 30 30 … … 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 }300 301 /**302 \brief Creates a new UPointCurve-Derivation-Curve of deriavation'th degree303 */304 UPointCurve::UPointCurve (int derivation)305 {306 this->derivation = derivation;307 dirCurve=NULL;308 }309 310 /**311 \brief Deletes a UPointCurve.312 313 It does this by freeing all the space taken over from the nodes314 */315 UPointCurve::~UPointCurve(void)316 {317 PathNode* tmpNode;318 currentNode = firstNode;319 while (tmpNode != 0)320 {321 tmpNode = currentNode;322 currentNode = currentNode->next;323 delete tmpNode;324 }325 if (dirCurve)326 delete dirCurve;327 }328 329 /**330 \brief Rebuilds a UPointCurve331 332 \todo very bad algorithm333 */334 void UPointCurve::rebuild(void)335 {336 // rebuilding the Curve itself337 PathNode* tmpNode = this->firstNode;338 int i=0;339 Matrix xTmpMat = Matrix(this->nodeCount, this->nodeCount);340 Matrix yTmpMat = Matrix(this->nodeCount, this->nodeCount);341 Matrix zTmpMat = Matrix(this->nodeCount, this->nodeCount);342 Matrix xValMat = Matrix(this->nodeCount, 3);343 Matrix yValMat = Matrix(this->nodeCount, 3);344 Matrix zValMat = Matrix(this->nodeCount, 3);345 while(tmpNode)346 {347 Vector fac = Vector(1,1,1);348 for (int j = 0; j < this->nodeCount; j++)349 {350 xTmpMat(i,j) = fac.x; fac.x *= (float)i/(float)this->nodeCount;//tmpNode->position.x;351 yTmpMat(i,j) = fac.y; fac.y *= (float)i/(float)this->nodeCount;//tmpNode->position.y;352 zTmpMat(i,j) = fac.z; fac.z *= (float)i/(float)this->nodeCount;//tmpNode->position.z;353 }354 xValMat(i,0) = tmpNode->position.x;355 yValMat(i,0) = tmpNode->position.y;356 zValMat(i,0) = tmpNode->position.z;357 ++i;358 tmpNode = tmpNode->next;359 }360 tmpNode = this->firstNode;361 xValMat = xTmpMat.Inv() *= xValMat;362 yValMat = yTmpMat.Inv() *= yValMat;363 zValMat = zTmpMat.Inv() *= zValMat;364 i = 0;365 while(tmpNode)366 {367 tmpNode->vFactor.x = xValMat(i,0);368 tmpNode->vFactor.y = yValMat(i,0);369 tmpNode->vFactor.z = zValMat(i,0);370 371 i++;372 tmpNode = tmpNode->next;373 }374 }375 376 /**377 \brief calculates the Position on the curve378 \param t The position on the Curve (0<=t<=1)379 \return the Position on the Path380 */381 Vector UPointCurve::calcPos(float t)382 {383 PathNode* tmpNode = firstNode;384 Vector ret = Vector(0.0,0.0,0.0);385 float factor = 1.0;386 while(tmpNode)387 {388 ret.x += tmpNode->vFactor.x * factor;389 ret.y += tmpNode->vFactor.y * factor;390 ret.z += tmpNode->vFactor.z * factor;391 factor *= t;392 393 tmpNode = tmpNode->next;394 }395 return ret;396 }397 398 /**399 \brief Calulates the direction of the Curve at time t.400 \param The time at which to evaluate the curve.401 \returns The vvaluated Vector.402 */403 Vector UPointCurve::calcDir (float t)404 {405 PathNode* tmpNode = firstNode;406 Vector ret = Vector(0.0,0.0,0.0);407 float factor = 1.0/t;408 int k=0;409 while(tmpNode)410 {411 ret.x += tmpNode->vFactor.x * factor *k;412 ret.y += tmpNode->vFactor.y * factor *k;413 ret.z += tmpNode->vFactor.z * factor *k;414 factor *= t;415 k++;416 tmpNode = tmpNode->next;417 }418 ret.normalize();419 return ret;420 }421 422 Vector UPointCurve::calcAcc (float t)423 {424 }425 426 /**427 \brief Calculates the Quaternion needed for our rotations428 \param t The time at which to evaluate the cuve.429 \returns The evaluated Quaternion.430 */431 Quaternion UPointCurve::calcQuat (float t)432 {433 return Quaternion (calcDir(t), Vector(0,0,1));434 }435 436 437 /**438 \brief returns the Position of the point calculated on the Curve439 \return a Vector to the calculated position440 */441 Vector UPointCurve::getPos(void) const442 {443 return curvePoint;444 }
Note: See TracChangeset
for help on using the changeset viewer.