Changeset 3966 in orxonox.OLD for orxonox/trunk/src/lib/math
- Timestamp:
- Apr 26, 2005, 12:23:38 AM (20 years ago)
- Location:
- orxonox/trunk/src/lib/math
- Files:
-
- 2 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/math/vector.cc
r3860 r3966 100 100 */ 101 101 102 Vector *Vector::getNormalized()102 Vector Vector::getNormalized() 103 103 { 104 104 float l = len(); 105 105 if(unlikely(l != 1.0)) 106 106 { 107 return this;107 return *this; 108 108 } 109 109 else if(unlikely(l == 0.0)) 110 110 { 111 return 0;111 return *this; 112 112 } 113 113 114 return new Vector(x / l, y /l, z / l);114 return *this / l; 115 115 } 116 116 … … 172 172 \brief Outputs the values of the Vector 173 173 */ 174 void Vector::debug(void) 174 void Vector::debug(void) const 175 175 { 176 176 PRINT(0)("Vector Debug information\n"); … … 438 438 \param to to where 439 439 \param t the time this transformation should take 440 \param res The approximation-density 441 */ 442 void Quaternion::quatSlerp(const Quaternion* from, const Quaternion* to, float t, Quaternion* res) 440 441 \returns the Result of the smooth move 442 */ 443 Quaternion Quaternion::quatSlerp(const Quaternion& from, const Quaternion& to, float t) 443 444 { 444 445 float tol[4]; … … 446 447 DELTA = 0.2; 447 448 448 cosom = from ->v.x * to->v.x + from->v.y * to->v.y + from->v.z * to->v.z + from->w * to->w;449 cosom = from.v.x * to.v.x + from.v.y * to.v.y + from.v.z * to.v.z + from.w * to.w; 449 450 450 451 if( cosom < 0.0 ) 451 452 { 452 453 cosom = -cosom; 453 tol[0] = -to ->v.x;454 tol[1] = -to ->v.y;455 tol[2] = -to ->v.z;456 tol[3] = -to ->w;454 tol[0] = -to.v.x; 455 tol[1] = -to.v.y; 456 tol[2] = -to.v.z; 457 tol[3] = -to.w; 457 458 } 458 459 else 459 460 { 460 tol[0] = to ->v.x;461 tol[1] = to ->v.y;462 tol[2] = to ->v.z;463 tol[3] = to ->w;461 tol[0] = to.v.x; 462 tol[1] = to.v.y; 463 tol[2] = to.v.z; 464 tol[3] = to.w; 464 465 } 465 466 466 467 //if( (1.0 - cosom) > DELTA ) 467 468 //{ 468 469 470 471 472 473 474 else469 omega = acos(cosom); 470 sinom = sin(omega); 471 scale0 = sin((1.0 - t) * omega) / sinom; 472 scale1 = sin(t * omega) / sinom; 473 //} 474 /* 475 else 475 476 { 476 477 477 scale0 = 1.0 - t; 478 scale1 = t; 478 479 } 479 */ 480 res->v.x = scale0 * from->v.x + scale1 * tol[0]; 481 res->v.y = scale0 * from->v.y + scale1 * tol[1]; 482 res->v.z = scale0 * from->v.z + scale1 * tol[2]; 483 res->w = scale0 * from->w + scale1 * tol[3]; 480 */ 481 482 483 /* 484 Quaternion res; 485 res.v.x = scale0 * from.v.x + scale1 * tol[0]; 486 res.v.y = scale0 * from.v.y + scale1 * tol[1]; 487 res.v.z = scale0 * from.v.z + scale1 * tol[2]; 488 res.w = scale0 * from.w + scale1 * tol[3]; 489 */ 490 return Quaternion(scale0 * from.w + scale1 * tol[3], 491 Vector(scale0 * from.v.x + scale1 * tol[0], 492 scale0 * from.v.y + scale1 * tol[1], 493 scale0 * from.v.z + scale1 * tol[2])); 484 494 } 485 495 -
orxonox/trunk/src/lib/math/vector.h
r3860 r3966 31 31 32 32 inline Vector operator+ (const Vector& v) const { return Vector(x + v.x, y + v.y, z + v.z); } 33 inline const Vector& operator+= (const Vector& v) {this->x += v.x; this->y += v.y; this->z += v.z; return *this;} 33 34 inline Vector operator- (const Vector& v) const { return Vector(x - v.x, y - v.y, z - v.z); } 35 inline const Vector& operator-= (const Vector& v) {this->x -= v.x; this->y -= v.y; this->z -= v.z; return *this;} 34 36 inline float operator* (const Vector& v) const { return x * v.x + y * v.y + z * v.z; } 37 inline const Vector& operator*= (const Vector& v) {this->x *= v.x; this->y *= v.y; this->z *= v.z; return *this;} 35 38 inline Vector operator* (float f) const { return Vector(x * f, y * f, z * f); } 39 inline const Vector& operator*= (float f) {this->x *= f; this->y *= f; this->z *= f; return *this;} 36 40 Vector operator/ (float f) const; 41 inline const Vector& operator/= (float f) {this->x /= f; this->y /= f; this->z /= f; return *this;} 42 inline const Vector& operator= (const Vector& v) {this->x = v.x; this->y = v.y; this->z = v.z; return *this;} 37 43 float dot (const Vector& v) const; 38 inline Vector cross (const Vector& v) const { 44 inline Vector cross (const Vector& v) const { return Vector(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x ); } 39 45 void scale(const Vector& v); 40 46 inline float len() const { return sqrt (x*x+y*y+z*z); } … … 50 56 z = z / l; 51 57 } 52 Vector *getNormalized();58 Vector getNormalized(); 53 59 Vector abs(); 54 60 55 void debug() ;61 void debug() const; 56 62 }; 57 63 … … 76 82 Quaternion (float roll, float pitch, float yaw); 77 83 Quaternion operator/ (const float& f) const; 84 inline const Quaternion operator/= (const float& f) {*this = *this / f; return *this;} 78 85 Quaternion operator* (const float& f) const; 86 inline const Quaternion operator*= (const float& f) {*this = *this * f; return *this;} 79 87 Quaternion operator* (const Quaternion& q) const; 88 inline const Quaternion operator*= (const Quaternion& q) {*this = *this * q; return *this;} 80 89 inline Quaternion operator+ (const Quaternion& q) const { return Quaternion(q.v + v, q.w + w); } 90 inline const Quaternion& operator+= (const Quaternion& q) {this->v += q.v; this->w += q.w; return *this;} 81 91 inline Quaternion operator- (const Quaternion& q) const { return Quaternion(q.v - v, q.w - w); } 92 inline const Quaternion& operator-= (const Quaternion& q) {this->v -= q.v; this->w -= q.w; return *this;} 93 inline Quaternion operator= (const Quaternion& q) {this->v = q.v; this->w = q.w; return *this;} 82 94 Quaternion conjugate () const { Quaternion r(*this); 83 95 r.v = Vector() - r.v; … … 87 99 float norm () const; 88 100 void matrix (float m[4][4]) const; 89 void quatSlerp(const Quaternion* from, const Quaternion* to, const float t, Quaternion* res);101 Quaternion quatSlerp(const Quaternion& from, const Quaternion& to, float t); 90 102 91 103 void debug();
Note: See TracChangeset
for help on using the changeset viewer.