Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3822 in orxonox.OLD for orxonox/trunk/src


Ignore:
Timestamp:
Apr 14, 2005, 1:05:07 AM (20 years ago)
Author:
patrick
Message:

orxonox/trunk: quaternion functions inlined

Location:
orxonox/trunk/src/lib/math
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/math/vector.cc

    r3819 r3822  
    185185        \brief creates a multiplicational identity Quaternion
    186186*/
    187 Quaternion::Quaternion ()
    188 {
    189         w = 1;
    190         v = Vector(0,0,0);
    191 }
     187//Quaternion::Quaternion ()
     188
    192189
    193190/**
     
    196193        \param axis: the axis to rotate around
    197194*/
    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
    203197
    204198/**
     
    281275Quaternion Quaternion::operator*(const Quaternion& q) const
    282276{
    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/*
    308297Quaternion Quaternion::operator+(const Quaternion& q) const
    309298{
     
    313302  return r;
    314303}
     304*/
    315305
    316306/**
     
    319309   \return the difference of both Quaternions
    320310*/
     311/*
    321312Quaternion Quaternion::operator- (const Quaternion& q) const
    322313{
     
    326317  return r;
    327318}
     319*/
    328320
    329321/**
     
    332324   \return a new Vector representing v rotated by the Quaternion
    333325*/
     326
    334327Vector Quaternion::apply (Vector& v) const
    335328{
     
    339332  q = *this * q * conjugate();
    340333  return q.v;
    341 }
     334  }
    342335
    343336/**
  • orxonox/trunk/src/lib/math/vector.h

    r3819 r3822  
    6969  float w;        //!< Real part of the number
    7070 
    71   Quaternion ();
     71  inline Quaternion () { w = 1; v = Vector(0,0,0); }
     72  inline Quaternion (const Vector& b, float a) { w = a; v = b; }
    7273  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); }
    7475  Quaternion (const Vector& dir, const Vector& up);
    7576  Quaternion (float roll, float pitch, float yaw);
    76  
    7777  Quaternion operator/ (const float& f) const;
    7878  Quaternion operator* (const float& f) const;
    7979  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); }
    8282  Quaternion conjugate () const;
    8383  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; }
    8585  float norm () const;
    8686  void matrix (float m[4][4]) const;
Note: See TracChangeset for help on using the changeset viewer.