Kaynağa Gözat

math: new mat3::scale() and mat4::scale() methods.

legacy
Sam Hocevar sam 12 yıl önce
ebeveyn
işleme
bed2d554c1
2 değiştirilmiş dosya ile 28 ekleme ve 0 silme
  1. +12
    -0
      src/lol/math/vector.h
  2. +16
    -0
      src/math/vector.cpp

+ 12
- 0
src/lol/math/vector.h Dosyayı Görüntüle

@@ -1453,6 +1453,8 @@ 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, T y, T z);
static Mat3<T> scale(Vec3<T> v);
static Mat3<T> rotate(T angle, T x, T y, T z);
static Mat3<T> rotate(T angle, Vec3<T> v);
static Mat3<T> rotate(Quat<T> q);
@@ -1562,6 +1564,16 @@ 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, T y, T z)
{
return Mat4<T>(Mat3<T>::scale(x, y, z), (T)1);
}

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

static inline Mat4<T> translate(Mat4<T> const &mat, Vec3<T> v)
{
return translate(v) * mat;


+ 16
- 0
src/math/vector.cpp Dosyayı Görüntüle

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


Yükleniyor…
İptal
Kaydet