Ignore:
Timestamp:
Apr 29, 2012, 4:01:00 PM (9 years ago)
Author:
sam
Message:

math: chage quaternion constructor to wxyz order because it matches the
mathematical writing, and add static constructors to create quaternions
from a rotation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lol/math/vector.h

    r1272 r1305  
    910910{
    911911    inline Quat() {}
    912     inline Quat(T X) : x(0), y(0), z(0), w(X) {}
    913     inline Quat(T X, T Y, T Z, T W) : x(X), y(Y), z(Z), w(W) {}
     912    inline Quat(T W) : x(0), y(0), z(0), w(W) {}
     913    inline Quat(T W, T X, T Y, T Z) : x(X), y(Y), z(Z), w(W) {}
    914914
    915915    Quat(Mat3<T> const &m);
     
    917917
    918918    DECLARE_MEMBER_OPS(Quat)
     919
     920    static Quat<T> rotate(T angle, T x, T y, T z);
     921    static Quat<T> rotate(T angle, Vec3<T> const &v);
    919922
    920923    inline Quat<T> operator *(Quat<T> const &val) const
     
    924927        Vec3<T> v2(val.x, val.y, val.z);
    925928        Vec3<T> v3 = cross(v1, v2) + w * v2 + val.w * v1;
    926         return Quat<T>(v3.x, v3.y, v3.z, w * val.w - dot(v1, v2));
     929        return Quat<T>(w * val.w - dot(v1, v2), v3.x, v3.y, v3.z);
    927930    }
    928931
     
    934937    inline Quat<T> operator ~() const
    935938    {
    936         return Quat<T>(-x, -y, -z, w);
     939        return Quat<T>(w, -x, -y, -z);
    937940    }
    938941
     
    942945#endif
    943946
     947    /* Storage order is still xyzw because operator[] uses &this->x */
    944948    T x, y, z, w;
    945949};
Note: See TracChangeset for help on using the changeset viewer.