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/math/vector.cpp

    r1272 r1305  
    204204template<> void quat::printf() const
    205205{
    206     Log::Debug("[ %6.6f %6.6f %6.6f %6.6f ]\n", x, y, z, w);
     206    Log::Debug("[ %6.6f %6.6f %6.6f %6.6f ]\n", w, x, y, z);
    207207}
    208208
     
    341341    angle *= (M_PI / 180.0f);
    342342
    343     float st = sinf(angle);
    344     float ct = cosf(angle);
     343    float st = std::sin(angle);
     344    float ct = std::cos(angle);
    345345
    346346    mat2 ret;
     
    359359    angle *= (M_PI / 180.0f);
    360360
    361     float st = sinf(angle);
    362     float ct = cosf(angle);
     361    float st = std::sin(angle);
     362    float ct = std::cos(angle);
    363363
    364364    float len = sqrtf(x * x + y * y + z * z);
     
    455455        w = s * (m[1][0] - m[0][1]);
    456456    }
     457}
     458
     459template<> quat quat::rotate(float angle, vec3 const &v)
     460{
     461    angle *= (M_PI / 360.0f);
     462
     463    vec3 tmp = normalize(v) * std::sin(angle);
     464
     465    return quat(tmp.x, tmp.y, tmp.z, std::cos(angle));
     466}
     467
     468template<> quat quat::rotate(float angle, float x, float y, float z)
     469{
     470    return quat::rotate(angle, vec3(x, y, z));
    457471}
    458472
Note: See TracChangeset for help on using the changeset viewer.