Changeset 1270


Ignore:
Timestamp:
Apr 22, 2012, 3:03:54 PM (11 years ago)
Author:
sam
Message:

math: implement rotate() for mat3 in addition to mat4.

Location:
trunk/src
Files:
2 edited

Legend:

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

    r1264 r1270  
    15621562    static Mat4<T> translate(T x, T y, T z);
    15631563    static Mat4<T> translate(Vec3<T> v);
    1564     static Mat4<T> rotate(T angle, T x, T y, T z);
    1565     static Mat4<T> rotate(T angle, Vec3<T> v);
    1566     static Mat4<T> rotate(Quat<T> q);
    15671564
    15681565    static inline Mat4<T> translate(Mat4<T> const &mat, Vec3<T> v)
    15691566    {
    15701567        return translate(v) * mat;
     1568    }
     1569
     1570    static inline Mat4<T> rotate(T angle, T x, T y, T z)
     1571    {
     1572        return Mat4<T>(Mat3<T>::rotate(angle, x, y, z), (T)1);
     1573    }
     1574
     1575    static inline Mat4<T> rotate(T angle, Vec3<T> v)
     1576    {
     1577        return Mat4<T>(Mat3<T>::rotate(angle, v), (T)1);
     1578    }
     1579
     1580    static inline Mat4<T> rotate(Quat<T> q)
     1581    {
     1582        return Mat4<T>(Mat3<T>::rotate(q), (T)1);
    15711583    }
    15721584
  • trunk/src/math/vector.cpp

    r1257 r1270  
    321321}
    322322
    323 template<> mat4 mat4::rotate(float angle, float x, float y, float z)
     323template<> mat2 mat2::rotate(float angle)
     324{
     325    angle *= (M_PI / 180.0f);
     326
     327    float st = sinf(angle);
     328    float ct = cosf(angle);
     329
     330    mat2 ret;
     331
     332    ret[0][0] = ct;
     333    ret[0][1] = st;
     334
     335    ret[1][0] = -st;
     336    ret[1][1] = ct;
     337
     338    return ret;
     339}
     340
     341template<> mat3 mat3::rotate(float angle, float x, float y, float z)
    324342{
    325343    angle *= (M_PI / 180.0f);
     
    338356    float mtz = (1.0f - ct) * z;
    339357
    340     mat4 ret(1.0f);
     358    mat3 ret;
    341359
    342360    ret[0][0] = x * mtx + ct;
     
    355373}
    356374
    357 template<> mat4 mat4::rotate(float angle, vec3 v)
     375template<> mat3 mat3::rotate(float angle, vec3 v)
    358376{
    359377    return rotate(angle, v.x, v.y, v.z);
    360378}
    361379
    362 template<> mat4 mat4::rotate(quat q)
    363 {
    364     mat4 ret(1.0f);
     380template<> mat3 mat3::rotate(quat q)
     381{
    365382    float n = norm(q);
    366383
    367384    if (!n)
    368         return ret;
    369 
     385        return mat3(1.0f);
     386
     387    mat3 ret;
    370388    float s = 2.0f / n;
    371389
Note: See TracChangeset for help on using the changeset viewer.