ソースを参照

math: finish renaming matrix<> to mat<>.

undefined
Sam Hocevar 10年前
コミット
52cd11358e
5個のファイルの変更157行の追加157行の削除
  1. +10
    -10
      src/lol/base/types.h
  2. +140
    -140
      src/lol/math/matrix.h
  3. +2
    -2
      src/lol/math/transform.h
  4. +3
    -3
      src/math/constants.cpp
  5. +2
    -2
      src/math/vector.cpp

+ 10
- 10
src/lol/base/types.h ファイルの表示

@@ -38,7 +38,7 @@ int const FULL_SWIZZLE = 0xaaaa;
int const NO_SWIZZLE = 0xbbbb;

template<int N, typename T, int SWIZZLE = FULL_SWIZZLE> struct vec;
template<int COLS, int ROWS, typename T> struct matrix;
template<int COLS, int ROWS, typename T> struct mat;
template<typename T> struct Cmplx;
template<typename T> struct Quat;

@@ -68,16 +68,16 @@ LOL_VECTOR_TYPEDEFS(vec<2 COMMA, >, vec2)
LOL_VECTOR_TYPEDEFS(vec<3 COMMA, >, vec3)
LOL_VECTOR_TYPEDEFS(vec<4 COMMA, >, vec4)

LOL_VECTOR_TYPEDEFS(matrix<2 COMMA 2 COMMA, >, mat2)
LOL_VECTOR_TYPEDEFS(matrix<3 COMMA 3 COMMA, >, mat3)
LOL_VECTOR_TYPEDEFS(matrix<4 COMMA 4 COMMA, >, mat4)
LOL_VECTOR_TYPEDEFS(mat<2 COMMA 2 COMMA, >, mat2)
LOL_VECTOR_TYPEDEFS(mat<3 COMMA 3 COMMA, >, mat3)
LOL_VECTOR_TYPEDEFS(mat<4 COMMA 4 COMMA, >, mat4)

LOL_VECTOR_TYPEDEFS(matrix<2 COMMA 3 COMMA, >, mat2x3)
LOL_VECTOR_TYPEDEFS(matrix<2 COMMA 4 COMMA, >, mat2x4)
LOL_VECTOR_TYPEDEFS(matrix<3 COMMA 2 COMMA, >, mat3x2)
LOL_VECTOR_TYPEDEFS(matrix<3 COMMA 4 COMMA, >, mat3x4)
LOL_VECTOR_TYPEDEFS(matrix<4 COMMA 2 COMMA, >, mat4x2)
LOL_VECTOR_TYPEDEFS(matrix<4 COMMA 3 COMMA, >, mat4x3)
LOL_VECTOR_TYPEDEFS(mat<2 COMMA 3 COMMA, >, mat2x3)
LOL_VECTOR_TYPEDEFS(mat<2 COMMA 4 COMMA, >, mat2x4)
LOL_VECTOR_TYPEDEFS(mat<3 COMMA 2 COMMA, >, mat3x2)
LOL_VECTOR_TYPEDEFS(mat<3 COMMA 4 COMMA, >, mat3x4)
LOL_VECTOR_TYPEDEFS(mat<4 COMMA 2 COMMA, >, mat4x2)
LOL_VECTOR_TYPEDEFS(mat<4 COMMA 3 COMMA, >, mat4x3)

LOL_VECTOR_TYPEDEFS(Cmplx<, >, cmplx)
LOL_VECTOR_TYPEDEFS(Quat<, >, quat)


+ 140
- 140
src/lol/math/matrix.h ファイルの表示

@@ -33,13 +33,13 @@ namespace lol
*/

