Changeset 3822 in orxonox.OLD for orxonox/trunk
- Timestamp:
- Apr 14, 2005, 1:05:07 AM (20 years ago)
- Location:
- orxonox/trunk/src/lib/math
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/math/vector.cc
r3819 r3822 185 185 \brief creates a multiplicational identity Quaternion 186 186 */ 187 Quaternion::Quaternion () 188 { 189 w = 1; 190 v = Vector(0,0,0); 191 } 187 //Quaternion::Quaternion () 188 192 189 193 190 /** … … 196 193 \param axis: the axis to rotate around 197 194 */ 198 Quaternion::Quaternion (float angle, const Vector& axis) 199 { 200 w = cos(angle/2); 201 v = axis * sin(angle/2); 202 } 195 //Quaternion::Quaternion (float angle, const Vector& axis) 196 203 197 204 198 /** … … 281 275 Quaternion Quaternion::operator*(const Quaternion& q) const 282 276 { 283 float A, B, C, D, E, F, G, H; 284 Quaternion r; 285 286 A = (w + v.x)*(q.w + q.v.x); 287 B = (v.z - v.y)*(q.v.y - q.v.z); 288 C = (w - v.x)*(q.v.y + q.v.z); 289 D = (v.y + v.z)*(q.w - q.v.x); 290 E = (v.x + v.z)*(q.v.x + q.v.y); 291 F = (v.x - v.z)*(q.v.x - q.v.y); 292 G = (w + v.y)*(q.w - q.v.z); 293 H = (w - v.y)*(q.w + q.v.z); 294 295 r.w = B + (-E - F + G + H)/2; 296 r.v.x = A - (E + F + G + H)/2; 297 r.v.y = C + (E - F + G - H)/2; 298 r.v.z = D + (E - F - G + H)/2; 299 300 return r; 301 } 302 303 /** 304 \brief add two Quaternions 305 \param q: another Quaternion 306 \return the sum of both Quaternions 307 */ 277 float A, B, C, D, E, F, G, H; 278 279 A = (w + v.x)*(q.w + q.v.x); 280 B = (v.z - v.y)*(q.v.y - q.v.z); 281 C = (w - v.x)*(q.v.y + q.v.z); 282 D = (v.y + v.z)*(q.w - q.v.x); 283 E = (v.x + v.z)*(q.v.x + q.v.y); 284 F = (v.x - v.z)*(q.v.x - q.v.y); 285 G = (w + v.y)*(q.w - q.v.z); 286 H = (w - v.y)*(q.w + q.v.z); 287 288 return Quaternion(Vector(A - (E + F + G + H)/2, C + (E - F + G - H)/2, D + (E - F - G + H)/2), B + (-E - F + G + H)/2); 289 } 290 291 /** 292 \brief add two Quaternions 293 \param q: another Quaternion 294 \return the sum of both Quaternions 295 */ 296 /* 308 297 Quaternion Quaternion::operator+(const Quaternion& q) const 309 298 { … … 313 302 return r; 314 303 } 304 */ 315 305 316 306 /** … … 319 309 \return the difference of both Quaternions 320 310 */ 311 /* 321 312 Quaternion Quaternion::operator- (const Quaternion& q) const 322 313 { … … 326 317 return r; 327 318 } 319 */ 328 320 329 321 /** … … 332 324 \return a new Vector representing v rotated by the Quaternion 333 325 */ 326 334 327 Vector Quaternion::apply (Vector& v) const 335 328 { … … 339 332 q = *this * q * conjugate(); 340 333 return q.v; 341 }334 } 342 335 343 336 /** -
orxonox/trunk/src/lib/math/vector.h
r3819 r3822 69 69 float w; //!< Real part of the number 70 70 71 Quaternion (); 71 inline Quaternion () { w = 1; v = Vector(0,0,0); } 72 inline Quaternion (const Vector& b, float a) { w = a; v = b; } 72 73 Quaternion (float m[4][4]); 73 Quaternion (float angle, const Vector& axis);74 inline Quaternion (float angle, const Vector& axis) { w = cos(angle/2); v = axis * sin(angle/2); } 74 75 Quaternion (const Vector& dir, const Vector& up); 75 76 Quaternion (float roll, float pitch, float yaw); 76 77 77 Quaternion operator/ (const float& f) const; 78 78 Quaternion operator* (const float& f) const; 79 79 Quaternion operator* (const Quaternion& q) const; 80 Quaternion operator+ (const Quaternion& q) const;81 Quaternion operator- (const Quaternion& q) const;80 inline Quaternion operator+ (const Quaternion& q) const { return Quaternion(q.v + v, q.w + w); } 81 inline Quaternion operator- (const Quaternion& q) const { return Quaternion(q.v - v, q.w - w); } 82 82 Quaternion conjugate () const; 83 83 Quaternion inverse () const; 84 Vector apply (Vector& f) const ;84 Vector apply (Vector& f) const ;//{ Quaternion q; q.v = v; q.w = 0; q = *this * q * conjugate(); return q.v; } 85 85 float norm () const; 86 86 void matrix (float m[4][4]) const;
Note: See TracChangeset
for help on using the changeset viewer.