Browse Source

math: add a uniform scaling matrix constructor.

legacy
Sam Hocevar sam 12 years ago
parent
commit
2bf4cb668b
2 changed files with 17 additions and 0 deletions
  1. +6
    -0
      src/lol/math/vector.h
  2. +11
    -0
      src/math/vector.cpp

+ 6
- 0
src/lol/math/vector.h View File

@@ -1696,6 +1696,7 @@ template <typename T> struct Mat3
inline Vec3<T> const& operator[](size_t n) const { return (&v0)[n]; }

/* Helpers for transformation matrices */
static Mat3<T> scale(T x);
static Mat3<T> scale(T x, T y, T z);
static Mat3<T> scale(Vec3<T> v);
static Mat3<T> rotate(T angle, T x, T y, T z);
@@ -1832,6 +1833,11 @@ template <typename T> struct Mat4
static Mat4<T> translate(T x, T y, T z);
static Mat4<T> translate(Vec3<T> v);

static inline Mat4<T> scale(T x)
{
return Mat4<T>(Mat3<T>::scale(x), (T)1);
}

static inline Mat4<T> scale(T x, T y, T z)
{
return Mat4<T>(Mat3<T>::scale(x, y, z), (T)1);


+ 11
- 0
src/math/vector.cpp View File

@@ -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);


Loading…
Cancel
Save