Changeset 3605 in orxonox.OLD for orxonox/branches/levelloader/src/lib/math
- Timestamp:
- Mar 18, 2005, 11:52:15 AM (20 years ago)
- Location:
- orxonox/branches/levelloader/src/lib/math
- Files:
-
- 2 deleted
- 4 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 } -
orxonox/branches/levelloader/src/lib/math/curve.h
r3499 r3605 13 13 14 14 //! An Enumerator that defines what sort of Curves are availible 15 enum CurveType {BEZIERCURVE , UPOINTCURVE};15 enum CurveType {BEZIERCURVE}; 16 16 17 17 … … 38 38 PathNode* currentNode; //!< The node we are working with (the Last node). 39 39 40 40 41 private: 41 42 virtual void rebuild(void) = 0; 42 43 public: 44 Curve(void); 45 43 46 Curve* dirCurve; //!< The derivation-curve of this Curve. 44 47 void addNode(const Vector& newNode); … … 68 71 BezierCurve(void); 69 72 BezierCurve(int derivation); 70 ~BezierCurve(void); 71 void init(void); 73 virtual ~BezierCurve(void); 72 74 73 75 Vector calcPos(float t); … … 91 93 }; 92 94 93 //! Uniform Point Curve-class94 /**95 A UPoint Curve is a A Curve, that flows through all the nodes given it.96 The Algorithm to buid the curve is rather slow, but Painting and tracing along the curve has high speed, so do not change this curve during the Game.97 98 This Curve is very erattic, so i do not recommend to use it.99 */100 class UPointCurve : public Curve101 {102 private:103 void rebuild(void);104 public:105 UPointCurve(void);106 UPointCurve(int derivation);107 ~UPointCurve(void);108 void init(void);109 110 Vector calcPos(float t);111 Vector calcDir(float t);112 Vector calcAcc(float t);113 Quaternion calcQuat(float t);114 115 Vector getPos(void) const;116 };117 118 95 #endif /* _CURVE_H */ -
orxonox/branches/levelloader/src/lib/math/vector.cc
r3499 r3605 19 19 */ 20 20 21 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_MATH 21 22 22 23 #include "vector.h" 23 24 #include "debug.h" 24 25 25 26 using namespace std; … … 201 202 } 202 203 203 204 204 /** 205 205 \brief calculate the angle between two vectors in radiances … … 225 225 f = acos( v1 * v2 / (v1.len() * v2.len())); 226 226 return f * 180 / PI; 227 } 228 229 230 /** 231 \brief Outputs the values of the Vector 232 */ 233 void Vector::debug(void) 234 { 235 PRINT(0)("Vector Debug information\n"); 236 PRINT(0)("x: %f; y: %f; z: %f", x, y, z); 237 PRINT(3)(" lenght: %f", len()); 238 PRINT(0)("\n"); 227 239 } 228 240 … … 581 593 582 594 /** 595 \brief outputs some nice formated debug information about this quaternion 596 */ 597 void Quaternion::debug(void) 598 { 599 PRINT(0)("Quaternion Debug Information\n"); 600 PRINT(0)("real a=%f; imag: x=%f y=%f z=%f\n", w, v.x, v.y, v.z); 601 } 602 603 /** 583 604 \brief create a rotation from a vector 584 605 \param v: a vector -
orxonox/branches/levelloader/src/lib/math/vector.h
r3499 r3605 41 41 Vector* getNormalized(); 42 42 Vector abs(); 43 44 void debug(); 43 45 }; 44 46 … … 53 55 { 54 56 public: 55 Vector v; //!< Imaginary Vector 56 float w; //!< Real part of the number 57 58 Quaternion (); 59 Quaternion (float m[4][4]); 60 Quaternion (float angle, const Vector& axis); 61 Quaternion (const Vector& dir, const Vector& up); 62 Quaternion (float roll, float pitch, float yaw); 63 64 Quaternion operator/ (const float& f) const; 65 Quaternion operator* (const float& f) const; 66 Quaternion operator* (const Quaternion& q) const; 67 Quaternion operator+ (const Quaternion& q) const; 68 Quaternion operator- (const Quaternion& q) const; 69 Quaternion conjugate () const; 70 Quaternion inverse () const; 71 Vector apply (Vector& f) const; 72 float norm () const; 73 void matrix (float m[4][4]) const; 74 void quatSlerp(const Quaternion* from, const Quaternion* to, const float t, Quaternion* res); 75 57 Vector v; //!< Imaginary Vector 58 float w; //!< Real part of the number 59 60 Quaternion (); 61 Quaternion (float m[4][4]); 62 Quaternion (float angle, const Vector& axis); 63 Quaternion (const Vector& dir, const Vector& up); 64 Quaternion (float roll, float pitch, float yaw); 65 66 Quaternion operator/ (const float& f) const; 67 Quaternion operator* (const float& f) const; 68 Quaternion operator* (const Quaternion& q) const; 69 Quaternion operator+ (const Quaternion& q) const; 70 Quaternion operator- (const Quaternion& q) const; 71 Quaternion conjugate () const; 72 Quaternion inverse () const; 73 Vector apply (Vector& f) const; 74 float norm () const; 75 void matrix (float m[4][4]) const; 76 void quatSlerp(const Quaternion* from, const Quaternion* to, const float t, Quaternion* res); 77 78 void debug(); 76 79 private: 77 80 float DELTA; //!< resolution of calculation 78 81 79 82 };
Note: See TracChangeset
for help on using the changeset viewer.