Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4999 in orxonox.OLD for orxonox/trunk


Ignore:
Timestamp:
Aug 13, 2005, 7:35:16 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: the Quaternion multiplication-code is much faster now.
The previous approach was to brute force, and the new one is inlined :)

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

Legend:

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

    r4998 r4999  
    131131  v.y = cr * sp * cy + sr * cp * sy;
    132132  v.z = cr * cp * sy - sr * sp * cy;
    133 }
    134 
    135 /**
    136  *  rotates one Quaternion by another
    137  * @param q: another Quaternion to rotate this by
    138  * @return a quaternion that represents the first one rotated by the second one (WARUNING: this operation is not commutative! e.g. (A*B) != (B*A))
    139 */
    140 Quaternion Quaternion::operator*(const Quaternion& q) const
    141 {
    142   float A, B, C, D, E, F, G, H;
    143 
    144   A = (w   + v.x)*(q.w   + q.v.x);
    145   B = (v.z - v.y)*(q.v.y - q.v.z);
    146   C = (w   - v.x)*(q.v.y + q.v.z);
    147   D = (v.y + v.z)*(q.w   - q.v.x);
    148   E = (v.x + v.z)*(q.v.x + q.v.y);
    149   F = (v.x - v.z)*(q.v.x - q.v.y);
    150   G = (w   + v.y)*(q.w   - q.v.z);
    151   H = (w   - v.y)*(q.w   + q.v.z);
    152 
    153   Quaternion r;
    154   r.v.x = A - (E + F + G + H)/2;
    155   r.v.y = C + (E - F + G - H)/2;
    156   r.v.z = D + (E - F - G + H)/2;
    157   r.w = B +  (-E - F + G + H)/2;
    158 
    159   return r;
    160133}
    161134
  • orxonox/trunk/src/lib/math/vector.h

    r4998 r4999  
    132132  /** @param f: the value to multiply by @returns the quaternion multiplied by f (this *= f) */
    133133  inline const Quaternion& operator*= (const float& f) {*this = *this * f; return *this;}
    134   Quaternion operator* (const Quaternion& q) const;
     134  /** @param q: another Quaternion to rotate this by @return a quaternion that represents the first one rotated by the second one (WARUNING: this operation is not commutative! e.g. (A*B) != (B*A)) */
     135  Quaternion operator* (const Quaternion& q) const { return Quaternion(Vector(this->w*q.v.x + this->v.x*q.w + this->v.y*q.v.z - this->v.z*q.v.y,
     136                                                                         this->w*q.v.y + this->v.y*q.w + this->v.z*q.v.x - this->v.x*q.v.z,
     137                                                                         this->w*q.v.z + this->v.z*q.w + this->v.x*q.v.y - this->v.y*q.v.x),
     138                                                                         this->w*q.w - this->v.x*q.v.x - this->v.y*q.v.y - this->v.z*q.v.z);
     139  };
    135140  /** @param q: the Quaternion to multiply by @returns the quaternion multiplied by q (this *= q) */
    136141  inline const Quaternion& operator*= (const Quaternion& q) {*this = *this * q; return *this; };
Note: See TracChangeset for help on using the changeset viewer.