diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index 9710c4fb..b5940e79 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -1453,6 +1453,8 @@ template struct Mat3 inline Vec3 const& operator[](size_t n) const { return (&v0)[n]; } /* Helpers for transformation matrices */ + static Mat3 scale(T x, T y, T z); + static Mat3 scale(Vec3 v); static Mat3 rotate(T angle, T x, T y, T z); static Mat3 rotate(T angle, Vec3 v); static Mat3 rotate(Quat q); @@ -1562,6 +1564,16 @@ template struct Mat4 static Mat4 translate(T x, T y, T z); static Mat4 translate(Vec3 v); + static inline Mat4 scale(T x, T y, T z) + { + return Mat4(Mat3::scale(x, y, z), (T)1); + } + + static inline Mat4 scale(Vec3 v) + { + return Mat4(Mat3::scale(v), (T)1); + } + static inline Mat4 translate(Mat4 const &mat, Vec3 v) { return translate(v) * mat; diff --git a/src/math/vector.cpp b/src/math/vector.cpp index 24d67a53..7d81cbd3 100644 --- a/src/math/vector.cpp +++ b/src/math/vector.cpp @@ -306,6 +306,22 @@ template<> std::ostream &operator<<(std::ostream &stream, mat4 const &m) } #endif +template<> mat3 mat3::scale(float x, float y, float z) +{ + mat3 ret(1.0f); + + ret[0][0] = x; + ret[1][1] = y; + ret[2][2] = z; + + return ret; +} + +template<> mat3 mat3::scale(vec3 v) +{ + return scale(v.x, v.y, v.z); +} + template<> mat4 mat4::translate(float x, float y, float z) { mat4 ret(1.0f);