diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index ed66146d..5e47c8f2 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -1351,6 +1351,10 @@ template struct Mat2 : v0(val, (T)0), v1((T)0, val) {} + explicit inline Mat2(Mat4 const &mat) + : v0(mat[0].xy), + v1(mat[1].xy) {} + inline Vec2& operator[](size_t n) { return (&v0)[n]; } inline Vec2 const& operator[](size_t n) const { return (&v0)[n]; } @@ -1430,6 +1434,11 @@ template struct Mat3 v1((T)0, val, (T)0), v2((T)0, (T)0, val) {} + explicit inline Mat3(Mat4 const &mat) + : v0(mat[0].xyz), + v1(mat[1].xyz), + v2(mat[2].xyz) {} + inline Vec3& operator[](size_t n) { return (&v0)[n]; } inline Vec3 const& operator[](size_t n) const { return (&v0)[n]; } @@ -1443,6 +1452,11 @@ template struct Mat3 return rotate(angle, v) * mat; } + static Mat3 normal(Mat3 const &mat) + { + return transpose(inverse(mat)); + } + void printf() const; #if !defined __ANDROID__ @@ -1532,7 +1546,10 @@ template struct Mat4 return rotate(angle, v) * mat; } - static Mat3 normal(Mat4 const &mat); + static Mat3 normal(Mat4 const &mat) + { + return transpose(inverse(Mat3(mat))); + } /* Helpers for view matrices */ static Mat4 lookat(Vec3 eye, Vec3 center, Vec3 up);