Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4997 in orxonox.OLD for orxonox/trunk/src/lib/math/vector.h


Ignore:
Timestamp:
Aug 13, 2005, 3:10:52 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: optimized vector class

File:
1 edited

Legend:

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

    r4994 r4997  
    5454  inline const Vector& operator*= (float f) { this->x *= f; this->y *= f; this->z *= f; return *this; };
    5555  /** @param f a factor to divide the vector with @returns the vector divided by f (this / f) */
    56   inline Vector operator/ (float f) const {return (unlikely(f == 0.0))?Vector(0,0,0):Vector(this->x / f, this->y / f, this->z / f); };
     56  inline Vector operator/ (float f) const { return (unlikely(f == 0.0))?Vector(0,0,0):Vector(this->x / f, this->y / f, this->z / f); };
    5757  /** @param f a factor to divide the vector with @returns the vector divided by f (this /= f) */
    5858  inline const Vector& operator/= (float f) {if (unlikely(f == 0.0)) {this->x=0;this->y=0;this->z=0;} else {this->x /= f; this->y /= f; this->z /= f;} return *this; };
     
    124124  Quaternion (const Vector& dir, const Vector& up);
    125125  Quaternion (float roll, float pitch, float yaw);
    126   Quaternion operator/ (const float& f) const;
     126  /** @param f: a real value @return a Quaternion containing the quotient */
     127  inline Quaternion operator/ (const float& f) const { return (unlikely(f==0.0)) ? Quaternion() : Quaternion(this->v/f, this->w/f); };
    127128  /** @param f: the value to divide by @returns the quaternion devided by f (this /= f) */
    128129  inline const Quaternion& operator/= (const float& f) {*this = *this / f; return *this;}
    129   Quaternion operator* (const float& f) const;
     130  /** @param f: a real value @return a Quaternion containing the product */
     131  inline Quaternion operator* (const float& f) const { return Quaternion(this->v*f, this->w*f); };
    130132  /** @param f: the value to multiply by @returns the quaternion multiplied by f (this *= f) */
    131133  inline const Quaternion& operator*= (const float& f) {*this = *this * f; return *this;}
    132134  Quaternion operator* (const Quaternion& q) const;
    133135  /** @param q: the Quaternion to multiply by @returns the quaternion multiplied by q (this *= q) */
    134   inline const Quaternion operator*= (const Quaternion& q) {*this = *this * q; return *this; };
     136  inline const Quaternion& operator*= (const Quaternion& q) {*this = *this * q; return *this; };
     137  /** @param q the Quaternion by which to devide @returns the division from this by q (this / q) */
     138  inline Quaternion operator/ (const Quaternion& q) const { return *this * q.inverse(); };
     139  /** @param q the Quaternion by which to devide @returns the division from this by q (this /= q) */
     140  inline const Quaternion& operator/= (const Quaternion& q) { *this = *this * q.inverse(); return *this; };
    135141  /** @param q the Quaternion to add to this @returns the quaternion added with q (this + q) */
    136142  inline Quaternion operator+ (const Quaternion& q) const { return Quaternion(q.v + v, q.w + w); };
     
    144150  inline Quaternion operator= (const Quaternion& q) {this->v = q.v; this->w = q.w; return *this;}
    145151  /** conjugates this Quaternion @returns the conjugate */
    146   inline Quaternion conjugate () const {  Quaternion r(*this);  r.v = Vector() - r.v;  return r;}
    147   Quaternion inverse () const;
    148   Vector apply (const Vector& f) const;
    149   float norm () const;
     152  inline Quaternion conjugate () const { Quaternion r(*this); r.v = Vector() - r.v; return r; };
     153  /** @returns the norm of The Quaternion */
     154  inline float norm () const { return w*w + v.x*v.x + v.y*v.y + v.z*v.z; };
     155  /** @returns the inverted Quaterntion of this */
     156  inline Quaternion inverse () const { return conjugate() / norm(); };
     157  /** @param v: the Vector  @return a new Vector representing v rotated by the Quaternion */
     158  inline Vector apply (const Vector& v) const { return (*this * Quaternion(v, 0) * conjugate()).v; };
    150159  void matrix (float m[4][4]) const;
    151160
     
    270279
    271280#endif /* _VECTOR_H */
     281
Note: See TracChangeset for help on using the changeset viewer.