Ignore:
Timestamp:
Apr 21, 2012, 6:58:30 PM (8 years ago)
Author:
sam
Message:

math: add code to build the normal matrix from a transformation matrix.

File:
1 edited

Legend:

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

    r1257 r1258  
    13521352        v1((T)0, val) {}
    13531353
     1354    explicit inline Mat2(Mat4<T> const &mat)
     1355      : v0(mat[0].xy),
     1356        v1(mat[1].xy) {}
     1357
    13541358    inline Vec2<T>& operator[](size_t n) { return (&v0)[n]; }
    13551359    inline Vec2<T> const& operator[](size_t n) const { return (&v0)[n]; }
     
    14311435        v2((T)0, (T)0, val) {}
    14321436
     1437    explicit inline Mat3(Mat4<T> const &mat)
     1438      : v0(mat[0].xyz),
     1439        v1(mat[1].xyz),
     1440        v2(mat[2].xyz) {}
     1441
    14331442    inline Vec3<T>& operator[](size_t n) { return (&v0)[n]; }
    14341443    inline Vec3<T> const& operator[](size_t n) const { return (&v0)[n]; }
     
    14421451    {
    14431452        return rotate(angle, v) * mat;
     1453    }
     1454
     1455    static Mat3<T> normal(Mat3<T> const &mat)
     1456    {
     1457        return transpose(inverse(mat));
    14441458    }
    14451459
     
    15331547    }
    15341548
    1535     static Mat3<T> normal(Mat4<T> const &mat);
     1549    static Mat3<T> normal(Mat4<T> const &mat)
     1550    {
     1551        return transpose(inverse(Mat3<T>(mat)));
     1552    }
    15361553
    15371554    /* Helpers for view matrices */
Note: See TracChangeset for help on using the changeset viewer.