From 2bf4cb668b37aa3df8696bdf338705c88bbef6f3 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 24 Sep 2012 06:44:37 +0000 Subject: [PATCH] math: add a uniform scaling matrix constructor. --- src/lol/math/vector.h | 6 ++++++ src/math/vector.cpp | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index 9ffebd69..e6d3647b 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -1696,6 +1696,7 @@ template struct Mat3 inline Vec3 const& operator[](size_t n) const { return (&v0)[n]; } /* Helpers for transformation matrices */ + static Mat3 scale(T x); 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); @@ -1832,6 +1833,11 @@ template struct Mat4 static Mat4 translate(T x, T y, T z); static Mat4 translate(Vec3 v); + static inline Mat4 scale(T x) + { + return Mat4(Mat3::scale(x), (T)1); + } + static inline Mat4 scale(T x, T y, T z) { return Mat4(Mat3::scale(x, y, z), (T)1); diff --git a/src/math/vector.cpp b/src/math/vector.cpp index 3066de3e..9fd2e194 100644 --- a/src/math/vector.cpp +++ b/src/math/vector.cpp @@ -305,6 +305,17 @@ template<> std::ostream &operator<<(std::ostream &stream, mat4 const &m) return stream; } +template<> mat3 mat3::scale(float x) +{ + mat3 ret(1.0f); + + ret[0][0] = x; + ret[1][1] = x; + ret[2][2] = x; + + return ret; +} + template<> mat3 mat3::scale(float x, float y, float z) { mat3 ret(1.0f);