- Timestamp:
- Apr 13, 2005, 11:39:33 PM (20 years ago)
- Location:
- orxonox/trunk/src/lib/math
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/math/vector.cc
r3607 r3814 23 23 #include "vector.h" 24 24 #include "debug.h" 25 #include "stdincl.h" 25 26 26 27 using namespace std; … … 31 32 \return the sum of both vectors 32 33 */ 34 /* 33 35 Vector Vector::operator+ (const Vector& v) const 34 36 { 35 Vector r; 36 37 r.x = x + v.x; 38 r.y = y + v.y; 39 r.z = z + v.z; 40 41 return r; 42 } 37 return Vector(x + v.x, y + v.y, z + v.z); 38 } 39 */ 43 40 44 41 /** … … 49 46 Vector Vector::operator- (const Vector& v) const 50 47 { 51 Vector r; 52 53 r.x = x - v.x; 54 r.y = y - v.y; 55 r.z = z - v.z; 56 57 return r; 48 return Vector(x - v.x, y - v.y, z - v.z); 58 49 } 59 50 … … 75 66 Vector Vector::operator* (float f) const 76 67 { 77 Vector r; 78 79 r.x = x * f; 80 r.y = y * f; 81 r.z = z * f; 82 83 return r; 68 return Vector(x * f, y * f, z * f); 84 69 } 85 70 … … 91 76 Vector Vector::operator/ (float f) const 92 77 { 93 Vector r; 94 95 if( f == 0.0) 78 __UNLIKELY_IF( f == 0.0) 96 79 { 97 80 // Prevent divide by zero 98 81 return Vector (0,0,0); 99 82 } 100 101 r.x = x / f; 102 r.y = y / f; 103 r.z = z / f; 104 105 return r; 83 return Vector(x / f, y / f, z / f); 106 84 } 107 85 … … 123 101 Vector Vector::cross (const Vector& v) const 124 102 { 125 Vector r; 126 127 r.x = y * v.z - z * v.y; 128 r.y = z * v.x - x * v.z; 129 r.z = x * v.y - y * v.x; 130 131 return r; 103 return Vector(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x ); 132 104 } 133 105 … … 139 111 float l = len(); 140 112 141 if( l == 0.0)113 __UNLIKELY_IF( l == 0.0) 142 114 { 143 115 // Prevent divide by zero … … 158 130 { 159 131 float l = len(); 160 if(l != 1.0)132 __UNLIKELY_IF(l != 1.0) 161 133 { 162 134 return this; 163 135 } 164 else if(l == 0.0)136 else __UNLIKELY_IF(l == 0.0) 165 137 { 166 138 return 0; 167 139 } 168 169 Vector *normalizedVector = new Vector(x / l, y /l, z / l); 170 return normalizedVector; 140 141 return new Vector(x / l, y /l, z / l); 171 142 } 172 143 … … 365 336 Quaternion Quaternion::operator+(const Quaternion& q) const 366 337 { 367 368 369 370 371 } 372 373 /** 374 375 376 338 Quaternion r(*this); 339 r.w = r.w + q.w; 340 r.v = r.v + q.v; 341 return r; 342 } 343 344 /** 345 \brief subtract two Quaternions 346 \param q: another Quaternion 347 \return the difference of both Quaternions 377 348 */ 378 349 Quaternion Quaternion::operator- (const Quaternion& q) const 379 350 { 380 381 382 383 384 } 385 386 /** 387 388 389 351 Quaternion r(*this); 352 r.w = r.w - q.w; 353 r.v = r.v - q.v; 354 return r; 355 } 356 357 /** 358 \brief rotate a Vector by a Quaternion 359 \param v: the Vector 360 \return a new Vector representing v rotated by the Quaternion 390 361 */ 391 362 Vector Quaternion::apply (Vector& v) const 392 363 { 393 394 395 396 397 398 } 399 400 /** 401 402 403 364 Quaternion q; 365 q.v = v; 366 q.w = 0; 367 q = *this * q * conjugate(); 368 return q.v; 369 } 370 371 /** 372 \brief multiply a Quaternion with a real value 373 \param f: a real value 374 \return a new Quaternion containing the product 404 375 */ 405 376 Quaternion Quaternion::operator*(const float& f) const 406 377 { 407 408 409 410 411 } 412 413 /** 414 415 416 378 Quaternion r(*this); 379 r.w = r.w*f; 380 r.v = r.v*f; 381 return r; 382 } 383 384 /** 385 \brief divide a Quaternion by a real value 386 \param f: a real value 387 \return a new Quaternion containing the quotient 417 388 */ 418 389 Quaternion Quaternion::operator/(const float& f) const 419 390 { 420 421 422 423 424 425 } 426 427 /** 428 429 391 if( f == 0) return Quaternion(); 392 Quaternion r(*this); 393 r.w = r.w/f; 394 r.v = r.v/f; 395 return r; 396 } 397 398 /** 399 \brief calculate the conjugate value of the Quaternion 400 \return the conjugate Quaternion 430 401 */ 431 402 Quaternion Quaternion::conjugate() const 432 403 { 433 434 435 436 } 437 438 /** 439 440 404 Quaternion r(*this); 405 r.v = Vector() - r.v; 406 return r; 407 } 408 409 /** 410 \brief calculate the norm of the Quaternion 411 \return the norm of The Quaternion 441 412 */ 442 413 float Quaternion::norm() const 443 414 { 444 445 } 446 447 /** 448 449 450 415 return w*w + v.x*v.x + v.y*v.y + v.z*v.z; 416 } 417 418 /** 419 \brief calculate the inverse value of the Quaternion 420 \return the inverse Quaternion 421 451 422 Note that this is equal to conjugate() if the Quaternion's norm is 1 452 423 */ 453 424 Quaternion Quaternion::inverse() const 454 425 { 455 456 457 458 459 460 461 } 462 463 /** 464 465 426 float n = norm(); 427 if (n != 0) 428 { 429 return conjugate() / norm(); 430 } 431 else return Quaternion(); 432 } 433 434 /** 435 \brief convert the Quaternion to a 4x4 rotational glMatrix 436 \param m: a buffer to store the Matrix in 466 437 */ 467 438 void Quaternion::matrix (float m[4][4]) const -
orxonox/trunk/src/lib/math/vector.h
r3541 r3814 29 29 ~Vector () {} 30 30 31 Vector operator+ (const Vector& v) const;31 inline Vector operator+ (const Vector& v) const { return Vector(x + v.x, y + v.y, z + v.z); } 32 32 Vector operator- (const Vector& v) const; 33 33 float operator* (const Vector& v) const;
Note: See TracChangeset
for help on using the changeset viewer.