diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index 260430d5..9710c4fb 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -1561,15 +1561,27 @@ template struct Mat4 /* Helpers for transformation matrices */ static Mat4 translate(T x, T y, T z); static Mat4 translate(Vec3 v); - static Mat4 rotate(T angle, T x, T y, T z); - static Mat4 rotate(T angle, Vec3 v); - static Mat4 rotate(Quat q); static inline Mat4 translate(Mat4 const &mat, Vec3 v) { return translate(v) * mat; } + static inline Mat4 rotate(T angle, T x, T y, T z) + { + return Mat4(Mat3::rotate(angle, x, y, z), (T)1); + } + + static inline Mat4 rotate(T angle, Vec3 v) + { + return Mat4(Mat3::rotate(angle, v), (T)1); + } + + static inline Mat4 rotate(Quat q) + { + return Mat4(Mat3::rotate(q), (T)1); + } + static inline Mat4 rotate(Mat4 &mat, T angle, Vec3 v) { return rotate(angle, v) * mat; diff --git a/src/math/vector.cpp b/src/math/vector.cpp index 2bd82214..24d67a53 100644 --- a/src/math/vector.cpp +++ b/src/math/vector.cpp @@ -320,7 +320,25 @@ template<> mat4 mat4::translate(vec3 v) return translate(v.x, v.y, v.z); } -template<> mat4 mat4::rotate(float angle, float x, float y, float z) +template<> mat2 mat2::rotate(float angle) +{ + angle *= (M_PI / 180.0f); + + float st = sinf(angle); + float ct = cosf(angle); + + mat2 ret; + + ret[0][0] = ct; + ret[0][1] = st; + + ret[1][0] = -st; + ret[1][1] = ct; + + return ret; +} + +template<> mat3 mat3::rotate(float angle, float x, float y, float z) { angle *= (M_PI / 180.0f); @@ -337,7 +355,7 @@ template<> mat4 mat4::rotate(float angle, float x, float y, float z) float mty = (1.0f - ct) * y; float mtz = (1.0f - ct) * z; - mat4 ret(1.0f); + mat3 ret; ret[0][0] = x * mtx + ct; ret[0][1] = x * mty + st * z; @@ -354,19 +372,19 @@ template<> mat4 mat4::rotate(float angle, float x, float y, float z) return ret; } -template<> mat4 mat4::rotate(float angle, vec3 v) +template<> mat3 mat3::rotate(float angle, vec3 v) { return rotate(angle, v.x, v.y, v.z); } -template<> mat4 mat4::rotate(quat q) +template<> mat3 mat3::rotate(quat q) { - mat4 ret(1.0f); float n = norm(q); if (!n) - return ret; + return mat3(1.0f); + mat3 ret; float s = 2.0f / n; ret[0][0] = 1.0f - s * (q.y * q.y + q.z * q.z);