template<int COLS, int ROWS, typename T>
struct matrix
struct mat
{
typedef matrix<COLS,ROWS,T> type;
typedef mat<COLS,ROWS,T> type;

inline matrix() {}
inline mat() {}

explicit inline matrix(T const &val)
explicit inline mat(T const &val)
{
T const zero = T(0);
for (int i = 0; i < COLS; ++i)
@@ -59,19 +59,19 @@ private:
*/

template <typename T>
struct matrix<2, 2, T>
struct mat<2, 2, T>
{
typedef matrix<2,2,T> type;
typedef mat<2,2,T> type;

inline matrix() {}
inline matrix(vec<2,T> v0, vec<2,T> v1)
inline mat() {}
inline mat(vec<2,T> v0, vec<2,T> v1)
#if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS
: m_data{ v0, v1 } {}
#else
: m_v0(v0), m_v1(v1) {}
#endif

explicit inline matrix(T const &val)
explicit inline mat(T const &val)
#if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS
: m_data{ vec<2,T>(val, T(0)),
vec<2,T>(T(0), val) } {}
@@ -80,7 +80,7 @@ struct matrix<2, 2, T>
m_v1(T(0), val) {}
#endif

explicit inline matrix(matrix<4,4,T> const &m)
explicit inline mat(mat<4,4,T> const &m)
#if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS
: m_data{ m[0].xy, m[1].xy } {}
#else
@@ -96,8 +96,8 @@ struct matrix<2, 2, T>
#endif

/* Helpers for transformation matrices */
static matrix<2,2,T> rotate(T degrees);
static inline matrix<2,2,T> rotate(matrix<2,2,T> m, T degrees)
static mat<2,2,T> rotate(T degrees);
static inline mat<2,2,T> rotate(mat<2,2,T> m, T degrees)
{
return rotate(degrees) * m;
}
@@ -107,9 +107,9 @@ struct matrix<2, 2, T>

template<class U>
friend std::ostream &operator<<(std::ostream &stream,
matrix<2,2,U> const &m);
mat<2,2,U> const &m);

static const matrix<2,2,T> identity;
static const mat<2,2,T> identity;

private:
#if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS
@@ -124,19 +124,19 @@ private:
*/

template <typename T>
struct matrix<3,3,T>
struct mat<3,3,T>
{
typedef matrix<3,3,T> type;
typedef mat<3,3,T> type;

inline matrix() {}
inline matrix(vec<3,T> v0, vec<3,T> v1, vec<3,T> v2)
inline mat() {}
inline mat(vec<3,T> v0, vec<3,T> v1, vec<3,T> v2)
#if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS
: m_data{ v0, v1, v2 } {}
#else
: m_v0(v0), m_v1(v1), m_v2(v2) {}
#endif

explicit inline matrix(T const &val)
explicit inline mat(T const &val)
#if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS
: m_data{ vec<3,T>(val, (T)0, (T)0),
vec<3,T>((T)0, val, (T)0),
@@ -147,7 +147,7 @@ struct matrix<3,3,T>
m_v2((T)0, (T)0, val) {}
#endif

explicit inline matrix(matrix<2,2,T> m, T const &val = T(1))
explicit inline mat(mat<2,2,T> m, T const &val = T(1))
#if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS
: m_data{ vec<3,T>(m[0], (T)0),
vec<3,T>(m[1], (T)0),
@@ -158,14 +158,14 @@ struct matrix<3,3,T>
m_v2((T)0, (T)0, val) {}
#endif

explicit inline matrix(matrix<4,4,T> const &m)
explicit inline mat(mat<4,4,T> const &m)
#if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS
: m_data{ m[0].xyz, m[1].xyz, m[2].xyz } {}
#else
: m_v0(m[0].xyz), m_v1(m[1].xyz), m_v2(m[2].xyz) {}
#endif

explicit matrix(Quat<T> const &q);
explicit mat(Quat<T> const &q);

#if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS
inline vec<3,T>& operator[](size_t n) { return m_data[n]; }
@@ -176,39 +176,39 @@ struct matrix<3,3,T>
#endif

/* Helpers for transformation matrices */
static matrix<3,3,T> scale(T x);
static matrix<3,3,T> scale(T x, T y, T z);
static matrix<3,3,T> scale(vec<3,T> v);
static matrix<3,3,T> rotate(T degrees, T x, T y, T z);
static matrix<3,3,T> rotate(T degrees, vec<3,T> v);
static matrix<3,3,T> fromeuler_xyz(vec<3,T> const &v);
static matrix<3,3,T> fromeuler_xzy(vec<3,T> const &v);
static matrix<3,3,T> fromeuler_yxz(vec<3,T> const &v);
static matrix<3,3,T> fromeuler_yzx(vec<3,T> const &v);
static matrix<3,3,T> fromeuler_zxy(vec<3,T> const &v);
static matrix<3,3,T> fromeuler_zyx(vec<3,T> const &v);
static matrix<3,3,T> fromeuler_xyz(T phi, T theta, T psi);
static matrix<3,3,T> fromeuler_xzy(T phi, T theta, T psi);
static matrix<3,3,T> fromeuler_yxz(T phi, T theta, T psi);
static matrix<3,3,T> fromeuler_yzx(T phi, T theta, T psi);
static matrix<3,3,T> fromeuler_zxy(T phi, T theta, T psi);
static matrix<3,3,T> fromeuler_zyx(T phi, T theta, T psi);
static matrix<3,3,T> fromeuler_xyx(vec<3,T> const &v);
static matrix<3,3,T> fromeuler_xzx(vec<3,T> const &v);
static matrix<3,3,T> fromeuler_yxy(vec<3,T> const &v);
static matrix<3,3,T> fromeuler_yzy(vec<3,T> const &v);
static matrix<3,3,T> fromeuler_zxz(vec<3,T> const &v);
static matrix<3,3,T> fromeuler_zyz(vec<3,T> const &v);
static matrix<3,3,T> fromeuler_xyx(T phi, T theta, T psi);
static matrix<3,3,T> fromeuler_xzx(T phi, T theta, T psi);
static matrix<3,3,T> fromeuler_yxy(T phi, T theta, T psi);
static matrix<3,3,T> fromeuler_yzy(T phi, T theta, T psi);
static matrix<3,3,T> fromeuler_zxz(T phi, T theta, T psi);
static matrix<3,3,T> fromeuler_zyz(T phi, T theta, T psi);
static inline matrix<3,3,T> rotate(matrix<3,3,T> m, T degrees, vec<3,T> v)
static mat<3,3,T> scale(T x);
static mat<3,3,T> scale(T x, T y, T z);
static mat<3,3,T> scale(vec<3,T> v);
static mat<3,3,T> rotate(T degrees, T x, T y, T z);
static mat<3,3,T> rotate(T degrees, vec<3,T> v);
static mat<3,3,T> fromeuler_xyz(vec<3,T> const &v);
static mat<3,3,T> fromeuler_xzy(vec<3,T> const &v);
static mat<3,3,T> fromeuler_yxz(vec<3,T> const &v);
static mat<3,3,T> fromeuler_yzx(vec<3,T> const &v);
static mat<3,3,T> fromeuler_zxy(vec<3,T> const &v);
static mat<3,3,T> fromeuler_zyx(vec<3,T> const &v);
static mat<3,3,T> fromeuler_xyz(T phi, T theta, T psi);
static mat<3,3,T> fromeuler_xzy(T phi, T theta, T psi);
static mat<3,3,T> fromeuler_yxz(T phi, T theta, T psi);
static mat<3,3,T> fromeuler_yzx(T phi, T theta, T psi);
static mat<3,3,T> fromeuler_zxy(T phi, T theta, T psi);
static mat<3,3,T> fromeuler_zyx(T phi, T theta, T psi);
static mat<3,3,T> fromeuler_xyx(vec<3,T> const &v);
static mat<3,3,T> fromeuler_xzx(vec<3,T> const &v);
static mat<3,3,T> fromeuler_yxy(vec<3,T> const &v);
static mat<3,3,T> fromeuler_yzy(vec<3,T> const &v);
static mat<3,3,T> fromeuler_zxz(vec<3,T> const &v);
static mat<3,3,T> fromeuler_zyz(vec<3,T> const &v);
static mat<3,3,T> fromeuler_xyx(T phi, T theta, T psi);
static mat<3,3,T> fromeuler_xzx(T phi, T theta, T psi);
static mat<3,3,T> fromeuler_yxy(T phi, T theta, T psi);
static mat<3,3,T> fromeuler_yzy(T phi, T theta, T psi);
static mat<3,3,T> fromeuler_zxz(T phi, T theta, T psi);
static mat<3,3,T> fromeuler_zyz(T phi, T theta, T psi);
static inline mat<3,3,T> rotate(mat<3,3,T> m, T degrees, vec<3,T> v)
{
return rotate(degrees, v) * m;
}
@@ -218,9 +218,9 @@ struct matrix<3,3,T>

template<class U>
friend std::ostream &operator<<(std::ostream &stream,
matrix<3,3,U> const &m);
mat<3,3,U> const &m);

static const matrix<3,3,T> identity;
static const mat<3,3,T> identity;

private:
#if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS
@@ -235,19 +235,19 @@ private:
*/

template <typename T>
struct matrix<4, 4, T>
struct mat<4, 4, T>
{
typedef matrix<4,4,T> type;
typedef mat<4,4,T> type;

inline matrix() {}
inline matrix(vec<4,T> v0, vec<4,T> v1, vec<4,T> v2, vec<4,T> v3)
inline mat() {}
inline mat(vec<4,T> v0, vec<4,T> v1, vec<4,T> v2, vec<4,T> v3)
#if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS
: m_data{ v0, v1, v2, v3 } {}
#else
: m_v0(v0), m_v1(v1), m_v2(v2), m_v3(v3) {}
#endif

explicit inline matrix(T const &val)
explicit inline mat(T const &val)
#if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS
: m_data{ vec<4,T>(val, (T)0, (T)0, (T)0),
vec<4,T>((T)0, val, (T)0, (T)0),
@@ -260,7 +260,7 @@ struct matrix<4, 4, T>
m_v3((T)0, (T)0, (T)0, val) {}
#endif

explicit inline matrix(matrix<2,2,T> m, T const &val = T(1))
explicit inline mat(mat<2,2,T> m, T const &val = T(1))
#if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS
: m_data{ vec<4,T>(m[0], (T)0, (T)0),
vec<4,T>(m[1], (T)0, (T)0),
@@ -273,7 +273,7 @@ struct matrix<4, 4, T>
m_v3((T)0, (T)0, (T)0, val) {}
#endif

explicit inline matrix(matrix<3,3,T> m, T const &val = T(1))
explicit inline mat(mat<3,3,T> m, T const &val = T(1))
#if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS
: m_data{ vec<4,T>(m[0], (T)0),
vec<4,T>(m[1], (T)0),
@@ -286,7 +286,7 @@ struct matrix<4, 4, T>
m_v3((T)0, (T)0, (T)0, val) {}
#endif

explicit matrix(Quat<T> const &q);
explicit mat(Quat<T> const &q);

#if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS
inline vec<4,T>& operator[](size_t n) { return m_data[n]; }
@@ -297,88 +297,88 @@ struct matrix<4, 4, T>
#endif

/* Helpers for transformation matrices */
static matrix<4,4,T> translate(T x, T y, T z);
static matrix<4,4,T> translate(vec<3,T> v);
static mat<4,4,T> translate(T x, T y, T z);
static mat<4,4,T> translate(vec<3,T> v);

static inline matrix<4,4,T> scale(T x)
static inline mat<4,4,T> scale(T x)
{
return matrix<4,4,T>(matrix<3,3,T>::scale(x), (T)1);
return mat<4,4,T>(mat<3,3,T>::scale(x), (T)1);
}

static inline matrix<4,4,T> scale(T x, T y, T z)
static inline mat<4,4,T> scale(T x, T y, T z)
{
return matrix<4,4,T>(matrix<3,3,T>::scale(x, y, z), (T)1);
return mat<4,4,T>(mat<3,3,T>::scale(x, y, z), (T)1);
}

static inline matrix<4,4,T> scale(vec<3,T> v)
static inline mat<4,4,T> scale(vec<3,T> v)
{
return matrix<4,4,T>(matrix<3,3,T>::scale(v), (T)1);
return mat<4,4,T>(mat<3,3,T>::scale(v), (T)1);
}

static inline matrix<4,4,T> translate(matrix<4,4,T> const &m, vec<3,T> v)
static inline mat<4,4,T> translate(mat<4,4,T> const &m, vec<3,T> v)
{
return translate(v) * m;
}

static inline matrix<4,4,T> rotate(T degrees, T x, T y, T z)
static inline mat<4,4,T> rotate(T degrees, T x, T y, T z)
{
return matrix<4,4,T>(matrix<3,3,T>::rotate(degrees, x, y, z), (T)1);
return mat<4,4,T>(mat<3,3,T>::rotate(degrees, x, y, z), (T)1);
}

static inline matrix<4,4,T> rotate(T degrees, vec<3,T> v)
static inline mat<4,4,T> rotate(T degrees, vec<3,T> v)
{
return matrix<4,4,T>(matrix<3,3,T>::rotate(degrees, v), (T)1);
return mat<4,4,T>(mat<3,3,T>::rotate(degrees, v), (T)1);
}

static inline matrix<4,4,T> rotate(matrix<4,4,T> &m, T degrees, vec<3,T> v)
static inline mat<4,4,T> rotate(mat<4,4,T> &m, T degrees, vec<3,T> v)
{
return rotate(degrees, v) * m;
}

static matrix<4,4,T> fromeuler_xyz(vec<3,T> const &v);
static matrix<4,4,T> fromeuler_xzy(vec<3,T> const &v);
static matrix<4,4,T> fromeuler_yxz(vec<3,T> const &v);
static matrix<4,4,T> fromeuler_yzx(vec<3,T> const &v);
static matrix<4,4,T> fromeuler_zxy(vec<3,T> const &v);
static matrix<4,4,T> fromeuler_zyx(vec<3,T> const &v);
static matrix<4,4,T> fromeuler_xyz(T phi, T theta, T psi);
static matrix<4,4,T> fromeuler_xzy(T phi, T theta, T psi);
static matrix<4,4,T> fromeuler_yxz(T phi, T theta, T psi);
static matrix<4,4,T> fromeuler_yzx(T phi, T theta, T psi);
static matrix<4,4,T> fromeuler_zxy(T phi, T theta, T psi);
static matrix<4,4,T> fromeuler_zyx(T phi, T theta, T psi);
static matrix<4,4,T> fromeuler_xyx(vec<3,T> const &v);
static matrix<4,4,T> fromeuler_xzx(vec<3,T> const &v);
static matrix<4,4,T> fromeuler_yxy(vec<3,T> const &v);
static matrix<4,4,T> fromeuler_yzy(vec<3,T> const &v);
static matrix<4,4,T> fromeuler_zxz(vec<3,T> const &v);
static matrix<4,4,T> fromeuler_zyz(vec<3,T> const &v);
static matrix<4,4,T> fromeuler_xyx(T phi, T theta, T psi);
static matrix<4,4,T> fromeuler_xzx(T phi, T theta, T psi);
static matrix<4,4,T> fromeuler_yxy(T phi, T theta, T psi);
static matrix<4,4,T> fromeuler_yzy(T phi, T theta, T psi);
static matrix<4,4,T> fromeuler_zxz(T phi, T theta, T psi);
static matrix<4,4,T> fromeuler_zyz(T phi, T theta, T psi);
static mat<4,4,T> fromeuler_xyz(vec<3,T> const &v);
static mat<4,4,T> fromeuler_xzy(vec<3,T> const &v);
static mat<4,4,T> fromeuler_yxz(vec<3,T> const &v);
static mat<4,4,T> fromeuler_yzx(vec<3,T> const &v);
static mat<4,4,T> fromeuler_zxy(vec<3,T> const &v);
static mat<4,4,T> fromeuler_zyx(vec<3,T> const &v);
static mat<4,4,T> fromeuler_xyz(T phi, T theta, T psi);
static mat<4,4,T> fromeuler_xzy(T phi, T theta, T psi);
static mat<4,4,T> fromeuler_yxz(T phi, T theta, T psi);
static mat<4,4,T> fromeuler_yzx(T phi, T theta, T psi);
static mat<4,4,T> fromeuler_zxy(T phi, T theta, T psi);
static mat<4,4,T> fromeuler_zyx(T phi, T theta, T psi);
static mat<4,4,T> fromeuler_xyx(vec<3,T> const &v);
static mat<4,4,T> fromeuler_xzx(vec<3,T> const &v);
static mat<4,4,T> fromeuler_yxy(vec<3,T> const &v);
static mat<4,4,T> fromeuler_yzy(vec<3,T> const &v);
static mat<4,4,T> fromeuler_zxz(vec<3,T> const &v);
static mat<4,4,T> fromeuler_zyz(vec<3,T> const &v);
static mat<4,4,T> fromeuler_xyx(T phi, T theta, T psi);
static mat<4,4,T> fromeuler_xzx(T phi, T theta, T psi);
static mat<4,4,T> fromeuler_yxy(T phi, T theta, T psi);
static mat<4,4,T> fromeuler_yzy(T phi, T theta, T psi);
static mat<4,4,T> fromeuler_zxz(T phi, T theta, T psi);
static mat<4,4,T> fromeuler_zyz(T phi, T theta, T psi);

/* Helpers for view matrices */
static matrix<4,4,T> lookat(vec<3,T> eye, vec<3,T> center, vec<3,T> up);
static mat<4,4,T> lookat(vec<3,T> eye, vec<3,T> center, vec<3,T> up);

/* Helpers for projection matrices */
static matrix<4,4,T> ortho(T left, T right, T bottom, T top, T near, T far);
static matrix<4,4,T> ortho(T width, T height, T near, T far);
static matrix<4,4,T> frustum(T left, T right, T bottom, T top, T near, T far);
static matrix<4,4,T> perspective(T fov_y, T width, T height, T near, T far);
static matrix<4,4,T> shifted_perspective(T fov_y, T screen_size, T screen_ratio_yx, T near, T far);
static mat<4,4,T> ortho(T left, T right, T bottom, T top, T near, T far);
static mat<4,4,T> ortho(T width, T height, T near, T far);
static mat<4,4,T> frustum(T left, T right, T bottom, T top, T near, T far);
static mat<4,4,T> perspective(T fov_y, T width, T height, T near, T far);
static mat<4,4,T> shifted_perspective(T fov_y, T screen_size, T screen_ratio_yx, T near, T far);

void printf() const;
String tostring() const;

template<class U>
friend std::ostream &operator<<(std::ostream &stream,
matrix<4,4,U> const &m);
mat<4,4,U> const &m);

static const matrix<4,4,T> identity;
static const mat<4,4,T> identity;

private:
#if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS
@@ -388,18 +388,18 @@ private:
#endif
};

template<typename T> T determinant(matrix<2,2,T> const &);
template<typename T> T determinant(matrix<3,3,T> const &);
template<typename T> T determinant(matrix<4,4,T> const &);
template<typename T> T determinant(mat<2,2,T> const &);
template<typename T> T determinant(mat<3,3,T> const &);
template<typename T> T determinant(mat<4,4,T> const &);

template<typename T> matrix<2,2,T> inverse(matrix<2,2,T> const &);
template<typename T> matrix<3,3,T> inverse(matrix<3,3,T> const &);
template<typename T> matrix<4,4,T> inverse(matrix<4,4,T> const &);
template<typename T> mat<2,2,T> inverse(mat<2,2,T> const &);
template<typename T> mat<3,3,T> inverse(mat<3,3,T> const &);
template<typename T> mat<4,4,T> inverse(mat<4,4,T> const &);

template<int COLS, int ROWS, typename T>
static inline matrix<ROWS, COLS, T> transpose(matrix<COLS, ROWS, T> const &m)
static inline mat<ROWS, COLS, T> transpose(mat<COLS, ROWS, T> const &m)
{
matrix<ROWS, COLS, T> ret;
mat<ROWS, COLS, T> ret;
for (int i = 0; i < COLS; ++i)
for (int j = 0; j < ROWS; ++j)
ret[j][i] = m[i][j];
@@ -411,8 +411,8 @@ static inline matrix<ROWS, COLS, T> transpose(matrix<COLS, ROWS, T> const &m)
*/

template<int COLS, int ROWS, typename T>
static inline matrix<COLS, ROWS, T> &operator +=(matrix<COLS, ROWS, T> &a,
matrix<COLS, ROWS, T> const &b)
static inline mat<COLS, ROWS, T> &operator +=(mat<COLS, ROWS, T> &a,
mat<COLS, ROWS, T> const &b)
{
for (int i = 0; i < COLS; ++i)
a[i] += b[i];
@@ -420,22 +420,22 @@ static inline matrix<COLS, ROWS, T> &operator +=(matrix<COLS, ROWS, T> &a,
}

template<int COLS, int ROWS, typename T>
static inline matrix<COLS, ROWS, T> operator +(matrix<COLS, ROWS, T> const &a,
matrix<COLS, ROWS, T> const &b)
static inline mat<COLS, ROWS, T> operator +(mat<COLS, ROWS, T> const &a,
mat<COLS, ROWS, T> const &b)
{
matrix<COLS, ROWS, T> ret = a;
mat<COLS, ROWS, T> ret = a;
return ret += b;
}

template<int COLS, int ROWS, typename T>
static inline matrix<COLS, ROWS, T> operator +(matrix<COLS, ROWS, T> const &m)
static inline mat<COLS, ROWS, T> operator +(mat<COLS, ROWS, T> const &m)
{
return m;
}

template<int COLS, int ROWS, typename T>
static inline matrix<COLS, ROWS, T> &operator -=(matrix<COLS, ROWS, T> &a,
matrix<COLS, ROWS, T> const &b)
static inline mat<COLS, ROWS, T> &operator -=(mat<COLS, ROWS, T> &a,
mat<COLS, ROWS, T> const &b)
{
for (int i = 0; i < COLS; ++i)
a[i] -= b[i];
@@ -443,17 +443,17 @@ static inline matrix<COLS, ROWS, T> &operator -=(matrix<COLS, ROWS, T> &a,
}

template<int COLS, int ROWS, typename T>
static inline matrix<COLS, ROWS, T> operator -(matrix<COLS, ROWS, T> const &a,
matrix<COLS, ROWS, T> const &b)
static inline mat<COLS, ROWS, T> operator -(mat<COLS, ROWS, T> const &a,
mat<COLS, ROWS, T> const &b)
{
matrix<COLS, ROWS, T> ret = a;
mat<COLS, ROWS, T> ret = a;
return ret -= b;
}

template<int COLS, int ROWS, typename T>
static inline matrix<COLS, ROWS, T> operator -(matrix<COLS, ROWS, T> const &m)
static inline mat<COLS, ROWS, T> operator -(mat<COLS, ROWS, T> const &m)
{
matrix<COLS, ROWS, T> ret;
mat<COLS, ROWS, T> ret;
for (int i = 0; i < COLS; ++i)
ret[i] = -m[i];
return ret;
@@ -464,7 +464,7 @@ static inline matrix<COLS, ROWS, T> operator -(matrix<COLS, ROWS, T> const &m)
*/

template<int COLS, int ROWS, int MASK, typename T>
static inline vec<ROWS, T> operator *(matrix<COLS, ROWS, T> const &m,
static inline vec<ROWS, T> operator *(mat<COLS, ROWS, T> const &m,
vec<COLS, T, MASK> const &v)
{
vec<ROWS, T> ret(T(0));
@@ -475,7 +475,7 @@ static inline vec<ROWS, T> operator *(matrix<COLS, ROWS, T> const &m,

template<int COLS, int ROWS, int MASK, typename T>
static inline vec<COLS, T> operator *(vec<ROWS, T, MASK> const &v,
matrix<COLS, ROWS, T> const &m)
mat<COLS, ROWS, T> const &m)
{
vec<COLS, T> ret(T(0));
for (int i = 0; i < COLS; ++i)
@@ -488,18 +488,18 @@ static inline vec<COLS, T> operator *(vec<ROWS, T, MASK> const &v,
*/

template<int COLS, int N, int ROWS, typename T>
static inline matrix<COLS, ROWS, T> operator *(matrix<N, ROWS, T> const &a,
matrix<COLS, N, T> const &b)
static inline mat<COLS, ROWS, T> operator *(mat<N, ROWS, T> const &a,
mat<COLS, N, T> const &b)
{
matrix<COLS, ROWS, T> ret;
mat<COLS, ROWS, T> ret;
for (int i = 0; i < COLS; ++i)
ret[i] = a * b[i];
return ret;
}

template<int N, typename T>
static inline matrix<N, N, T> &operator *=(matrix<N, N, T> &a,
matrix<N, N, T> const &b)
static inline mat<N, N, T> &operator *=(mat<N, N, T> &a,
mat<N, N, T> const &b)
{
return a = a * b;
}


+ 2
- 2
src/lol/math/transform.h ファイルの表示

@@ -155,8 +155,8 @@ template <typename T> struct Quat
explicit inline constexpr Quat(Quat<U> const &q)
: w(q.w), x(q.x), y(q.y), z(q.z) {}

Quat(matrix<3,3,T> const &m);
Quat(matrix<4,4,T> const &m);
Quat(mat<3,3,T> const &m);
Quat(mat<4,4,T> const &m);

LOL_COMMON_MEMBER_OPS(w)
LOL_NONVECTOR_MEMBER_OPS()


+ 3
- 3
src/math/constants.cpp ファイルの表示

@@ -30,13 +30,13 @@ namespace lol {

#define LOL_MAT_CONST(type, name, a) \
template<> \
matrix<2,2,type> const matrix<2,2,type>::name = matrix<2,2,type>((type)a); \
mat<2,2,type> const mat<2,2,type>::name = mat<2,2,type>((type)a); \
\
template<> \
matrix<3,3,type> const matrix<3,3,type>::name = matrix<3,3,type>((type)a); \
mat<3,3,type> const mat<3,3,type>::name = mat<3,3,type>((type)a); \
\
template<> \
matrix<4,4,type> const matrix<4,4,type>::name = matrix<4,4,type>((type)a);
mat<4,4,type> const mat<4,4,type>::name = mat<4,4,type>((type)a);

#define LOL_ALL_CONST_INNER(type) \
LOL_VEC_2_CONST(type, zero, 0, 0) \


+ 2
- 2
src/math/vector.cpp ファイルの表示

@@ -378,7 +378,7 @@ template<> mat3 mat3::rotate(float degrees, vec3 v)
return rotate(degrees, v.x, v.y, v.z);
}

template<> mat3::matrix(quat const &q)
template<> mat3::mat(quat const &q)
{
float n = norm(q);

@@ -405,7 +405,7 @@ template<> mat3::matrix(quat const &q)
(*this)[2][2] = 1.0f - s * (q.x * q.x + q.y * q.y);
}

template<> mat4::matrix(quat const &q)
template<> mat4::mat(quat const &q)
{
*this = mat4(mat3(q), 1.f);
}


読み込み中…
キャンセル
保存