From 4f28047fc468b70b2f12fb67cdeb55339a983530 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 3 Jul 2014 21:46:03 +0000 Subject: [PATCH] =?UTF-8?q?math:=20refactor=20more=20shit,=20I=20have=20no?= =?UTF-8?q?=20idea=20what=20I=E2=80=99m=20doing.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lol/base/types.h | 53 +- src/lol/math/geometry.h | 32 +- src/lol/math/matrix.h | 396 +++++----- src/lol/math/transform.h | 367 ++++----- src/lol/math/vector.h | 1349 +++++++++++++++++----------------- src/math/constants.cpp | 48 +- src/math/vector.cpp | 8 +- test/physics/easyphysics.cpp | 2 +- 8 files changed, 1137 insertions(+), 1118 deletions(-) diff --git a/src/lol/base/types.h b/src/lol/base/types.h index aa44589d..5ecaa4a0 100644 --- a/src/lol/base/types.h +++ b/src/lol/base/types.h @@ -16,10 +16,7 @@ namespace lol { -/* There are many reasons for wanting single-word type names, the most - * important one being compilation speedups in our vector.h: we can hide - * some global methods in namespaces that contain the name of the type, - * but namespaces cannot have spaces in their names. */ +/* It’s nice to have single-word type names, so define this. */ typedef long double ldouble; /* The “real” type used for real numbers. It’s a specialisation of the @@ -31,22 +28,23 @@ typedef Real<16> real; class half; /* - * Forward declaration of vec and matrix + * Forward declaration of vec_t, mat_t, cmplx_t, quat_t */ int const FULL_SWIZZLE = 0xaaaa; int const NO_SWIZZLE = 0xbbbb; -template struct vec; -template struct mat; -template struct Cmplx; -template struct Quat; +template struct vec_t; +template struct mat_t; +template struct cmplx_t; +template struct quat_t; +template struct dualquat_t; /* * Generic GLSL-like type names */ -#define LOL_VECTOR_TYPEDEFS(tleft, tright, suffix) \ +#define _T(tleft, tright, suffix) \ typedef tleft half tright f16##suffix; \ typedef tleft float tright suffix; \ typedef tleft double tright d##suffix; \ @@ -62,28 +60,29 @@ template struct Quat; typedef tleft real tright r##suffix; /* Idiotic hack to put "," inside a macro argument */ -#define COMMA , +#define _C , -LOL_VECTOR_TYPEDEFS(vec<2 COMMA, >, vec2) -LOL_VECTOR_TYPEDEFS(vec<3 COMMA, >, vec3) -LOL_VECTOR_TYPEDEFS(vec<4 COMMA, >, vec4) +_T(vec_t<, _C 2>, vec2) +_T(vec_t<, _C 3>, vec3) +_T(vec_t<, _C 4>, vec4) -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) +_T(mat_t<, _C 2 _C 2>, mat2) +_T(mat_t<, _C 3 _C 3>, mat3) +_T(mat_t<, _C 4 _C 4>, mat4) -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) +_T(mat_t<, _C 2 _C 3>, mat2x3) +_T(mat_t<, _C 2 _C 4>, mat2x4) +_T(mat_t<, _C 3 _C 2>, mat3x2) +_T(mat_t<, _C 3 _C 4>, mat3x4) +_T(mat_t<, _C 4 _C 2>, mat4x2) +_T(mat_t<, _C 4 _C 3>, mat4x3) -LOL_VECTOR_TYPEDEFS(Cmplx<, >, cmplx) -LOL_VECTOR_TYPEDEFS(Quat<, >, quat) +_T(cmplx_t<, >, cmplx) +_T(quat_t<, >, quat) +_T(dualquat_t<, >, dualquat) -#undef COMMA -#undef LOL_VECTOR_TYPEDEFS +#undef _C +#undef _T /* * HLSL/Cg-compliant type names diff --git a/src/lol/math/geometry.h b/src/lol/math/geometry.h index 4c217baf..159379ef 100644 --- a/src/lol/math/geometry.h +++ b/src/lol/math/geometry.h @@ -49,7 +49,7 @@ template struct Box2 B(T(0)) {} - inline Box2(vec<2,T> const &a, vec<2,T> const &b) + inline Box2(vec_t const &a, vec_t const &b) : A(a), B(b) {} @@ -59,32 +59,32 @@ template struct Box2 B(bx, by) {} - Box2 operator +(vec<2,T> const &v) const + Box2 operator +(vec_t const &v) const { return Box2(A + v, B + v); } - Box2 &operator +=(vec<2,T> const &v) + Box2 &operator +=(vec_t const &v) { return *this = *this + v; } - Box2 operator -(vec<2,T> const &v) const + Box2 operator -(vec_t const &v) const { return Box2(A - v, B - v); } - Box2 &operator -=(vec<2,T> const &v) + Box2 &operator -=(vec_t const &v) { return *this = *this - v; } - Box2 operator *(vec<2,T> const &v) const + Box2 operator *(vec_t const &v) const { return Box2(A * v, B * v); } - Box2 &operator *=(vec<2,T> const &v) + Box2 &operator *=(vec_t const &v) { return *this = *this * v; } @@ -99,7 +99,7 @@ template struct Box2 return A != box.A || B != box.B; } - vec<2,T> A, B; + vec_t A, B; }; /* @@ -113,7 +113,7 @@ template struct Box3 B(T(0)) {} - inline Box3(vec<3,T> const &a, vec<3,T> const &b) + inline Box3(vec_t const &a, vec_t const &b) : A(a), B(b) {} @@ -124,32 +124,32 @@ template struct Box3 B(bx, by, bz) {} - Box3 operator +(vec<3,T> const &v) const + Box3 operator +(vec_t const &v) const { return Box3(A + v, B + v); } - Box3 &operator +=(vec<3,T> const &v) + Box3 &operator +=(vec_t const &v) { return *this = *this + v; } - Box3 operator -(vec<3,T> const &v) const + Box3 operator -(vec_t const &v) const { return Box3(A - v, B - v); } - Box3 &operator -=(vec<3,T> const &v) + Box3 &operator -=(vec_t const &v) { return *this = *this - v; } - Box3 operator *(vec<3,T> const &v) const + Box3 operator *(vec_t const &v) const { return Box3(A * v, B * v); } - Box3 &operator *=(vec<3,T> const &v) + Box3 &operator *=(vec_t const &v) { return *this = *this * v; } @@ -164,7 +164,7 @@ template struct Box3 return A != box.A || B != box.B; } - vec<3,T> A, B; + vec_t A, B; }; /* diff --git a/src/lol/math/matrix.h b/src/lol/math/matrix.h index cc650f76..678578c0 100644 --- a/src/lol/math/matrix.h +++ b/src/lol/math/matrix.h @@ -29,17 +29,17 @@ namespace lol #endif /* - * The generic "matrix" type, which is fixed-size + * The generic “mat_t” type, which is fixed-size */ -template -struct mat +template +struct mat_t { - typedef mat type; + typedef mat_t type; - inline mat() {} + inline mat_t() {} - explicit inline mat(T const &val) + explicit inline mat_t(T const &val) { T const zero = T(0); for (int i = 0; i < COLS; ++i) @@ -47,11 +47,11 @@ struct mat m_data[i][j] = i == j ? val : zero; } - inline vec& operator[](size_t n) { return m_data[n]; } - inline vec const& operator[](size_t n) const { return m_data[n]; } + inline vec_t& operator[](size_t n) { return m_data[n]; } + inline vec_t const& operator[](size_t n) const { return m_data[n]; } private: - vec m_data[COLS]; + vec_t m_data[COLS]; }; /* @@ -59,28 +59,28 @@ private: */ template -struct mat<2, 2, T> +struct mat_t { - typedef mat<2,2,T> type; + typedef mat_t type; - inline mat() {} - inline mat(vec<2,T> v0, vec<2,T> v1) + inline mat_t() {} + inline mat_t(vec_t v0, vec_t v1) #if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS : m_data{ v0, v1 } {} #else : m_v0(v0), m_v1(v1) {} #endif - explicit inline mat(T const &val) + explicit inline mat_t(T const &val) #if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS - : m_data{ vec<2,T>(val, T(0)), - vec<2,T>(T(0), val) } {} + : m_data{ vec_t(val, T(0)), + vec_t(T(0), val) } {} #else : m_v0(val, T(0)), m_v1(T(0), val) {} #endif - explicit inline mat(mat<4,4,T> const &m) + explicit inline mat_t(mat_t const &m) #if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS : m_data{ m[0].xy, m[1].xy } {} #else @@ -88,16 +88,16 @@ struct mat<2, 2, T> #endif #if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS - inline vec<2,T>& operator[](size_t n) { return m_data[n]; } - inline vec<2,T> const& operator[](size_t n) const { return m_data[n]; } + inline vec_t& operator[](size_t n) { return m_data[n]; } + inline vec_t const& operator[](size_t n) const { return m_data[n]; } #else - inline vec<2,T>& operator[](size_t n) { return (&m_v0)[n]; } - inline vec<2,T> const& operator[](size_t n) const { return (&m_v0)[n]; } + inline vec_t& operator[](size_t n) { return (&m_v0)[n]; } + inline vec_t const& operator[](size_t n) const { return (&m_v0)[n]; } #endif /* Helpers for transformation matrices */ - static mat<2,2,T> rotate(T degrees); - static inline mat<2,2,T> rotate(mat<2,2,T> m, T degrees) + static mat_t rotate(T degrees); + static inline mat_t rotate(mat_t m, T degrees) { return rotate(degrees) * m; } @@ -107,15 +107,15 @@ struct mat<2, 2, T> template friend std::ostream &operator<<(std::ostream &stream, - mat<2,2,U> const &m); + mat_t const &m); - static const mat<2,2,T> identity; + static const mat_t identity; private: #if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS - vec<2,T> m_data[2]; + vec_t m_data[2]; #else - vec<2,T> m_v0, m_v1; + vec_t m_v0, m_v1; #endif }; @@ -124,91 +124,91 @@ private: */ template -struct mat<3,3,T> +struct mat_t { - typedef mat<3,3,T> type; + typedef mat_t type; - inline mat() {} - inline mat(vec<3,T> v0, vec<3,T> v1, vec<3,T> v2) + inline mat_t() {} + inline mat_t(vec_t v0, vec_t v1, vec_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 mat(T const &val) + explicit inline mat_t(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), - vec<3,T>((T)0, (T)0, val) } {} + : m_data{ vec_t(val, (T)0, (T)0), + vec_t((T)0, val, (T)0), + vec_t((T)0, (T)0, val) } {} #else : m_v0(val, (T)0, (T)0), m_v1((T)0, val, (T)0), m_v2((T)0, (T)0, val) {} #endif - explicit inline mat(mat<2,2,T> m, T const &val = T(1)) + explicit inline mat_t(mat_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), - vec<3,T>((T)0, (T)0, val) } {} + : m_data{ vec_t(m[0], (T)0), + vec_t(m[1], (T)0), + vec_t((T)0, (T)0, val) } {} #else : m_v0(m[0], (T)0), m_v1(m[1], (T)0), m_v2((T)0, (T)0, val) {} #endif - explicit inline mat(mat<4,4,T> const &m) + explicit inline mat_t(mat_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 mat(Quat const &q); + explicit mat_t(quat_t const &q); #if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS - inline vec<3,T>& operator[](size_t n) { return m_data[n]; } - inline vec<3,T> const& operator[](size_t n) const { return m_data[n]; } + inline vec_t& operator[](size_t n) { return m_data[n]; } + inline vec_t const& operator[](size_t n) const { return m_data[n]; } #else - inline vec<3,T>& operator[](size_t n) { return (&m_v0)[n]; } - inline vec<3,T> const& operator[](size_t n) const { return (&m_v0)[n]; } + inline vec_t& operator[](size_t n) { return (&m_v0)[n]; } + inline vec_t const& operator[](size_t n) const { return (&m_v0)[n]; } #endif /* Helpers for transformation matrices */ - 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) + static mat_t scale(T x); + static mat_t scale(T x, T y, T z); + static mat_t scale(vec_t v); + static mat_t rotate(T degrees, T x, T y, T z); + static mat_t rotate(T degrees, vec_t v); + + static mat_t fromeuler_xyz(vec_t const &v); + static mat_t fromeuler_xzy(vec_t const &v); + static mat_t fromeuler_yxz(vec_t const &v); + static mat_t fromeuler_yzx(vec_t const &v); + static mat_t fromeuler_zxy(vec_t const &v); + static mat_t fromeuler_zyx(vec_t const &v); + static mat_t fromeuler_xyz(T phi, T theta, T psi); + static mat_t fromeuler_xzy(T phi, T theta, T psi); + static mat_t fromeuler_yxz(T phi, T theta, T psi); + static mat_t fromeuler_yzx(T phi, T theta, T psi); + static mat_t fromeuler_zxy(T phi, T theta, T psi); + static mat_t fromeuler_zyx(T phi, T theta, T psi); + + static mat_t fromeuler_xyx(vec_t const &v); + static mat_t fromeuler_xzx(vec_t const &v); + static mat_t fromeuler_yxy(vec_t const &v); + static mat_t fromeuler_yzy(vec_t const &v); + static mat_t fromeuler_zxz(vec_t const &v); + static mat_t fromeuler_zyz(vec_t const &v); + static mat_t fromeuler_xyx(T phi, T theta, T psi); + static mat_t fromeuler_xzx(T phi, T theta, T psi); + static mat_t fromeuler_yxy(T phi, T theta, T psi); + static mat_t fromeuler_yzy(T phi, T theta, T psi); + static mat_t fromeuler_zxz(T phi, T theta, T psi); + static mat_t fromeuler_zyz(T phi, T theta, T psi); + + static inline mat_t rotate(mat_t m, T degrees, vec_t v) { return rotate(degrees, v) * m; } @@ -218,15 +218,15 @@ struct mat<3,3,T> template friend std::ostream &operator<<(std::ostream &stream, - mat<3,3,U> const &m); + mat_t const &m); - static const mat<3,3,T> identity; + static const mat_t identity; private: #if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS - vec<3,T> m_data[3]; + vec_t m_data[3]; #else - vec<3,T> m_v0, m_v1, m_v2; + vec_t m_v0, m_v1, m_v2; #endif }; @@ -235,24 +235,24 @@ private: */ template -struct mat<4, 4, T> +struct mat_t { - typedef mat<4,4,T> type; + typedef mat_t type; - inline mat() {} - inline mat(vec<4,T> v0, vec<4,T> v1, vec<4,T> v2, vec<4,T> v3) + inline mat_t() {} + inline mat_t(vec_t v0, vec_t v1, vec_t v2, vec_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 mat(T const &val) + explicit inline mat_t(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), - vec<4,T>((T)0, (T)0, val, (T)0), - vec<4,T>((T)0, (T)0, (T)0, val) } {} + : m_data{ vec_t(val, (T)0, (T)0, (T)0), + vec_t((T)0, val, (T)0, (T)0), + vec_t((T)0, (T)0, val, (T)0), + vec_t((T)0, (T)0, (T)0, val) } {} #else : m_v0(val, (T)0, (T)0, (T)0), m_v1((T)0, val, (T)0, (T)0), @@ -260,12 +260,12 @@ struct mat<4, 4, T> m_v3((T)0, (T)0, (T)0, val) {} #endif - explicit inline mat(mat<2,2,T> m, T const &val = T(1)) + explicit inline mat_t(mat_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), - vec<4,T>((T)0, (T)0, val, (T)0), - vec<4,T>((T)0, (T)0, (T)0, val) } {} + : m_data{ vec_t(m[0], (T)0, (T)0), + vec_t(m[1], (T)0, (T)0), + vec_t((T)0, (T)0, val, (T)0), + vec_t((T)0, (T)0, (T)0, val) } {} #else : m_v0(m[0], (T)0, (T)0), m_v1(m[1], (T)0, (T)0), @@ -273,12 +273,12 @@ struct mat<4, 4, T> m_v3((T)0, (T)0, (T)0, val) {} #endif - explicit inline mat(mat<3,3,T> m, T const &val = T(1)) + explicit inline mat_t(mat_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), - vec<4,T>(m[2], (T)0), - vec<4,T>((T)0, (T)0, (T)0, val) } {} + : m_data{ vec_t(m[0], (T)0), + vec_t(m[1], (T)0), + vec_t(m[2], (T)0), + vec_t((T)0, (T)0, (T)0, val) } {} #else : m_v0(m[0], (T)0), m_v1(m[1], (T)0), @@ -286,120 +286,120 @@ struct mat<4, 4, T> m_v3((T)0, (T)0, (T)0, val) {} #endif - explicit mat(Quat const &q); + explicit mat_t(quat_t const &q); #if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS - inline vec<4,T>& operator[](size_t n) { return m_data[n]; } - inline vec<4,T> const& operator[](size_t n) const { return m_data[n]; } + inline vec_t& operator[](size_t n) { return m_data[n]; } + inline vec_t const& operator[](size_t n) const { return m_data[n]; } #else - inline vec<4,T>& operator[](size_t n) { return (&m_v0)[n]; } - inline vec<4,T> const& operator[](size_t n) const { return (&m_v0)[n]; } + inline vec_t& operator[](size_t n) { return (&m_v0)[n]; } + inline vec_t const& operator[](size_t n) const { return (&m_v0)[n]; } #endif /* Helpers for transformation matrices */ - static mat<4,4,T> translate(T x, T y, T z); - static mat<4,4,T> translate(vec<3,T> v); + static mat_t translate(T x, T y, T z); + static mat_t translate(vec_t v); - static inline mat<4,4,T> scale(T x) + static inline mat_t scale(T x) { - return mat<4,4,T>(mat<3,3,T>::scale(x), (T)1); + return mat_t(mat_t::scale(x), (T)1); } - static inline mat<4,4,T> scale(T x, T y, T z) + static inline mat_t scale(T x, T y, T z) { - return mat<4,4,T>(mat<3,3,T>::scale(x, y, z), (T)1); + return mat_t(mat_t::scale(x, y, z), (T)1); } - static inline mat<4,4,T> scale(vec<3,T> v) + static inline mat_t scale(vec_t v) { - return mat<4,4,T>(mat<3,3,T>::scale(v), (T)1); + return mat_t(mat_t::scale(v), (T)1); } - static inline mat<4,4,T> translate(mat<4,4,T> const &m, vec<3,T> v) + static inline mat_t translate(mat_t const &m, vec_t v) { return translate(v) * m; } - static inline mat<4,4,T> rotate(T degrees, T x, T y, T z) + static inline mat_t rotate(T degrees, T x, T y, T z) { - return mat<4,4,T>(mat<3,3,T>::rotate(degrees, x, y, z), (T)1); + return mat_t(mat_t::rotate(degrees, x, y, z), (T)1); } - static inline mat<4,4,T> rotate(T degrees, vec<3,T> v) + static inline mat_t rotate(T degrees, vec_t v) { - return mat<4,4,T>(mat<3,3,T>::rotate(degrees, v), (T)1); + return mat_t(mat_t::rotate(degrees, v), (T)1); } - static inline mat<4,4,T> rotate(mat<4,4,T> &m, T degrees, vec<3,T> v) + static inline mat_t rotate(mat_t &m, T degrees, vec_t v) { return rotate(degrees, v) * m; } - 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); + static mat_t fromeuler_xyz(vec_t const &v); + static mat_t fromeuler_xzy(vec_t const &v); + static mat_t fromeuler_yxz(vec_t const &v); + static mat_t fromeuler_yzx(vec_t const &v); + static mat_t fromeuler_zxy(vec_t const &v); + static mat_t fromeuler_zyx(vec_t const &v); + static mat_t fromeuler_xyz(T phi, T theta, T psi); + static mat_t fromeuler_xzy(T phi, T theta, T psi); + static mat_t fromeuler_yxz(T phi, T theta, T psi); + static mat_t fromeuler_yzx(T phi, T theta, T psi); + static mat_t fromeuler_zxy(T phi, T theta, T psi); + static mat_t fromeuler_zyx(T phi, T theta, T psi); + + static mat_t fromeuler_xyx(vec_t const &v); + static mat_t fromeuler_xzx(vec_t const &v); + static mat_t fromeuler_yxy(vec_t const &v); + static mat_t fromeuler_yzy(vec_t const &v); + static mat_t fromeuler_zxz(vec_t const &v); + static mat_t fromeuler_zyz(vec_t const &v); + static mat_t fromeuler_xyx(T phi, T theta, T psi); + static mat_t fromeuler_xzx(T phi, T theta, T psi); + static mat_t fromeuler_yxy(T phi, T theta, T psi); + static mat_t fromeuler_yzy(T phi, T theta, T psi); + static mat_t fromeuler_zxz(T phi, T theta, T psi); + static mat_t fromeuler_zyz(T phi, T theta, T psi); /* Helpers for view matrices */ - static mat<4,4,T> lookat(vec<3,T> eye, vec<3,T> center, vec<3,T> up); + static mat_t lookat(vec_t eye, vec_t center, vec_t up); /* Helpers for projection matrices */ - 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); + static mat_t ortho(T left, T right, T bottom, T top, T near, T far); + static mat_t ortho(T width, T height, T near, T far); + static mat_t frustum(T left, T right, T bottom, T top, T near, T far); + static mat_t perspective(T fov_y, T width, T height, T near, T far); + static mat_t shifted_perspective(T fov_y, T screen_size, T screen_ratio_yx, T near, T far); void printf() const; String tostring() const; template friend std::ostream &operator<<(std::ostream &stream, - mat<4,4,U> const &m); + mat_t const &m); - static const mat<4,4,T> identity; + static const mat_t identity; private: #if LOL_FEATURE_CXX11_ARRAY_INITIALIZERS - vec<4,T> m_data[4]; + vec_t m_data[4]; #else - vec<4,T> m_v0, m_v1, m_v2, m_v3; + vec_t m_v0, m_v1, m_v2, m_v3; #endif }; -template T determinant(mat<2,2,T> const &); -template T determinant(mat<3,3,T> const &); -template T determinant(mat<4,4,T> const &); +template T determinant(mat_t const &); +template T determinant(mat_t const &); +template T determinant(mat_t const &); -template mat<2,2,T> inverse(mat<2,2,T> const &); -template mat<3,3,T> inverse(mat<3,3,T> const &); -template mat<4,4,T> inverse(mat<4,4,T> const &); +template mat_t inverse(mat_t const &); +template mat_t inverse(mat_t const &); +template mat_t inverse(mat_t const &); -template -static inline mat transpose(mat const &m) +template +static inline mat_t transpose(mat_t const &m) { - mat ret; + mat_t ret; for (int i = 0; i < COLS; ++i) for (int j = 0; j < ROWS; ++j) ret[j][i] = m[i][j]; @@ -410,50 +410,50 @@ static inline mat transpose(mat const &m) * Addition/subtraction/unary */ -template -static inline mat &operator +=(mat &a, - mat const &b) +template +static inline mat_t &operator +=(mat_t &a, + mat_t const &b) { for (int i = 0; i < COLS; ++i) a[i] += b[i]; return a; } -template -static inline mat operator +(mat const &a, - mat const &b) +template +static inline mat_t operator +(mat_t const &a, + mat_t const &b) { - mat ret = a; + mat_t ret = a; return ret += b; } -template -static inline mat operator +(mat const &m) +template +static inline mat_t operator +(mat_t const &m) { return m; } -template -static inline mat &operator -=(mat &a, - mat const &b) +template +static inline mat_t &operator -=(mat_t &a, + mat_t const &b) { for (int i = 0; i < COLS; ++i) a[i] -= b[i]; return a; } -template -static inline mat operator -(mat const &a, - mat const &b) +template +static inline mat_t operator -(mat_t const &a, + mat_t const &b) { - mat ret = a; + mat_t ret = a; return ret -= b; } -template -static inline mat operator -(mat const &m) +template +static inline mat_t operator -(mat_t const &m) { - mat ret; + mat_t ret; for (int i = 0; i < COLS; ++i) ret[i] = -m[i]; return ret; @@ -463,21 +463,21 @@ static inline mat operator -(mat const &m) * Matrix-vector and vector-matrix multiplication */ -template -static inline vec operator *(mat const &m, - vec const &v) +template +static inline vec_t operator *(mat_t const &m, + vec_t const &v) { - vec ret(T(0)); + vec_t ret(T(0)); for (int i = 0; i < COLS; ++i) ret += m[i] * v[i]; return ret; } -template -static inline vec operator *(vec const &v, - mat const &m) +template +static inline vec_t operator *(vec_t const &v, + mat_t const &m) { - vec ret(T(0)); + vec_t ret(T(0)); for (int i = 0; i < COLS; ++i) ret[i] = dot(v, m[i]); return ret; @@ -487,19 +487,19 @@ static inline vec operator *(vec const &v, * Matrix-matrix multiplication */ -template -static inline mat operator *(mat const &a, - mat const &b) +template +static inline mat_t operator *(mat_t const &a, + mat_t const &b) { - mat ret; + mat_t ret; for (int i = 0; i < COLS; ++i) ret[i] = a * b[i]; return ret; } -template -static inline mat &operator *=(mat &a, - mat const &b) +template +static inline mat_t &operator *=(mat_t &a, + mat_t const &b) { return a = a * b; } diff --git a/src/lol/math/transform.h b/src/lol/math/transform.h index 45136ef9..5a7a0708 100644 --- a/src/lol/math/transform.h +++ b/src/lol/math/transform.h @@ -9,8 +9,8 @@ // // -// The complex and quaternion classes -// ---------------------------------- +// The complex, quaternion and dual quaternion classes +// --------------------------------------------------- // #if !defined __LOL_MATH_TRANSFORM_H__ @@ -18,9 +18,6 @@ #include -#include -#include - namespace lol { @@ -29,162 +26,114 @@ namespace lol #endif /* - * 2-element complexes + * 2-element transforms: complex numbers */ -template struct Cmplx +template +struct cmplx_t { - typedef Cmplx type; + typedef cmplx_t type; - inline constexpr Cmplx() {} - inline constexpr Cmplx(T X) : x(X), y(T(0)) {} - inline constexpr Cmplx(T X, T Y) : x(X), y(Y) {} + inline constexpr cmplx_t() {} + inline constexpr cmplx_t(T X) : x(X), y(T(0)) {} + inline constexpr cmplx_t(T X, T Y) : x(X), y(Y) {} template - explicit inline constexpr Cmplx(Cmplx const &z) + explicit inline constexpr cmplx_t(cmplx_t const &z) : x(z.x), y(z.y) {} LOL_COMMON_MEMBER_OPS(x) LOL_NONVECTOR_MEMBER_OPS() - inline Cmplx operator *(Cmplx const &val) const + inline cmplx_t operator *(cmplx_t const &val) const { - return Cmplx(x * val.x - y * val.y, x * val.y + y * val.x); + return cmplx_t(x * val.x - y * val.y, x * val.y + y * val.x); } - inline Cmplx operator *=(Cmplx const &val) + inline cmplx_t operator *=(cmplx_t const &val) { return *this = (*this) * val; } - inline Cmplx operator ~() const + inline cmplx_t operator ~() const { - return Cmplx(x, -y); + return cmplx_t(x, -y); } template - friend std::ostream &operator<<(std::ostream &stream, Cmplx const &v); + friend std::ostream &operator<<(std::ostream &stream, cmplx_t const &v); T x, y; }; -template -static inline T dot(Cmplx const &z1, Cmplx const &z2) -{ - T ret(0); - for (size_t i = 0; i < sizeof(Cmplx) / sizeof(T); ++i) - ret += z1[i] * z2[i]; - return ret; -} - -template -static inline T sqlength(Cmplx const &z) -{ - return dot(z, z); -} - -template -static inline T length(Cmplx const &z) -{ - /* FIXME: this is not very nice */ - return (T)sqrt((double)sqlength(z)); -} - -template -static inline T norm(Cmplx const &z) -{ - return length(z); -} - -template -static inline Cmplx re(Cmplx const &z) -{ - return ~z / sqlength(z); -} - -template -static inline Cmplx normalize(Cmplx const &z) -{ - T norm = (T)length(z); - return norm ? z / norm : Cmplx(T(0)); -} - -template -static inline Cmplx operator /(T a, Cmplx const &b) -{ - return a * re(b); -} - -template -static inline Cmplx operator /(Cmplx a, Cmplx const &b) -{ - return a * re(b); -} - -template -static inline bool operator ==(Cmplx const &a, T b) -{ - return (a.x == b) && !a.y; -} - -template -static inline bool operator !=(Cmplx const &a, T b) -{ - return (a.x != b) || a.y; -} - -template -static inline bool operator ==(T a, Cmplx const &b) { return b == a; } - -template -static inline bool operator !=(T a, Cmplx const &b) { return b != a; } - /* - * 4-element quaternions + * 4-element transforms: quaternions */ -template struct Quat +template +struct quat_t { - typedef Quat type; + typedef quat_t type; - inline constexpr Quat() {} - inline constexpr Quat(T W) : w(W), x(0), y(0), z(0) {} - inline constexpr Quat(T W, T X, T Y, T Z) : w(W), x(X), y(Y), z(Z) {} + /* Default constructor and copy constructor */ + inline constexpr quat_t() : w(), x(), y(), z() {} + inline constexpr quat_t(quat_t const &q) + : w(q.w), x(q.x), y(q.y), z(q.z) {} + /* Explicit constructor for type conversion */ template - explicit inline constexpr Quat(Quat const &q) + explicit inline constexpr quat_t(quat_t const &q) : w(q.w), x(q.x), y(q.y), z(q.z) {} - Quat(mat<3,3,T> const &m); - Quat(mat<4,4,T> const &m); + /* Various explicit constructors */ + explicit inline constexpr quat_t(T W, T X, T Y, T Z) + : w(W), x(X), y(Y), z(Z) {} + explicit inline constexpr quat_t(T W) + : w(W), x(0), y(0), z(0) {} + + explicit quat_t(mat_t const &m); + explicit quat_t(mat_t const &m); LOL_COMMON_MEMBER_OPS(w) LOL_NONVECTOR_MEMBER_OPS() + inline quat_t operator *(quat_t const &val) const + { + vec_t v1(x, y, z); + vec_t v2(val.x, val.y, val.z); + vec_t v3 = cross(v1, v2) + w * v2 + val.w * v1; + return quat_t(w * val.w - dot(v1, v2), v3.x, v3.y, v3.z); + } + + inline quat_t operator *=(quat_t const &val) + { + return *this = (*this * val); + } + /* Create a unit quaternion representing a rotation around an axis. */ - static Quat rotate(T degrees, T x, T y, T z); - static Quat rotate(T degrees, vec<3,T> const &v); + static quat_t rotate(T degrees, T x, T y, T z); + static quat_t rotate(T degrees, vec_t const &v); /* Create a unit quaternion representing a rotation between two vectors. * Input vectors need not be normalised. */ - static Quat rotate(vec<3,T> const &src, vec<3,T> const &dst); + static quat_t rotate(vec_t const &src, vec_t const &dst); /* Convert from Euler angles. The axes in fromeuler_xyx are * x, then y', then x", ie. the axes are attached to the model. * If you want to rotate around static axes, just reverse the order * of the arguments. Angle values are in degrees. */ - static Quat fromeuler_xyx(vec<3,T> const &v); - static Quat fromeuler_xzx(vec<3,T> const &v); - static Quat fromeuler_yxy(vec<3,T> const &v); - static Quat fromeuler_yzy(vec<3,T> const &v); - static Quat fromeuler_zxz(vec<3,T> const &v); - static Quat fromeuler_zyz(vec<3,T> const &v); - static Quat fromeuler_xyx(T phi, T theta, T psi); - static Quat fromeuler_xzx(T phi, T theta, T psi); - static Quat fromeuler_yxy(T phi, T theta, T psi); - static Quat fromeuler_yzy(T phi, T theta, T psi); - static Quat fromeuler_zxz(T phi, T theta, T psi); - static Quat fromeuler_zyz(T phi, T theta, T psi); + static quat_t fromeuler_xyx(vec_t const &v); + static quat_t fromeuler_xzx(vec_t const &v); + static quat_t fromeuler_yxy(vec_t const &v); + static quat_t fromeuler_yzy(vec_t const &v); + static quat_t fromeuler_zxz(vec_t const &v); + static quat_t fromeuler_zyz(vec_t const &v); + static quat_t fromeuler_xyx(T phi, T theta, T psi); + static quat_t fromeuler_xzx(T phi, T theta, T psi); + static quat_t fromeuler_yxy(T phi, T theta, T psi); + static quat_t fromeuler_yzy(T phi, T theta, T psi); + static quat_t fromeuler_zxz(T phi, T theta, T psi); + static quat_t fromeuler_zyz(T phi, T theta, T psi); /* Convert from Tait-Bryan angles (incorrectly called Euler angles, * but since everyone does it…). The axes in fromeuler_xyz are @@ -194,67 +143,60 @@ template struct Quat * If you want to rotate around static axes, reverse the order in * the function name (_zyx instead of _xyz) AND reverse the order * of the arguments. */ - static Quat fromeuler_xyz(vec<3,T> const &v); - static Quat fromeuler_xzy(vec<3,T> const &v); - static Quat fromeuler_yxz(vec<3,T> const &v); - static Quat fromeuler_yzx(vec<3,T> const &v); - static Quat fromeuler_zxy(vec<3,T> const &v); - static Quat fromeuler_zyx(vec<3,T> const &v); - static Quat fromeuler_xyz(T phi, T theta, T psi); - static Quat fromeuler_xzy(T phi, T theta, T psi); - static Quat fromeuler_yxz(T phi, T theta, T psi); - static Quat fromeuler_yzx(T phi, T theta, T psi); - static Quat fromeuler_zxy(T phi, T theta, T psi); - static Quat fromeuler_zyx(T phi, T theta, T psi); - - inline Quat operator *(Quat const &val) const; - - inline Quat operator *=(Quat const &val) - { - return *this = (*this) * val; - } - - inline Quat operator ~() const + static quat_t fromeuler_xyz(vec_t const &v); + static quat_t fromeuler_xzy(vec_t const &v); + static quat_t fromeuler_yxz(vec_t const &v); + static quat_t fromeuler_yzx(vec_t const &v); + static quat_t fromeuler_zxy(vec_t const &v); + static quat_t fromeuler_zyx(vec_t const &v); + static quat_t fromeuler_xyz(T phi, T theta, T psi); + static quat_t fromeuler_xzy(T phi, T theta, T psi); + static quat_t fromeuler_yxz(T phi, T theta, T psi); + static quat_t fromeuler_yzx(T phi, T theta, T psi); + static quat_t fromeuler_zxy(T phi, T theta, T psi); + static quat_t fromeuler_zyx(T phi, T theta, T psi); + + inline quat_t operator ~() const { - return Quat(w, -x, -y, -z); + return quat_t(w, -x, -y, -z); } - inline vec<3,T> transform(vec<3,T> const &v) const + inline vec_t transform(vec_t const &v) const { - Quat p = Quat(0, v.x, v.y, v.z); - Quat q = *this * p / *this; - return vec<3,T>(q.x, q.y, q.z); + quat_t p = quat_t(0, v.x, v.y, v.z); + quat_t q = *this * p / *this; + return vec_t(q.x, q.y, q.z); } - inline vec<4,T> transform(vec<4,T> const &v) const + inline vec_t transform(vec_t const &v) const { - Quat p = Quat(0, v.x, v.y, v.z); - Quat q = *this * p / *this; - return vec<4,T>(q.x, q.y, q.z, v.w); + quat_t p = quat_t(0, v.x, v.y, v.z); + quat_t q = *this * p / *this; + return vec_t(q.x, q.y, q.z, v.w); } - inline vec<3,T> operator *(vec<3,T> const &v) const + inline vec_t operator *(vec_t const &v) const { return transform(v); } - inline vec<4,T> operator *(vec<4,T> const &v) const + inline vec_t operator *(vec_t const &v) const { return transform(v); } - inline vec<3,T> axis() + inline vec_t axis() { - vec<3,T> v(x, y, z); + vec_t v(x, y, z); T n2 = sqlength(v); if (n2 <= (T)1e-6) - return vec<3,T>::axis_x; + return vec_t::axis_x; return normalize(v); } inline T angle() { - vec<3,T> v(x, y, z); + vec_t v(x, y, z); T n2 = sqlength(v); if (n2 <= (T)1e-6) return (T)0; @@ -262,78 +204,153 @@ template struct Quat } template - friend std::ostream &operator<<(std::ostream &stream, Quat const &v); + friend std::ostream &operator<<(std::ostream &stream, quat_t const &v); /* XXX: storage order is wxyz, unlike vectors! */ T w, x, y, z; }; +/* + * Common operations on transforms + */ + template -static inline T dot(Quat const &q1, Quat const &q2) +static inline T dot(cmplx_t const &t1, cmplx_t const &t2) { T ret(0); - for (size_t i = 0; i < sizeof(Quat) / sizeof(T); ++i) - ret += q1[i] * q2[i]; + for (size_t i = 0; i < sizeof(t1) / sizeof(T); ++i) + ret += t1[i] * t2[i]; return ret; } template -static inline T sqlength(Quat const &q) +static inline T sqlength(cmplx_t const &t) { - return dot(q, q); + return dot(t, t); } template -static inline T length(Quat const &q) +static inline T length(cmplx_t const &t) { /* FIXME: this is not very nice */ - return (T)sqrt((double)sqlength(q)); + return (T)sqrt((double)sqlength(t)); } template -static inline T norm(Quat const &q) +static inline T norm(cmplx_t const &t) { - return length(q); + return length(t); } template -static inline Quat re(Quat const &q) +static inline cmplx_t normalize(cmplx_t const &z) { - return ~q / sqlength(q); + T norm = (T)length(z); + return norm ? z / norm : cmplx_t(T(0)); } +/* XXX: duplicate */ + template -static inline Quat normalize(Quat const &q) +static inline T dot(quat_t const &t1, quat_t const &t2) { - T norm = (T)length(q); - return norm ? q / norm : Quat(T(0)); + T ret(0); + for (size_t i = 0; i < sizeof(t1) / sizeof(T); ++i) + ret += t1[i] * t2[i]; + return ret; } template -static inline Quat operator /(T x, Quat const &y) +static inline T sqlength(quat_t const &t) { - return x * re(y); + return dot(t, t); } template -static inline Quat operator /(Quat const &x, Quat const &y) +static inline T length(quat_t const &t) { - return x * re(y); + /* FIXME: this is not very nice */ + return (T)sqrt((double)sqlength(t)); +} + +template +static inline T norm(quat_t const &t) +{ + return length(t); +} + +template +static inline quat_t normalize(quat_t const &z) +{ + T norm = (T)length(z); + return norm ? z / norm : quat_t(T(0)); } +/* + * Complex numbers only + */ + template -extern Quat slerp(Quat const &qa, Quat const &qb, T f); +static inline cmplx_t re(cmplx_t const &z) +{ + return ~z / sqlength(z); +} + +template +static inline cmplx_t operator /(T a, cmplx_t const &b) +{ + return a * re(b); +} template -inline Quat Quat::operator *(Quat const &val) const +static inline cmplx_t operator /(cmplx_t a, cmplx_t const &b) { - Quat ret; - vec<3,T> v1(x, y, z); - vec<3,T> v2(val.x, val.y, val.z); - vec<3,T> v3 = cross(v1, v2) + w * v2 + val.w * v1; - return Quat(w * val.w - dot(v1, v2), v3.x, v3.y, v3.z); + return a * re(b); } +template +static inline bool operator ==(cmplx_t const &a, T b) +{ + return (a.x == b) && !a.y; +} + +template +static inline bool operator !=(cmplx_t const &a, T b) +{ + return (a.x != b) || a.y; +} + +template +static inline bool operator ==(T a, cmplx_t const &b) { return b == a; } + +template +static inline bool operator !=(T a, cmplx_t const &b) { return b != a; } + +/* + * Quaternions only + */ + +template +static inline quat_t re(quat_t const &q) +{ + return ~q / sqlength(q); +} + +template +static inline quat_t operator /(T x, quat_t const &y) +{ + return x * re(y); +} + +template +static inline quat_t operator /(quat_t const &x, quat_t const &y) +{ + return x * re(y); +} + +template +extern quat_t slerp(quat_t const &qa, quat_t const &qb, T f); + #if !LOL_FEATURE_CXX11_CONSTEXPR #undef constexpr #endif diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index a70609cd..96aa6e1b 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -48,18 +48,18 @@ namespace lol * fuck it. */ -template -struct vec +template +struct vec_t { - typedef vec type; + typedef vec_t type; - inline vec& operator =(vec that); + inline vec_t& operator =(vec_t that); #if LOL_FEATURE_CXX11_RELAXED_UNIONS - inline vec& operator =(vec const &that) + inline vec_t& operator =(vec_t const &that) { /* Pass by value in case this == &that */ - return *this = (vec)that; + return *this = (vec_t)that; } #endif @@ -76,12 +76,12 @@ struct vec } }; -/* The generic "vec" type, which is a fixed-size vector with no +/* The generic “vec_t” type, which is a fixed-size vector with no * swizzling. There's an override for N=2, N=3, N=4 that has swizzling. */ -template -struct vec +template +struct vec_t { - typedef vec type; + typedef vec_t type; inline T& operator[](size_t n) { return m_data[n]; } inline T const& operator[](size_t n) const { return m_data[n]; } @@ -148,8 +148,8 @@ private: void printf() const; \ String tostring() const; \ \ - /* vec -(vec) - * vec +(vec) */ \ + /* vec_t -(vec_t) + * vec_t +(vec_t) */ \ friend inline type operator -(type const &a) \ { \ type ret; \ @@ -163,50 +163,50 @@ private: return a; \ } \ \ - /* vec +(vec, vec) - * vec -(vec, vec) - * vec +=(vec, vec) - * vec -=(vec, vec) */ \ + /* vec_t +(vec_t, vec_t) + * vec_t -(vec_t, vec_t) + * vec_t +=(vec_t, vec_t) + * vec_t -=(vec_t, vec_t) */ \ LOL_V_VV_OP(+); \ LOL_V_VV_OP(-); \ LOL_V_VV_ASSIGN_OP(+); \ LOL_V_VV_ASSIGN_OP(-); \ \ - /* vec *(vec, scalar) - * vec /(vec, scalar) - * vec *=(vec, scalar) - * vec /=(vec, scalar) */ \ + /* vec_t *(vec_t, scalar) + * vec_t /(vec_t, scalar) + * vec_t *=(vec_t, scalar) + * vec_t /=(vec_t, scalar) */ \ LOL_V_VS_OP(*) \ LOL_V_VS_OP(/) \ LOL_V_VS_ASSIGN_OP(*) \ LOL_V_VS_ASSIGN_OP(/) \ \ - /* bool ==(vec, vec) - * bool !=(vec, vec) */ \ + /* bool ==(vec_t, vec_t) + * bool !=(vec_t, vec_t) */ \ LOL_B_VV_OP(==, ==, true) \ LOL_B_VV_OP(!=, ==, false) #define LOL_VECTOR_MEMBER_OPS() \ - /* vec *(vec, vec) - * vec /(vec, vec) - * vec *=(vec, vec) - * vec /=(vec, vec) */ \ + /* vec_t *(vec_t, vec_t) + * vec_t /(vec_t, vec_t) + * vec_t *=(vec_t, vec_t) + * vec_t /=(vec_t, vec_t) */ \ LOL_V_VV_OP(*); \ LOL_V_VV_OP(/); \ LOL_V_VV_ASSIGN_OP(*); \ LOL_V_VV_ASSIGN_OP(/); \ \ - /* bool >=(vec, vec) - * bool <=(vec, vec) - * bool >(vec, vec) - * bool <(vec, vec) */ \ + /* bool >=(vec_t, vec_t) + * bool <=(vec_t, vec_t) + * bool >(vec_t, vec_t) + * bool <(vec_t, vec_t) */ \ LOL_B_VV_OP(<=, <=, true) \ LOL_B_VV_OP(>=, >=, true) \ LOL_B_VV_OP(<, <, true) \ LOL_B_VV_OP(>, >, true) #define LOL_NONVECTOR_MEMBER_OPS() \ - /* vec *(scalar, vec) (no division, it works differently) */ \ + /* vec_t *(scalar, vec_t) (no division, it works differently) */ \ friend inline type operator *(T const &val, type const &a) \ { \ type ret; \ @@ -220,40 +220,40 @@ private: */ template -struct vec<2,T> +struct vec_t { - typedef vec<2,T> type; + typedef vec_t type; /* Default constructor, copy constructor, and destructor */ - inline constexpr vec() : x(), y() {} - inline constexpr vec(vec<2,T> const &v) : x(v.x), y(v.y) {} - inline ~vec() { x.~T(); y.~T(); } + inline constexpr vec_t() : x(), y() {} + inline constexpr vec_t(vec_t const &v) : x(v.x), y(v.y) {} + inline ~vec_t() { x.~T(); y.~T(); } /* Implicit constructor for swizzling */ template - inline constexpr vec(vec<2, T, SWIZZLE> const &v) + inline constexpr vec_t(vec_t const &v) : x(v[0]), y(v[1]) {} /* Explicit constructor for type conversion */ template - explicit inline constexpr vec(vec<2, U, SWIZZLE> const &v) + explicit inline constexpr vec_t(vec_t const &v) : x(v[0]), y(v[1]) {} /* Various explicit constructors */ - explicit inline constexpr vec(T X, T Y) + explicit inline constexpr vec_t(T X, T Y) : x(X), y(Y) {} - explicit inline constexpr vec(T X) + explicit inline constexpr vec_t(T X) : x(X), y(X) {} LOL_COMMON_MEMBER_OPS(x) LOL_VECTOR_MEMBER_OPS() - static const vec<2,T> zero; - static const vec<2,T> axis_x; - static const vec<2,T> axis_y; + static const vec_t zero; + static const vec_t axis_x; + static const vec_t axis_y; template - friend std::ostream &operator<<(std::ostream &stream, vec<2,U> const &v); + friend std::ostream &operator<<(std::ostream &stream, vec_t const &v); union { @@ -262,36 +262,36 @@ struct vec<2,T> struct { T s, t; }; #if !_DOXYGEN_SKIP_ME - vec<2,T,0x00> const xx, rr, ss; - vec<2,T,0x01> _____ xy, rg, st; - vec<2,T,0x10> _____ yx, gr, ts; - vec<2,T,0x11> const yy, gg, tt; - - vec<3,T,0x000> const xxx, rrr, sss; - vec<3,T,0x001> const xxy, rrg, sst; - vec<3,T,0x010> const xyx, rgr, sts; - vec<3,T,0x011> const xyy, rgg, stt; - vec<3,T,0x100> const yxx, grr, tss; - vec<3,T,0x101> const yxy, grg, tst; - vec<3,T,0x110> const yyx, ggr, tts; - vec<3,T,0x111> const yyy, ggg, ttt; - - vec<4,T,0x0000> const xxxx, rrrr, ssss; - vec<4,T,0x0001> const xxxy, rrrg, ssst; - vec<4,T,0x0010> const xxyx, rrgr, ssts; - vec<4,T,0x0011> const xxyy, rrgg, sstt; - vec<4,T,0x0100> const xyxx, rgrr, stss; - vec<4,T,0x0101> const xyxy, rgrg, stst; - vec<4,T,0x0110> const xyyx, rggr, stts; - vec<4,T,0x0111> const xyyy, rggg, sttt; - vec<4,T,0x1000> const yxxx, grrr, tsss; - vec<4,T,0x1001> const yxxy, grrg, tsst; - vec<4,T,0x1010> const yxyx, grgr, tsts; - vec<4,T,0x1011> const yxyy, grgg, tstt; - vec<4,T,0x1100> const yyxx, ggrr, ttss; - vec<4,T,0x1101> const yyxy, ggrg, ttst; - vec<4,T,0x1110> const yyyx, gggr, ttts; - vec<4,T,0x1111> const yyyy, gggg, tttt; + vec_t const xx, rr, ss; + vec_t _____ xy, rg, st; + vec_t _____ yx, gr, ts; + vec_t const yy, gg, tt; + + vec_t const xxx, rrr, sss; + vec_t const xxy, rrg, sst; + vec_t const xyx, rgr, sts; + vec_t const xyy, rgg, stt; + vec_t const yxx, grr, tss; + vec_t const yxy, grg, tst; + vec_t const yyx, ggr, tts; + vec_t const yyy, ggg, ttt; + + vec_t const xxxx, rrrr, ssss; + vec_t const xxxy, rrrg, ssst; + vec_t const xxyx, rrgr, ssts; + vec_t const xxyy, rrgg, sstt; + vec_t const xyxx, rgrr, stss; + vec_t const xyxy, rgrg, stst; + vec_t const xyyx, rggr, stts; + vec_t const xyyy, rggg, sttt; + vec_t const yxxx, grrr, tsss; + vec_t const yxxy, grrg, tsst; + vec_t const yxyx, grgr, tsts; + vec_t const yxyy, grgg, tstt; + vec_t const yyxx, ggrr, ttss; + vec_t const yyxy, ggrg, ttst; + vec_t const yyyx, gggr, ttts; + vec_t const yyyy, gggg, tttt; #endif }; }; @@ -301,53 +301,53 @@ struct vec<2,T> */ template -struct vec<3,T> +struct vec_t { - typedef vec<3,T> type; + typedef vec_t type; /* Default constructor, copy constructor, and destructor */ - inline constexpr vec() : x(), y(), z() {} - inline constexpr vec(vec<3,T> const &v) : x(v.x), y(v.y), z(v.z) {} - inline ~vec() { x.~T(); y.~T(); z.~T(); } + inline constexpr vec_t() : x(), y(), z() {} + inline constexpr vec_t(vec_t const &v) : x(v.x), y(v.y), z(v.z) {} + inline ~vec_t() { x.~T(); y.~T(); z.~T(); } /* Implicit constructor for swizzling */ template - inline constexpr vec(vec<3, T, SWIZZLE> const &v) + inline constexpr vec_t(vec_t const &v) : x(v[0]), y(v[1]), z(v[2]) {} /* Explicit constructor for type conversion */ template - explicit inline constexpr vec(vec<3, U, SWIZZLE> const &v) + explicit inline constexpr vec_t(vec_t const &v) : x(v[0]), y(v[1]), z(v[2]) {} /* Various explicit constructors */ - explicit inline constexpr vec(T X) + explicit inline constexpr vec_t(T X) : x(X), y(X), z(X) {} - explicit inline constexpr vec(T X, T Y, T Z) + explicit inline constexpr vec_t(T X, T Y, T Z) : x(X), y(Y), z(Z) {} - explicit inline constexpr vec(vec<2,T> XY, T Z) + explicit inline constexpr vec_t(vec_t XY, T Z) : x(XY.x), y(XY.y), z(Z) {} - explicit inline constexpr vec(T X, vec<2,T> YZ) + explicit inline constexpr vec_t(T X, vec_t YZ) : x(X), y(YZ.x), z(YZ.y) {} LOL_COMMON_MEMBER_OPS(x) LOL_VECTOR_MEMBER_OPS() - static vec<3,T> toeuler_xyx(Quat const &q); - static vec<3,T> toeuler_xzx(Quat const &q); - static vec<3,T> toeuler_yxy(Quat const &q); - static vec<3,T> toeuler_yzy(Quat const &q); - static vec<3,T> toeuler_zxz(Quat const &q); - static vec<3,T> toeuler_zyz(Quat const &q); - - static vec<3,T> toeuler_xyz(Quat const &q); - static vec<3,T> toeuler_xzy(Quat const &q); - static vec<3,T> toeuler_yxz(Quat const &q); - static vec<3,T> toeuler_yzx(Quat const &q); - static vec<3,T> toeuler_zxy(Quat const &q); - static vec<3,T> toeuler_zyx(Quat const &q); - - /* Return the cross product (vector product) of "a" and "b" */ \ + static vec_t toeuler_xyx(quat_t const &q); + static vec_t toeuler_xzx(quat_t const &q); + static vec_t toeuler_yxy(quat_t const &q); + static vec_t toeuler_yzy(quat_t const &q); + static vec_t toeuler_zxz(quat_t const &q); + static vec_t toeuler_zyz(quat_t const &q); + + static vec_t toeuler_xyz(quat_t const &q); + static vec_t toeuler_xzy(quat_t const &q); + static vec_t toeuler_yxz(quat_t const &q); + static vec_t toeuler_yzx(quat_t const &q); + static vec_t toeuler_zxy(quat_t const &q); + static vec_t toeuler_zyx(quat_t const &q); + + /* Return the cross product (vector product) of “a” and “b” */ \ friend inline type cross(type const &a, type const &b) { return type(a.y * b.z - a.z * b.y, @@ -355,7 +355,7 @@ struct vec<3,T> a.x * b.y - a.y * b.x); } - /* Return a vector that is orthogonal to "a" */ + /* Return a vector that is orthogonal to “a” */ friend inline type orthogonal(type const &a) { return lol::abs(a.x) > lol::abs(a.z) @@ -363,19 +363,19 @@ struct vec<3,T> : type((T)0, -a.z, a.y); } - /* Return a vector that is orthonormal to "a" */ + /* Return a vector that is orthonormal to “a” */ friend inline type orthonormal(type const &a) { return normalize(orthogonal(a)); } - static const vec<3,T> zero; - static const vec<3,T> axis_x; - static const vec<3,T> axis_y; - static const vec<3,T> axis_z; + static const vec_t zero; + static const vec_t axis_x; + static const vec_t axis_y; + static const vec_t axis_z; template - friend std::ostream &operator<<(std::ostream &stream, vec<3,U> const &v); + friend std::ostream &operator<<(std::ostream &stream, vec_t const &v); union { @@ -384,125 +384,125 @@ struct vec<3,T> struct { T s, t, p; }; #if !_DOXYGEN_SKIP_ME - vec<2,T,0x00> const xx, rr, ss; - vec<2,T,0x01> _____ xy, rg, st; - vec<2,T,0x02> _____ xz, rb, sp; - vec<2,T,0x10> _____ yx, gr, ts; - vec<2,T,0x11> const yy, gg, tt; - vec<2,T,0x12> _____ yz, gb, tp; - vec<2,T,0x20> _____ zx, br, ps; - vec<2,T,0x21> _____ zy, bg, pt; - vec<2,T,0x22> const zz, bb, pp; - - vec<3,T,0x000> const xxx, rrr, sss; - vec<3,T,0x001> const xxy, rrg, sst; - vec<3,T,0x002> const xxz, rrb, ssp; - vec<3,T,0x010> const xyx, rgr, sts; - vec<3,T,0x011> const xyy, rgg, stt; - vec<3,T,0x012> _____ xyz, rgb, stp; - vec<3,T,0x020> const xzx, rbr, sps; - vec<3,T,0x021> _____ xzy, rbg, spt; - vec<3,T,0x022> const xzz, rbb, spp; - vec<3,T,0x100> const yxx, grr, tss; - vec<3,T,0x101> const yxy, grg, tst; - vec<3,T,0x102> _____ yxz, grb, tsp; - vec<3,T,0x110> const yyx, ggr, tts; - vec<3,T,0x111> const yyy, ggg, ttt; - vec<3,T,0x112> const yyz, ggb, ttp; - vec<3,T,0x120> _____ yzx, gbr, tps; - vec<3,T,0x121> const yzy, gbg, tpt; - vec<3,T,0x122> const yzz, gbb, tpp; - vec<3,T,0x200> const zxx, brr, pss; - vec<3,T,0x201> _____ zxy, brg, pst; - vec<3,T,0x202> const zxz, brb, psp; - vec<3,T,0x210> _____ zyx, bgr, pts; - vec<3,T,0x211> const zyy, bgg, ptt; - vec<3,T,0x212> const zyz, bgb, ptp; - vec<3,T,0x220> const zzx, bbr, pps; - vec<3,T,0x221> const zzy, bbg, ppt; - vec<3,T,0x222> const zzz, bbb, ppp; - - vec<4,T,0x0000> const xxxx, rrrr, ssss; - vec<4,T,0x0001> const xxxy, rrrg, ssst; - vec<4,T,0x0002> const xxxz, rrrb, sssp; - vec<4,T,0x0010> const xxyx, rrgr, ssts; - vec<4,T,0x0011> const xxyy, rrgg, sstt; - vec<4,T,0x0012> const xxyz, rrgb, sstp; - vec<4,T,0x0020> const xxzx, rrbr, ssps; - vec<4,T,0x0021> const xxzy, rrbg, sspt; - vec<4,T,0x0022> const xxzz, rrbb, sspp; - vec<4,T,0x0100> const xyxx, rgrr, stss; - vec<4,T,0x0101> const xyxy, rgrg, stst; - vec<4,T,0x0102> const xyxz, rgrb, stsp; - vec<4,T,0x0110> const xyyx, rggr, stts; - vec<4,T,0x0111> const xyyy, rggg, sttt; - vec<4,T,0x0112> const xyyz, rggb, sttp; - vec<4,T,0x0120> const xyzx, rgbr, stps; - vec<4,T,0x0121> const xyzy, rgbg, stpt; - vec<4,T,0x0122> const xyzz, rgbb, stpp; - vec<4,T,0x0200> const xzxx, rbrr, spss; - vec<4,T,0x0201> const xzxy, rbrg, spst; - vec<4,T,0x0202> const xzxz, rbrb, spsp; - vec<4,T,0x0210> const xzyx, rbgr, spts; - vec<4,T,0x0211> const xzyy, rbgg, sptt; - vec<4,T,0x0212> const xzyz, rbgb, sptp; - vec<4,T,0x0220> const xzzx, rbbr, spps; - vec<4,T,0x0221> const xzzy, rbbg, sppt; - vec<4,T,0x0222> const xzzz, rbbb, sppp; - vec<4,T,0x1000> const yxxx, grrr, tsss; - vec<4,T,0x1001> const yxxy, grrg, tsst; - vec<4,T,0x1002> const yxxz, grrb, tssp; - vec<4,T,0x1010> const yxyx, grgr, tsts; - vec<4,T,0x1011> const yxyy, grgg, tstt; - vec<4,T,0x1012> const yxyz, grgb, tstp; - vec<4,T,0x1020> const yxzx, grbr, tsps; - vec<4,T,0x1021> const yxzy, grbg, tspt; - vec<4,T,0x1022> const yxzz, grbb, tspp; - vec<4,T,0x1100> const yyxx, ggrr, ttss; - vec<4,T,0x1101> const yyxy, ggrg, ttst; - vec<4,T,0x1102> const yyxz, ggrb, ttsp; - vec<4,T,0x1110> const yyyx, gggr, ttts; - vec<4,T,0x1111> const yyyy, gggg, tttt; - vec<4,T,0x1112> const yyyz, gggb, tttp; - vec<4,T,0x1120> const yyzx, ggbr, ttps; - vec<4,T,0x1121> const yyzy, ggbg, ttpt; - vec<4,T,0x1122> const yyzz, ggbb, ttpp; - vec<4,T,0x1200> const yzxx, gbrr, tpss; - vec<4,T,0x1201> const yzxy, gbrg, tpst; - vec<4,T,0x1202> const yzxz, gbrb, tpsp; - vec<4,T,0x1210> const yzyx, gbgr, tpts; - vec<4,T,0x1211> const yzyy, gbgg, tptt; - vec<4,T,0x1212> const yzyz, gbgb, tptp; - vec<4,T,0x1220> const yzzx, gbbr, tpps; - vec<4,T,0x1221> const yzzy, gbbg, tppt; - vec<4,T,0x1222> const yzzz, gbbb, tppp; - vec<4,T,0x2000> const zxxx, brrr, psss; - vec<4,T,0x2001> const zxxy, brrg, psst; - vec<4,T,0x2002> const zxxz, brrb, pssp; - vec<4,T,0x2010> const zxyx, brgr, psts; - vec<4,T,0x2011> const zxyy, brgg, pstt; - vec<4,T,0x2012> const zxyz, brgb, pstp; - vec<4,T,0x2020> const zxzx, brbr, psps; - vec<4,T,0x2021> const zxzy, brbg, pspt; - vec<4,T,0x2022> const zxzz, brbb, pspp; - vec<4,T,0x2100> const zyxx, bgrr, ptss; - vec<4,T,0x2101> const zyxy, bgrg, ptst; - vec<4,T,0x2102> const zyxz, bgrb, ptsp; - vec<4,T,0x2110> const zyyx, bggr, ptts; - vec<4,T,0x2111> const zyyy, bggg, pttt; - vec<4,T,0x2112> const zyyz, bggb, pttp; - vec<4,T,0x2120> const zyzx, bgbr, ptps; - vec<4,T,0x2121> const zyzy, bgbg, ptpt; - vec<4,T,0x2122> const zyzz, bgbb, ptpp; - vec<4,T,0x2200> const zzxx, bbrr, ppss; - vec<4,T,0x2201> const zzxy, bbrg, ppst; - vec<4,T,0x2202> const zzxz, bbrb, ppsp; - vec<4,T,0x2210> const zzyx, bbgr, ppts; - vec<4,T,0x2211> const zzyy, bbgg, pptt; - vec<4,T,0x2212> const zzyz, bbgb, pptp; - vec<4,T,0x2220> const zzzx, bbbr, ppps; - vec<4,T,0x2221> const zzzy, bbbg, pppt; - vec<4,T,0x2222> const zzzz, bbbb, pppp; + vec_t const xx, rr, ss; + vec_t _____ xy, rg, st; + vec_t _____ xz, rb, sp; + vec_t _____ yx, gr, ts; + vec_t const yy, gg, tt; + vec_t _____ yz, gb, tp; + vec_t _____ zx, br, ps; + vec_t _____ zy, bg, pt; + vec_t const zz, bb, pp; + + vec_t const xxx, rrr, sss; + vec_t const xxy, rrg, sst; + vec_t const xxz, rrb, ssp; + vec_t const xyx, rgr, sts; + vec_t const xyy, rgg, stt; + vec_t _____ xyz, rgb, stp; + vec_t const xzx, rbr, sps; + vec_t _____ xzy, rbg, spt; + vec_t const xzz, rbb, spp; + vec_t const yxx, grr, tss; + vec_t const yxy, grg, tst; + vec_t _____ yxz, grb, tsp; + vec_t const yyx, ggr, tts; + vec_t const yyy, ggg, ttt; + vec_t const yyz, ggb, ttp; + vec_t _____ yzx, gbr, tps; + vec_t const yzy, gbg, tpt; + vec_t const yzz, gbb, tpp; + vec_t const zxx, brr, pss; + vec_t _____ zxy, brg, pst; + vec_t const zxz, brb, psp; + vec_t _____ zyx, bgr, pts; + vec_t const zyy, bgg, ptt; + vec_t const zyz, bgb, ptp; + vec_t const zzx, bbr, pps; + vec_t const zzy, bbg, ppt; + vec_t const zzz, bbb, ppp; + + vec_t const xxxx, rrrr, ssss; + vec_t const xxxy, rrrg, ssst; + vec_t const xxxz, rrrb, sssp; + vec_t const xxyx, rrgr, ssts; + vec_t const xxyy, rrgg, sstt; + vec_t const xxyz, rrgb, sstp; + vec_t const xxzx, rrbr, ssps; + vec_t const xxzy, rrbg, sspt; + vec_t const xxzz, rrbb, sspp; + vec_t const xyxx, rgrr, stss; + vec_t const xyxy, rgrg, stst; + vec_t const xyxz, rgrb, stsp; + vec_t const xyyx, rggr, stts; + vec_t const xyyy, rggg, sttt; + vec_t const xyyz, rggb, sttp; + vec_t const xyzx, rgbr, stps; + vec_t const xyzy, rgbg, stpt; + vec_t const xyzz, rgbb, stpp; + vec_t const xzxx, rbrr, spss; + vec_t const xzxy, rbrg, spst; + vec_t const xzxz, rbrb, spsp; + vec_t const xzyx, rbgr, spts; + vec_t const xzyy, rbgg, sptt; + vec_t const xzyz, rbgb, sptp; + vec_t const xzzx, rbbr, spps; + vec_t const xzzy, rbbg, sppt; + vec_t const xzzz, rbbb, sppp; + vec_t const yxxx, grrr, tsss; + vec_t const yxxy, grrg, tsst; + vec_t const yxxz, grrb, tssp; + vec_t const yxyx, grgr, tsts; + vec_t const yxyy, grgg, tstt; + vec_t const yxyz, grgb, tstp; + vec_t const yxzx, grbr, tsps; + vec_t const yxzy, grbg, tspt; + vec_t const yxzz, grbb, tspp; + vec_t const yyxx, ggrr, ttss; + vec_t const yyxy, ggrg, ttst; + vec_t const yyxz, ggrb, ttsp; + vec_t const yyyx, gggr, ttts; + vec_t const yyyy, gggg, tttt; + vec_t const yyyz, gggb, tttp; + vec_t const yyzx, ggbr, ttps; + vec_t const yyzy, ggbg, ttpt; + vec_t const yyzz, ggbb, ttpp; + vec_t const yzxx, gbrr, tpss; + vec_t const yzxy, gbrg, tpst; + vec_t const yzxz, gbrb, tpsp; + vec_t const yzyx, gbgr, tpts; + vec_t const yzyy, gbgg, tptt; + vec_t const yzyz, gbgb, tptp; + vec_t const yzzx, gbbr, tpps; + vec_t const yzzy, gbbg, tppt; + vec_t const yzzz, gbbb, tppp; + vec_t const zxxx, brrr, psss; + vec_t const zxxy, brrg, psst; + vec_t const zxxz, brrb, pssp; + vec_t const zxyx, brgr, psts; + vec_t const zxyy, brgg, pstt; + vec_t const zxyz, brgb, pstp; + vec_t const zxzx, brbr, psps; + vec_t const zxzy, brbg, pspt; + vec_t const zxzz, brbb, pspp; + vec_t const zyxx, bgrr, ptss; + vec_t const zyxy, bgrg, ptst; + vec_t const zyxz, bgrb, ptsp; + vec_t const zyyx, bggr, ptts; + vec_t const zyyy, bggg, pttt; + vec_t const zyyz, bggb, pttp; + vec_t const zyzx, bgbr, ptps; + vec_t const zyzy, bgbg, ptpt; + vec_t const zyzz, bgbb, ptpp; + vec_t const zzxx, bbrr, ppss; + vec_t const zzxy, bbrg, ppst; + vec_t const zzxz, bbrb, ppsp; + vec_t const zzyx, bbgr, ppts; + vec_t const zzyy, bbgg, pptt; + vec_t const zzyz, bbgb, pptp; + vec_t const zzzx, bbbr, ppps; + vec_t const zzzy, bbbg, pppt; + vec_t const zzzz, bbbb, pppp; #endif }; }; @@ -512,54 +512,55 @@ struct vec<3,T> */ template -struct vec<4,T> +struct vec_t { - typedef vec<4,T> type; + typedef vec_t type; /* Default constructor, copy constructor, and destructor */ - inline constexpr vec() : x(), y(), z(), w() {} - inline constexpr vec(vec<4,T> const &v) : x(v.x), y(v.y), z(v.z), w(v.w) {} - inline ~vec() { x.~T(); y.~T(); z.~T(); w.~T(); } + inline constexpr vec_t() : x(), y(), z(), w() {} + inline constexpr vec_t(vec_t const &v) + : x(v.x), y(v.y), z(v.z), w(v.w) {} + inline ~vec_t() { x.~T(); y.~T(); z.~T(); w.~T(); } /* Implicit constructor for swizzling */ template - inline constexpr vec(vec<4, T, SWIZZLE> const &v) + inline constexpr vec_t(vec_t const &v) : x(v[0]), y(v[1]), z(v[2]), w(v[3]) {} /* Explicit constructor for type conversion */ template - explicit inline constexpr vec(vec<4, U, SWIZZLE> const &v) + explicit inline constexpr vec_t(vec_t const &v) : x(v[0]), y(v[1]), z(v[2]), w(v[3]) {} /* Various explicit constructors */ - explicit inline constexpr vec(T X) + explicit inline constexpr vec_t(T X) : x(X), y(X), z(X), w(X) {} - explicit inline constexpr vec(T X, T Y, T Z, T W) + explicit inline constexpr vec_t(T X, T Y, T Z, T W) : x(X), y(Y), z(Z), w(W) {} - explicit inline constexpr vec(vec<2,T> XY, T Z, T W) + explicit inline constexpr vec_t(vec_t XY, T Z, T W) : x(XY.x), y(XY.y), z(Z), w(W) {} - explicit inline constexpr vec(T X, vec<2,T> YZ, T W) + explicit inline constexpr vec_t(T X, vec_t YZ, T W) : x(X), y(YZ.x), z(YZ.y), w(W) {} - explicit inline constexpr vec(T X, T Y, vec<2,T> ZW) + explicit inline constexpr vec_t(T X, T Y, vec_t ZW) : x(X), y(Y), z(ZW.x), w(ZW.y) {} - explicit inline constexpr vec(vec<2,T> XY, vec<2,T> ZW) + explicit inline constexpr vec_t(vec_t XY, vec_t ZW) : x(XY.x), y(XY.y), z(ZW.x), w(ZW.y) {} - explicit inline constexpr vec(vec<3,T> XYZ, T W) + explicit inline constexpr vec_t(vec_t XYZ, T W) : x(XYZ.x), y(XYZ.y), z(XYZ.z), w(W) {} - explicit inline constexpr vec(T X, vec<3,T> YZW) + explicit inline constexpr vec_t(T X, vec_t YZW) : x(X), y(YZW.x), z(YZW.y), w(YZW.z) {} LOL_COMMON_MEMBER_OPS(x) LOL_VECTOR_MEMBER_OPS() - static const vec<4,T> zero; - static const vec<4,T> axis_x; - static const vec<4,T> axis_y; - static const vec<4,T> axis_z; - static const vec<4,T> axis_w; + static const vec_t zero; + static const vec_t axis_x; + static const vec_t axis_y; + static const vec_t axis_z; + static const vec_t axis_w; template - friend std::ostream &operator<<(std::ostream &stream, vec<4,U> const &v); + friend std::ostream &operator<<(std::ostream &stream, vec_t const &v); union { @@ -568,357 +569,357 @@ struct vec<4,T> struct { T s, t, p, q; }; #if !_DOXYGEN_SKIP_ME - vec<2,T,0x00> const xx, rr, ss; - vec<2,T,0x01> _____ xy, rg, st; - vec<2,T,0x02> _____ xz, rb, sp; - vec<2,T,0x03> _____ xw, ra, sq; - vec<2,T,0x10> _____ yx, gr, ts; - vec<2,T,0x11> const yy, gg, tt; - vec<2,T,0x12> _____ yz, gb, tp; - vec<2,T,0x13> _____ yw, ga, tq; - vec<2,T,0x20> _____ zx, br, ps; - vec<2,T,0x21> _____ zy, bg, pt; - vec<2,T,0x22> const zz, bb, pp; - vec<2,T,0x23> _____ zw, ba, pq; - vec<2,T,0x30> _____ wx, ar, qs; - vec<2,T,0x31> _____ wy, ag, qt; - vec<2,T,0x32> _____ wz, ab, qp; - vec<2,T,0x33> const ww, aa, qq; - - vec<3,T,0x000> const xxx, rrr, sss; - vec<3,T,0x001> const xxy, rrg, sst; - vec<3,T,0x002> const xxz, rrb, ssp; - vec<3,T,0x003> const xxw, rra, ssq; - vec<3,T,0x010> const xyx, rgr, sts; - vec<3,T,0x011> const xyy, rgg, stt; - vec<3,T,0x012> _____ xyz, rgb, stp; - vec<3,T,0x013> _____ xyw, rga, stq; - vec<3,T,0x020> const xzx, rbr, sps; - vec<3,T,0x021> _____ xzy, rbg, spt; - vec<3,T,0x022> const xzz, rbb, spp; - vec<3,T,0x023> _____ xzw, rba, spq; - vec<3,T,0x030> const xwx, rar, sqs; - vec<3,T,0x031> _____ xwy, rag, sqt; - vec<3,T,0x032> _____ xwz, rab, sqp; - vec<3,T,0x033> const xww, raa, sqq; - vec<3,T,0x100> const yxx, grr, tss; - vec<3,T,0x101> const yxy, grg, tst; - vec<3,T,0x102> _____ yxz, grb, tsp; - vec<3,T,0x103> _____ yxw, gra, tsq; - vec<3,T,0x110> const yyx, ggr, tts; - vec<3,T,0x111> const yyy, ggg, ttt; - vec<3,T,0x112> const yyz, ggb, ttp; - vec<3,T,0x113> const yyw, gga, ttq; - vec<3,T,0x120> _____ yzx, gbr, tps; - vec<3,T,0x121> const yzy, gbg, tpt; - vec<3,T,0x122> const yzz, gbb, tpp; - vec<3,T,0x123> _____ yzw, gba, tpq; - vec<3,T,0x130> _____ ywx, gar, tqs; - vec<3,T,0x131> const ywy, gag, tqt; - vec<3,T,0x132> _____ ywz, gab, tqp; - vec<3,T,0x133> const yww, gaa, tqq; - vec<3,T,0x200> const zxx, brr, pss; - vec<3,T,0x201> _____ zxy, brg, pst; - vec<3,T,0x202> const zxz, brb, psp; - vec<3,T,0x203> _____ zxw, bra, psq; - vec<3,T,0x210> _____ zyx, bgr, pts; - vec<3,T,0x211> const zyy, bgg, ptt; - vec<3,T,0x212> const zyz, bgb, ptp; - vec<3,T,0x213> _____ zyw, bga, ptq; - vec<3,T,0x220> const zzx, bbr, pps; - vec<3,T,0x221> const zzy, bbg, ppt; - vec<3,T,0x222> const zzz, bbb, ppp; - vec<3,T,0x223> const zzw, bba, ppq; - vec<3,T,0x230> _____ zwx, bar, pqs; - vec<3,T,0x231> _____ zwy, bag, pqt; - vec<3,T,0x232> const zwz, bab, pqp; - vec<3,T,0x233> const zww, baa, pqq; - vec<3,T,0x300> const wxx, arr, qss; - vec<3,T,0x301> _____ wxy, arg, qst; - vec<3,T,0x302> _____ wxz, arb, qsp; - vec<3,T,0x303> const wxw, ara, qsq; - vec<3,T,0x310> _____ wyx, agr, qts; - vec<3,T,0x311> const wyy, agg, qtt; - vec<3,T,0x312> _____ wyz, agb, qtp; - vec<3,T,0x313> const wyw, aga, qtq; - vec<3,T,0x320> _____ wzx, abr, qps; - vec<3,T,0x321> _____ wzy, abg, qpt; - vec<3,T,0x322> const wzz, abb, qpp; - vec<3,T,0x323> const wzw, aba, qpq; - vec<3,T,0x330> const wwx, aar, qqs; - vec<3,T,0x331> const wwy, aag, qqt; - vec<3,T,0x332> const wwz, aab, qqp; - vec<3,T,0x333> const www, aaa, qqq; - - vec<4,T,0x0000> const xxxx, rrrr, ssss; - vec<4,T,0x0001> const xxxy, rrrg, ssst; - vec<4,T,0x0002> const xxxz, rrrb, sssp; - vec<4,T,0x0003> const xxxw, rrra, sssq; - vec<4,T,0x0010> const xxyx, rrgr, ssts; - vec<4,T,0x0011> const xxyy, rrgg, sstt; - vec<4,T,0x0012> const xxyz, rrgb, sstp; - vec<4,T,0x0013> const xxyw, rrga, sstq; - vec<4,T,0x0020> const xxzx, rrbr, ssps; - vec<4,T,0x0021> const xxzy, rrbg, sspt; - vec<4,T,0x0022> const xxzz, rrbb, sspp; - vec<4,T,0x0023> const xxzw, rrba, sspq; - vec<4,T,0x0030> const xxwx, rrar, ssqs; - vec<4,T,0x0031> const xxwy, rrag, ssqt; - vec<4,T,0x0032> const xxwz, rrab, ssqp; - vec<4,T,0x0033> const xxww, rraa, ssqq; - vec<4,T,0x0100> const xyxx, rgrr, stss; - vec<4,T,0x0101> const xyxy, rgrg, stst; - vec<4,T,0x0102> const xyxz, rgrb, stsp; - vec<4,T,0x0103> const xyxw, rgra, stsq; - vec<4,T,0x0110> const xyyx, rggr, stts; - vec<4,T,0x0111> const xyyy, rggg, sttt; - vec<4,T,0x0112> const xyyz, rggb, sttp; - vec<4,T,0x0113> const xyyw, rgga, sttq; - vec<4,T,0x0120> const xyzx, rgbr, stps; - vec<4,T,0x0121> const xyzy, rgbg, stpt; - vec<4,T,0x0122> const xyzz, rgbb, stpp; - vec<4,T,0x0123> _____ xyzw, rgba, stpq; - vec<4,T,0x0130> const xywx, rgar, stqs; - vec<4,T,0x0131> const xywy, rgag, stqt; - vec<4,T,0x0132> _____ xywz, rgab, stqp; - vec<4,T,0x0133> const xyww, rgaa, stqq; - vec<4,T,0x0200> const xzxx, rbrr, spss; - vec<4,T,0x0201> const xzxy, rbrg, spst; - vec<4,T,0x0202> const xzxz, rbrb, spsp; - vec<4,T,0x0203> const xzxw, rbra, spsq; - vec<4,T,0x0210> const xzyx, rbgr, spts; - vec<4,T,0x0211> const xzyy, rbgg, sptt; - vec<4,T,0x0212> const xzyz, rbgb, sptp; - vec<4,T,0x0213> _____ xzyw, rbga, sptq; - vec<4,T,0x0220> const xzzx, rbbr, spps; - vec<4,T,0x0221> const xzzy, rbbg, sppt; - vec<4,T,0x0222> const xzzz, rbbb, sppp; - vec<4,T,0x0223> const xzzw, rbba, sppq; - vec<4,T,0x0230> const xzwx, rbar, spqs; - vec<4,T,0x0231> _____ xzwy, rbag, spqt; - vec<4,T,0x0232> const xzwz, rbab, spqp; - vec<4,T,0x0233> const xzww, rbaa, spqq; - vec<4,T,0x0300> const xwxx, rarr, sqss; - vec<4,T,0x0301> const xwxy, rarg, sqst; - vec<4,T,0x0302> const xwxz, rarb, sqsp; - vec<4,T,0x0303> const xwxw, rara, sqsq; - vec<4,T,0x0310> const xwyx, ragr, sqts; - vec<4,T,0x0311> const xwyy, ragg, sqtt; - vec<4,T,0x0312> _____ xwyz, ragb, sqtp; - vec<4,T,0x0313> const xwyw, raga, sqtq; - vec<4,T,0x0320> const xwzx, rabr, sqps; - vec<4,T,0x0321> _____ xwzy, rabg, sqpt; - vec<4,T,0x0322> const xwzz, rabb, sqpp; - vec<4,T,0x0323> const xwzw, raba, sqpq; - vec<4,T,0x0330> const xwwx, raar, sqqs; - vec<4,T,0x0331> const xwwy, raag, sqqt; - vec<4,T,0x0332> const xwwz, raab, sqqp; - vec<4,T,0x0333> const xwww, raaa, sqqq; - vec<4,T,0x1000> const yxxx, grrr, tsss; - vec<4,T,0x1001> const yxxy, grrg, tsst; - vec<4,T,0x1002> const yxxz, grrb, tssp; - vec<4,T,0x1003> const yxxw, grra, tssq; - vec<4,T,0x1010> const yxyx, grgr, tsts; - vec<4,T,0x1011> const yxyy, grgg, tstt; - vec<4,T,0x1012> const yxyz, grgb, tstp; - vec<4,T,0x1013> const yxyw, grga, tstq; - vec<4,T,0x1020> const yxzx, grbr, tsps; - vec<4,T,0x1021> const yxzy, grbg, tspt; - vec<4,T,0x1022> const yxzz, grbb, tspp; - vec<4,T,0x1023> _____ yxzw, grba, tspq; - vec<4,T,0x1030> const yxwx, grar, tsqs; - vec<4,T,0x1031> const yxwy, grag, tsqt; - vec<4,T,0x1032> _____ yxwz, grab, tsqp; - vec<4,T,0x1033> const yxww, graa, tsqq; - vec<4,T,0x1100> const yyxx, ggrr, ttss; - vec<4,T,0x1101> const yyxy, ggrg, ttst; - vec<4,T,0x1102> const yyxz, ggrb, ttsp; - vec<4,T,0x1103> const yyxw, ggra, ttsq; - vec<4,T,0x1110> const yyyx, gggr, ttts; - vec<4,T,0x1111> const yyyy, gggg, tttt; - vec<4,T,0x1112> const yyyz, gggb, tttp; - vec<4,T,0x1113> const yyyw, ggga, tttq; - vec<4,T,0x1120> const yyzx, ggbr, ttps; - vec<4,T,0x1121> const yyzy, ggbg, ttpt; - vec<4,T,0x1122> const yyzz, ggbb, ttpp; - vec<4,T,0x1123> const yyzw, ggba, ttpq; - vec<4,T,0x1130> const yywx, ggar, ttqs; - vec<4,T,0x1131> const yywy, ggag, ttqt; - vec<4,T,0x1132> const yywz, ggab, ttqp; - vec<4,T,0x1133> const yyww, ggaa, ttqq; - vec<4,T,0x1200> const yzxx, gbrr, tpss; - vec<4,T,0x1201> const yzxy, gbrg, tpst; - vec<4,T,0x1202> const yzxz, gbrb, tpsp; - vec<4,T,0x1203> _____ yzxw, gbra, tpsq; - vec<4,T,0x1210> const yzyx, gbgr, tpts; - vec<4,T,0x1211> const yzyy, gbgg, tptt; - vec<4,T,0x1212> const yzyz, gbgb, tptp; - vec<4,T,0x1213> const yzyw, gbga, tptq; - vec<4,T,0x1220> const yzzx, gbbr, tpps; - vec<4,T,0x1221> const yzzy, gbbg, tppt; - vec<4,T,0x1222> const yzzz, gbbb, tppp; - vec<4,T,0x1223> const yzzw, gbba, tppq; - vec<4,T,0x1230> _____ yzwx, gbar, tpqs; - vec<4,T,0x1231> const yzwy, gbag, tpqt; - vec<4,T,0x1232> const yzwz, gbab, tpqp; - vec<4,T,0x1233> const yzww, gbaa, tpqq; - vec<4,T,0x1300> const ywxx, garr, tqss; - vec<4,T,0x1301> const ywxy, garg, tqst; - vec<4,T,0x1302> _____ ywxz, garb, tqsp; - vec<4,T,0x1303> const ywxw, gara, tqsq; - vec<4,T,0x1310> const ywyx, gagr, tqts; - vec<4,T,0x1311> const ywyy, gagg, tqtt; - vec<4,T,0x1312> const ywyz, gagb, tqtp; - vec<4,T,0x1313> const ywyw, gaga, tqtq; - vec<4,T,0x1320> _____ ywzx, gabr, tqps; - vec<4,T,0x1321> const ywzy, gabg, tqpt; - vec<4,T,0x1322> const ywzz, gabb, tqpp; - vec<4,T,0x1323> const ywzw, gaba, tqpq; - vec<4,T,0x1330> const ywwx, gaar, tqqs; - vec<4,T,0x1331> const ywwy, gaag, tqqt; - vec<4,T,0x1332> const ywwz, gaab, tqqp; - vec<4,T,0x1333> const ywww, gaaa, tqqq; - vec<4,T,0x2000> const zxxx, brrr, psss; - vec<4,T,0x2001> const zxxy, brrg, psst; - vec<4,T,0x2002> const zxxz, brrb, pssp; - vec<4,T,0x2003> const zxxw, brra, pssq; - vec<4,T,0x2010> const zxyx, brgr, psts; - vec<4,T,0x2011> const zxyy, brgg, pstt; - vec<4,T,0x2012> const zxyz, brgb, pstp; - vec<4,T,0x2013> _____ zxyw, brga, pstq; - vec<4,T,0x2020> const zxzx, brbr, psps; - vec<4,T,0x2021> const zxzy, brbg, pspt; - vec<4,T,0x2022> const zxzz, brbb, pspp; - vec<4,T,0x2023> const zxzw, brba, pspq; - vec<4,T,0x2030> const zxwx, brar, psqs; - vec<4,T,0x2031> _____ zxwy, brag, psqt; - vec<4,T,0x2032> const zxwz, brab, psqp; - vec<4,T,0x2033> const zxww, braa, psqq; - vec<4,T,0x2100> const zyxx, bgrr, ptss; - vec<4,T,0x2101> const zyxy, bgrg, ptst; - vec<4,T,0x2102> const zyxz, bgrb, ptsp; - vec<4,T,0x2103> _____ zyxw, bgra, ptsq; - vec<4,T,0x2110> const zyyx, bggr, ptts; - vec<4,T,0x2111> const zyyy, bggg, pttt; - vec<4,T,0x2112> const zyyz, bggb, pttp; - vec<4,T,0x2113> const zyyw, bgga, pttq; - vec<4,T,0x2120> const zyzx, bgbr, ptps; - vec<4,T,0x2121> const zyzy, bgbg, ptpt; - vec<4,T,0x2122> const zyzz, bgbb, ptpp; - vec<4,T,0x2123> const zyzw, bgba, ptpq; - vec<4,T,0x2130> _____ zywx, bgar, ptqs; - vec<4,T,0x2131> const zywy, bgag, ptqt; - vec<4,T,0x2132> const zywz, bgab, ptqp; - vec<4,T,0x2133> const zyww, bgaa, ptqq; - vec<4,T,0x2200> const zzxx, bbrr, ppss; - vec<4,T,0x2201> const zzxy, bbrg, ppst; - vec<4,T,0x2202> const zzxz, bbrb, ppsp; - vec<4,T,0x2203> const zzxw, bbra, ppsq; - vec<4,T,0x2210> const zzyx, bbgr, ppts; - vec<4,T,0x2211> const zzyy, bbgg, pptt; - vec<4,T,0x2212> const zzyz, bbgb, pptp; - vec<4,T,0x2213> const zzyw, bbga, pptq; - vec<4,T,0x2220> const zzzx, bbbr, ppps; - vec<4,T,0x2221> const zzzy, bbbg, pppt; - vec<4,T,0x2222> const zzzz, bbbb, pppp; - vec<4,T,0x2223> const zzzw, bbba, pppq; - vec<4,T,0x2230> const zzwx, bbar, ppqs; - vec<4,T,0x2231> const zzwy, bbag, ppqt; - vec<4,T,0x2232> const zzwz, bbab, ppqp; - vec<4,T,0x2233> const zzww, bbaa, ppqq; - vec<4,T,0x2300> const zwxx, barr, pqss; - vec<4,T,0x2301> _____ zwxy, barg, pqst; - vec<4,T,0x2302> const zwxz, barb, pqsp; - vec<4,T,0x2303> const zwxw, bara, pqsq; - vec<4,T,0x2310> _____ zwyx, bagr, pqts; - vec<4,T,0x2311> const zwyy, bagg, pqtt; - vec<4,T,0x2312> const zwyz, bagb, pqtp; - vec<4,T,0x2313> const zwyw, baga, pqtq; - vec<4,T,0x2320> const zwzx, babr, pqps; - vec<4,T,0x2321> const zwzy, babg, pqpt; - vec<4,T,0x2322> const zwzz, babb, pqpp; - vec<4,T,0x2323> const zwzw, baba, pqpq; - vec<4,T,0x2330> const zwwx, baar, pqqs; - vec<4,T,0x2331> const zwwy, baag, pqqt; - vec<4,T,0x2332> const zwwz, baab, pqqp; - vec<4,T,0x2333> const zwww, baaa, pqqq; - vec<4,T,0x3000> const wxxx, arrr, qsss; - vec<4,T,0x3001> const wxxy, arrg, qsst; - vec<4,T,0x3002> const wxxz, arrb, qssp; - vec<4,T,0x3003> const wxxw, arra, qssq; - vec<4,T,0x3010> const wxyx, argr, qsts; - vec<4,T,0x3011> const wxyy, argg, qstt; - vec<4,T,0x3012> _____ wxyz, argb, qstp; - vec<4,T,0x3013> const wxyw, arga, qstq; - vec<4,T,0x3020> const wxzx, arbr, qsps; - vec<4,T,0x3021> _____ wxzy, arbg, qspt; - vec<4,T,0x3022> const wxzz, arbb, qspp; - vec<4,T,0x3023> const wxzw, arba, qspq; - vec<4,T,0x3030> const wxwx, arar, qsqs; - vec<4,T,0x3031> const wxwy, arag, qsqt; - vec<4,T,0x3032> const wxwz, arab, qsqp; - vec<4,T,0x3033> const wxww, araa, qsqq; - vec<4,T,0x3100> const wyxx, agrr, qtss; - vec<4,T,0x3101> const wyxy, agrg, qtst; - vec<4,T,0x3102> _____ wyxz, agrb, qtsp; - vec<4,T,0x3103> const wyxw, agra, qtsq; - vec<4,T,0x3110> const wyyx, aggr, qtts; - vec<4,T,0x3111> const wyyy, aggg, qttt; - vec<4,T,0x3112> const wyyz, aggb, qttp; - vec<4,T,0x3113> const wyyw, agga, qttq; - vec<4,T,0x3120> _____ wyzx, agbr, qtps; - vec<4,T,0x3121> const wyzy, agbg, qtpt; - vec<4,T,0x3122> const wyzz, agbb, qtpp; - vec<4,T,0x3123> const wyzw, agba, qtpq; - vec<4,T,0x3130> const wywx, agar, qtqs; - vec<4,T,0x3131> const wywy, agag, qtqt; - vec<4,T,0x3132> const wywz, agab, qtqp; - vec<4,T,0x3133> const wyww, agaa, qtqq; - vec<4,T,0x3200> const wzxx, abrr, qpss; - vec<4,T,0x3201> _____ wzxy, abrg, qpst; - vec<4,T,0x3202> const wzxz, abrb, qpsp; - vec<4,T,0x3203> const wzxw, abra, qpsq; - vec<4,T,0x3210> _____ wzyx, abgr, qpts; - vec<4,T,0x3211> const wzyy, abgg, qptt; - vec<4,T,0x3212> const wzyz, abgb, qptp; - vec<4,T,0x3213> const wzyw, abga, qptq; - vec<4,T,0x3220> const wzzx, abbr, qpps; - vec<4,T,0x3221> const wzzy, abbg, qppt; - vec<4,T,0x3222> const wzzz, abbb, qppp; - vec<4,T,0x3223> const wzzw, abba, qppq; - vec<4,T,0x3230> const wzwx, abar, qpqs; - vec<4,T,0x3231> const wzwy, abag, qpqt; - vec<4,T,0x3232> const wzwz, abab, qpqp; - vec<4,T,0x3233> const wzww, abaa, qpqq; - vec<4,T,0x3300> const wwxx, aarr, qqss; - vec<4,T,0x3301> const wwxy, aarg, qqst; - vec<4,T,0x3302> const wwxz, aarb, qqsp; - vec<4,T,0x3303> const wwxw, aara, qqsq; - vec<4,T,0x3310> const wwyx, aagr, qqts; - vec<4,T,0x3311> const wwyy, aagg, qqtt; - vec<4,T,0x3312> const wwyz, aagb, qqtp; - vec<4,T,0x3313> const wwyw, aaga, qqtq; - vec<4,T,0x3320> const wwzx, aabr, qqps; - vec<4,T,0x3321> const wwzy, aabg, qqpt; - vec<4,T,0x3322> const wwzz, aabb, qqpp; - vec<4,T,0x3323> const wwzw, aaba, qqpq; - vec<4,T,0x3330> const wwwx, aaar, qqqs; - vec<4,T,0x3331> const wwwy, aaag, qqqt; - vec<4,T,0x3332> const wwwz, aaab, qqqp; - vec<4,T,0x3333> const wwww, aaaa, qqqq; + vec_t const xx, rr, ss; + vec_t _____ xy, rg, st; + vec_t _____ xz, rb, sp; + vec_t _____ xw, ra, sq; + vec_t _____ yx, gr, ts; + vec_t const yy, gg, tt; + vec_t _____ yz, gb, tp; + vec_t _____ yw, ga, tq; + vec_t _____ zx, br, ps; + vec_t _____ zy, bg, pt; + vec_t const zz, bb, pp; + vec_t _____ zw, ba, pq; + vec_t _____ wx, ar, qs; + vec_t _____ wy, ag, qt; + vec_t _____ wz, ab, qp; + vec_t const ww, aa, qq; + + vec_t const xxx, rrr, sss; + vec_t const xxy, rrg, sst; + vec_t const xxz, rrb, ssp; + vec_t const xxw, rra, ssq; + vec_t const xyx, rgr, sts; + vec_t const xyy, rgg, stt; + vec_t _____ xyz, rgb, stp; + vec_t _____ xyw, rga, stq; + vec_t const xzx, rbr, sps; + vec_t _____ xzy, rbg, spt; + vec_t const xzz, rbb, spp; + vec_t _____ xzw, rba, spq; + vec_t const xwx, rar, sqs; + vec_t _____ xwy, rag, sqt; + vec_t _____ xwz, rab, sqp; + vec_t const xww, raa, sqq; + vec_t const yxx, grr, tss; + vec_t const yxy, grg, tst; + vec_t _____ yxz, grb, tsp; + vec_t _____ yxw, gra, tsq; + vec_t const yyx, ggr, tts; + vec_t const yyy, ggg, ttt; + vec_t const yyz, ggb, ttp; + vec_t const yyw, gga, ttq; + vec_t _____ yzx, gbr, tps; + vec_t const yzy, gbg, tpt; + vec_t const yzz, gbb, tpp; + vec_t _____ yzw, gba, tpq; + vec_t _____ ywx, gar, tqs; + vec_t const ywy, gag, tqt; + vec_t _____ ywz, gab, tqp; + vec_t const yww, gaa, tqq; + vec_t const zxx, brr, pss; + vec_t _____ zxy, brg, pst; + vec_t const zxz, brb, psp; + vec_t _____ zxw, bra, psq; + vec_t _____ zyx, bgr, pts; + vec_t const zyy, bgg, ptt; + vec_t const zyz, bgb, ptp; + vec_t _____ zyw, bga, ptq; + vec_t const zzx, bbr, pps; + vec_t const zzy, bbg, ppt; + vec_t const zzz, bbb, ppp; + vec_t const zzw, bba, ppq; + vec_t _____ zwx, bar, pqs; + vec_t _____ zwy, bag, pqt; + vec_t const zwz, bab, pqp; + vec_t const zww, baa, pqq; + vec_t const wxx, arr, qss; + vec_t _____ wxy, arg, qst; + vec_t _____ wxz, arb, qsp; + vec_t const wxw, ara, qsq; + vec_t _____ wyx, agr, qts; + vec_t const wyy, agg, qtt; + vec_t _____ wyz, agb, qtp; + vec_t const wyw, aga, qtq; + vec_t _____ wzx, abr, qps; + vec_t _____ wzy, abg, qpt; + vec_t const wzz, abb, qpp; + vec_t const wzw, aba, qpq; + vec_t const wwx, aar, qqs; + vec_t const wwy, aag, qqt; + vec_t const wwz, aab, qqp; + vec_t const www, aaa, qqq; + + vec_t const xxxx, rrrr, ssss; + vec_t const xxxy, rrrg, ssst; + vec_t const xxxz, rrrb, sssp; + vec_t const xxxw, rrra, sssq; + vec_t const xxyx, rrgr, ssts; + vec_t const xxyy, rrgg, sstt; + vec_t const xxyz, rrgb, sstp; + vec_t const xxyw, rrga, sstq; + vec_t const xxzx, rrbr, ssps; + vec_t const xxzy, rrbg, sspt; + vec_t const xxzz, rrbb, sspp; + vec_t const xxzw, rrba, sspq; + vec_t const xxwx, rrar, ssqs; + vec_t const xxwy, rrag, ssqt; + vec_t const xxwz, rrab, ssqp; + vec_t const xxww, rraa, ssqq; + vec_t const xyxx, rgrr, stss; + vec_t const xyxy, rgrg, stst; + vec_t const xyxz, rgrb, stsp; + vec_t const xyxw, rgra, stsq; + vec_t const xyyx, rggr, stts; + vec_t const xyyy, rggg, sttt; + vec_t const xyyz, rggb, sttp; + vec_t const xyyw, rgga, sttq; + vec_t const xyzx, rgbr, stps; + vec_t const xyzy, rgbg, stpt; + vec_t const xyzz, rgbb, stpp; + vec_t _____ xyzw, rgba, stpq; + vec_t const xywx, rgar, stqs; + vec_t const xywy, rgag, stqt; + vec_t _____ xywz, rgab, stqp; + vec_t const xyww, rgaa, stqq; + vec_t const xzxx, rbrr, spss; + vec_t const xzxy, rbrg, spst; + vec_t const xzxz, rbrb, spsp; + vec_t const xzxw, rbra, spsq; + vec_t const xzyx, rbgr, spts; + vec_t const xzyy, rbgg, sptt; + vec_t const xzyz, rbgb, sptp; + vec_t _____ xzyw, rbga, sptq; + vec_t const xzzx, rbbr, spps; + vec_t const xzzy, rbbg, sppt; + vec_t const xzzz, rbbb, sppp; + vec_t const xzzw, rbba, sppq; + vec_t const xzwx, rbar, spqs; + vec_t _____ xzwy, rbag, spqt; + vec_t const xzwz, rbab, spqp; + vec_t const xzww, rbaa, spqq; + vec_t const xwxx, rarr, sqss; + vec_t const xwxy, rarg, sqst; + vec_t const xwxz, rarb, sqsp; + vec_t const xwxw, rara, sqsq; + vec_t const xwyx, ragr, sqts; + vec_t const xwyy, ragg, sqtt; + vec_t _____ xwyz, ragb, sqtp; + vec_t const xwyw, raga, sqtq; + vec_t const xwzx, rabr, sqps; + vec_t _____ xwzy, rabg, sqpt; + vec_t const xwzz, rabb, sqpp; + vec_t const xwzw, raba, sqpq; + vec_t const xwwx, raar, sqqs; + vec_t const xwwy, raag, sqqt; + vec_t const xwwz, raab, sqqp; + vec_t const xwww, raaa, sqqq; + vec_t const yxxx, grrr, tsss; + vec_t const yxxy, grrg, tsst; + vec_t const yxxz, grrb, tssp; + vec_t const yxxw, grra, tssq; + vec_t const yxyx, grgr, tsts; + vec_t const yxyy, grgg, tstt; + vec_t const yxyz, grgb, tstp; + vec_t const yxyw, grga, tstq; + vec_t const yxzx, grbr, tsps; + vec_t const yxzy, grbg, tspt; + vec_t const yxzz, grbb, tspp; + vec_t _____ yxzw, grba, tspq; + vec_t const yxwx, grar, tsqs; + vec_t const yxwy, grag, tsqt; + vec_t _____ yxwz, grab, tsqp; + vec_t const yxww, graa, tsqq; + vec_t const yyxx, ggrr, ttss; + vec_t const yyxy, ggrg, ttst; + vec_t const yyxz, ggrb, ttsp; + vec_t const yyxw, ggra, ttsq; + vec_t const yyyx, gggr, ttts; + vec_t const yyyy, gggg, tttt; + vec_t const yyyz, gggb, tttp; + vec_t const yyyw, ggga, tttq; + vec_t const yyzx, ggbr, ttps; + vec_t const yyzy, ggbg, ttpt; + vec_t const yyzz, ggbb, ttpp; + vec_t const yyzw, ggba, ttpq; + vec_t const yywx, ggar, ttqs; + vec_t const yywy, ggag, ttqt; + vec_t const yywz, ggab, ttqp; + vec_t const yyww, ggaa, ttqq; + vec_t const yzxx, gbrr, tpss; + vec_t const yzxy, gbrg, tpst; + vec_t const yzxz, gbrb, tpsp; + vec_t _____ yzxw, gbra, tpsq; + vec_t const yzyx, gbgr, tpts; + vec_t const yzyy, gbgg, tptt; + vec_t const yzyz, gbgb, tptp; + vec_t const yzyw, gbga, tptq; + vec_t const yzzx, gbbr, tpps; + vec_t const yzzy, gbbg, tppt; + vec_t const yzzz, gbbb, tppp; + vec_t const yzzw, gbba, tppq; + vec_t _____ yzwx, gbar, tpqs; + vec_t const yzwy, gbag, tpqt; + vec_t const yzwz, gbab, tpqp; + vec_t const yzww, gbaa, tpqq; + vec_t const ywxx, garr, tqss; + vec_t const ywxy, garg, tqst; + vec_t _____ ywxz, garb, tqsp; + vec_t const ywxw, gara, tqsq; + vec_t const ywyx, gagr, tqts; + vec_t const ywyy, gagg, tqtt; + vec_t const ywyz, gagb, tqtp; + vec_t const ywyw, gaga, tqtq; + vec_t _____ ywzx, gabr, tqps; + vec_t const ywzy, gabg, tqpt; + vec_t const ywzz, gabb, tqpp; + vec_t const ywzw, gaba, tqpq; + vec_t const ywwx, gaar, tqqs; + vec_t const ywwy, gaag, tqqt; + vec_t const ywwz, gaab, tqqp; + vec_t const ywww, gaaa, tqqq; + vec_t const zxxx, brrr, psss; + vec_t const zxxy, brrg, psst; + vec_t const zxxz, brrb, pssp; + vec_t const zxxw, brra, pssq; + vec_t const zxyx, brgr, psts; + vec_t const zxyy, brgg, pstt; + vec_t const zxyz, brgb, pstp; + vec_t _____ zxyw, brga, pstq; + vec_t const zxzx, brbr, psps; + vec_t const zxzy, brbg, pspt; + vec_t const zxzz, brbb, pspp; + vec_t const zxzw, brba, pspq; + vec_t const zxwx, brar, psqs; + vec_t _____ zxwy, brag, psqt; + vec_t const zxwz, brab, psqp; + vec_t const zxww, braa, psqq; + vec_t const zyxx, bgrr, ptss; + vec_t const zyxy, bgrg, ptst; + vec_t const zyxz, bgrb, ptsp; + vec_t _____ zyxw, bgra, ptsq; + vec_t const zyyx, bggr, ptts; + vec_t const zyyy, bggg, pttt; + vec_t const zyyz, bggb, pttp; + vec_t const zyyw, bgga, pttq; + vec_t const zyzx, bgbr, ptps; + vec_t const zyzy, bgbg, ptpt; + vec_t const zyzz, bgbb, ptpp; + vec_t const zyzw, bgba, ptpq; + vec_t _____ zywx, bgar, ptqs; + vec_t const zywy, bgag, ptqt; + vec_t const zywz, bgab, ptqp; + vec_t const zyww, bgaa, ptqq; + vec_t const zzxx, bbrr, ppss; + vec_t const zzxy, bbrg, ppst; + vec_t const zzxz, bbrb, ppsp; + vec_t const zzxw, bbra, ppsq; + vec_t const zzyx, bbgr, ppts; + vec_t const zzyy, bbgg, pptt; + vec_t const zzyz, bbgb, pptp; + vec_t const zzyw, bbga, pptq; + vec_t const zzzx, bbbr, ppps; + vec_t const zzzy, bbbg, pppt; + vec_t const zzzz, bbbb, pppp; + vec_t const zzzw, bbba, pppq; + vec_t const zzwx, bbar, ppqs; + vec_t const zzwy, bbag, ppqt; + vec_t const zzwz, bbab, ppqp; + vec_t const zzww, bbaa, ppqq; + vec_t const zwxx, barr, pqss; + vec_t _____ zwxy, barg, pqst; + vec_t const zwxz, barb, pqsp; + vec_t const zwxw, bara, pqsq; + vec_t _____ zwyx, bagr, pqts; + vec_t const zwyy, bagg, pqtt; + vec_t const zwyz, bagb, pqtp; + vec_t const zwyw, baga, pqtq; + vec_t const zwzx, babr, pqps; + vec_t const zwzy, babg, pqpt; + vec_t const zwzz, babb, pqpp; + vec_t const zwzw, baba, pqpq; + vec_t const zwwx, baar, pqqs; + vec_t const zwwy, baag, pqqt; + vec_t const zwwz, baab, pqqp; + vec_t const zwww, baaa, pqqq; + vec_t const wxxx, arrr, qsss; + vec_t const wxxy, arrg, qsst; + vec_t const wxxz, arrb, qssp; + vec_t const wxxw, arra, qssq; + vec_t const wxyx, argr, qsts; + vec_t const wxyy, argg, qstt; + vec_t _____ wxyz, argb, qstp; + vec_t const wxyw, arga, qstq; + vec_t const wxzx, arbr, qsps; + vec_t _____ wxzy, arbg, qspt; + vec_t const wxzz, arbb, qspp; + vec_t const wxzw, arba, qspq; + vec_t const wxwx, arar, qsqs; + vec_t const wxwy, arag, qsqt; + vec_t const wxwz, arab, qsqp; + vec_t const wxww, araa, qsqq; + vec_t const wyxx, agrr, qtss; + vec_t const wyxy, agrg, qtst; + vec_t _____ wyxz, agrb, qtsp; + vec_t const wyxw, agra, qtsq; + vec_t const wyyx, aggr, qtts; + vec_t const wyyy, aggg, qttt; + vec_t const wyyz, aggb, qttp; + vec_t const wyyw, agga, qttq; + vec_t _____ wyzx, agbr, qtps; + vec_t const wyzy, agbg, qtpt; + vec_t const wyzz, agbb, qtpp; + vec_t const wyzw, agba, qtpq; + vec_t const wywx, agar, qtqs; + vec_t const wywy, agag, qtqt; + vec_t const wywz, agab, qtqp; + vec_t const wyww, agaa, qtqq; + vec_t const wzxx, abrr, qpss; + vec_t _____ wzxy, abrg, qpst; + vec_t const wzxz, abrb, qpsp; + vec_t const wzxw, abra, qpsq; + vec_t _____ wzyx, abgr, qpts; + vec_t const wzyy, abgg, qptt; + vec_t const wzyz, abgb, qptp; + vec_t const wzyw, abga, qptq; + vec_t const wzzx, abbr, qpps; + vec_t const wzzy, abbg, qppt; + vec_t const wzzz, abbb, qppp; + vec_t const wzzw, abba, qppq; + vec_t const wzwx, abar, qpqs; + vec_t const wzwy, abag, qpqt; + vec_t const wzwz, abab, qpqp; + vec_t const wzww, abaa, qpqq; + vec_t const wwxx, aarr, qqss; + vec_t const wwxy, aarg, qqst; + vec_t const wwxz, aarb, qqsp; + vec_t const wwxw, aara, qqsq; + vec_t const wwyx, aagr, qqts; + vec_t const wwyy, aagg, qqtt; + vec_t const wwyz, aagb, qqtp; + vec_t const wwyw, aaga, qqtq; + vec_t const wwzx, aabr, qqps; + vec_t const wwzy, aabg, qqpt; + vec_t const wwzz, aabb, qqpp; + vec_t const wwzw, aaba, qqpq; + vec_t const wwwx, aaar, qqqs; + vec_t const wwwy, aaag, qqqt; + vec_t const wwwz, aaab, qqqp; + vec_t const wwww, aaaa, qqqq; #endif }; }; /* * Operators for swizzled vectors. Since template deduction cannot be - * done for two arbitrary vec<> values, we help the compiler understand + * done for two arbitrary vec_t<> values, we help the compiler understand * the expected type. */ -template -static inline bool operator ==(vec const &a, - vec const &b) +template +static inline bool operator ==(vec_t const &a, + vec_t const &b) { for (size_t i = 0; i < N; ++i) if (!(a[i] == b[i])) @@ -926,9 +927,9 @@ static inline bool operator ==(vec const &a, return true; } -template -static inline bool operator !=(vec const &a, - vec const &b) +template +static inline bool operator !=(vec_t const &a, + vec_t const &b) { for (size_t i = 0; i < N; ++i) if (a[i] != b[i]) @@ -937,17 +938,17 @@ static inline bool operator !=(vec const &a, } #define LOL_SWIZZLE_V_VV_OP(op) \ - template \ - inline vec operator op(vec const &a, \ - vec const &b) \ + template \ + inline vec_t operator op(vec_t const &a, \ + vec_t const &b) \ { \ - return vec(a) op vec(b); \ + return vec_t(a) op vec_t(b); \ } \ \ - template \ - inline vec operator op(vec a, T const &b) \ + template \ + inline vec_t operator op(vec_t a, T const &b) \ { \ - return vec(a) op b; \ + return vec_t(a) op b; \ } LOL_SWIZZLE_V_VV_OP(+) @@ -957,47 +958,47 @@ LOL_SWIZZLE_V_VV_OP(/) #undef LOL_SWIZZLE_V_VV_OP -template -static inline vec operator *(T const &val, vec const &a) +template +static inline vec_t operator *(T const &val, vec_t const &a) { - vec ret; + vec_t ret; for (size_t i = 0; i < N; ++i) ret[i] = val * a[i]; return ret; } /* - * vec min|max|fmod(vec, vec|scalar) - * vec min|max|fmod(scalar, vec) + * vec_t min|max|fmod(vec_t, vec_t|scalar) + * vec_t min|max|fmod(scalar, vec_t) */ #define LOL_SWIZZLE_V_VV_FUN(fun) \ - template \ - inline vec fun(vec const &a, \ - vec const &b) \ + template \ + inline vec_t fun(vec_t const &a, \ + vec_t const &b) \ { \ using lol::fun; \ - vec ret; \ + vec_t ret; \ for (size_t i = 0; i < N; ++i) \ ret[i] = fun(a[i], b[i]); \ return ret; \ } \ \ - template \ - inline vec fun(vec const &a, T const &b) \ + template \ + inline vec_t fun(vec_t const &a, T const &b) \ { \ using lol::fun; \ - vec ret; \ + vec_t ret; \ for (size_t i = 0; i < N; ++i) \ ret[i] = fun(a[i], b); \ return ret; \ } \ \ - template \ - inline vec fun(T const &a, vec const &b) \ + template \ + inline vec_t fun(T const &a, vec_t const &b) \ { \ using lol::fun; \ - vec ret; \ + vec_t ret; \ for (size_t i = 0; i < N; ++i) \ ret[i] = fun(a, b[i]); \ return ret; \ @@ -1010,61 +1011,61 @@ LOL_SWIZZLE_V_VV_FUN(fmod) #undef LOL_SWIZZLE_V_VV_FUN /* - * vec clamp(vec, vec, vec) - * vec clamp(vec, scalar, vec) - * vec clamp(vec, vec, scalar) - * vec clamp(vec, scalar, scalar) + * vec_t clamp(vec_t, vec_t, vec_t) + * vec_t clamp(vec_t, scalar, vec_t) + * vec_t clamp(vec_t, vec_t, scalar) + * vec_t clamp(vec_t, scalar, scalar) */ -template -static inline vec clamp(vec const &x, - vec const &a, - vec const &b) +template +static inline vec_t clamp(vec_t const &x, + vec_t const &a, + vec_t const &b) { return max(min(x, b), a); } -template -static inline vec clamp(vec const &x, - T const &a, - vec const &b) +template +static inline vec_t clamp(vec_t const &x, + T const &a, + vec_t const &b) { return max(min(x, b), a); } -template -static inline vec clamp(vec const &x, - vec const &a, - T const &b) +template +static inline vec_t clamp(vec_t const &x, + vec_t const &a, + T const &b) { return max(min(x, b), a); } -template -static inline vec clamp(vec const &x, - T const &a, - T const &b) +template +static inline vec_t clamp(vec_t const &x, + T const &a, + T const &b) { return max(min(x, b), a); } /* - * vec mix(vec, vec, vec) - * vec mix(vec, vec, scalar) + * vec_t mix(vec_t, vec_t, vec_t) + * vec_t mix(vec_t, vec_t, scalar) */ -template -static inline vec mix(vec const &x, - vec const &y, - vec const &a) +template +static inline vec_t mix(vec_t const &x, + vec_t const &y, + vec_t const &a) { return x + a * (y - x); } -template -static inline vec mix(vec const &x, - vec const &y, - T const &a) +template +static inline vec_t mix(vec_t const &x, + vec_t const &y, + T const &a) { return x + a * (y - x); } @@ -1073,8 +1074,9 @@ static inline vec mix(vec const &x, * Some GLSL-like functions. */ -template -static inline T dot(vec const &a, vec const &b) +template +static inline T dot(vec_t const &a, + vec_t const &b) { T ret(0); for (size_t i = 0; i < N; ++i) @@ -1082,74 +1084,75 @@ static inline T dot(vec const &a, vec const &b) return ret; } -template -static inline T sqlength(vec const &a) +template +static inline T sqlength(vec_t const &a) { return dot(a, a); } -template -static inline T length(vec const &a) +template +static inline T length(vec_t const &a) { /* FIXME: this is not very nice */ return (T)sqrt((double)sqlength(a)); } -template -static inline vec lerp(vec const &a, - vec const &b, - T const &s) +template +static inline vec_t lerp(vec_t const &a, + vec_t const &b, + T const &s) { - vec ret; + vec_t ret; for (size_t i = 0; i < N; ++i) ret[i] = a[i] + s * (b[i] - a[i]); return ret; } -template -static inline T distance(vec const &a, vec const &b) +template +static inline T distance(vec_t const &a, + vec_t const &b) { return length(a - b); } -template -static inline vec fract(vec const &a) +template +static inline vec_t fract(vec_t const &a) { - vec ret; + vec_t ret; for (size_t i = 0; i < N; ++i) ret[i] = fract(a[i]); return ret; } -template -static inline vec normalize(vec const &a) +template +static inline vec_t normalize(vec_t const &a) { T norm = (T)length(a); - return norm ? a / norm : vec(T(0)); + return norm ? a / norm : vec_t(T(0)); } -template -static inline vec abs(vec const &a) +template +static inline vec_t abs(vec_t const &a) { - vec ret; + vec_t ret; for (size_t i = 0; i < N; ++i) ret[i] = lol::abs(a[i]); return ret; } -template -static inline vec degrees(vec const &a) +template +static inline vec_t degrees(vec_t const &a) { - vec ret; + vec_t ret; for (size_t i = 0; i < N; ++i) ret[i] = lol::degrees(a[i]); return ret; } -template -static inline vec radians(vec const &a) +template +static inline vec_t radians(vec_t const &a) { - vec ret; + vec_t ret; for (size_t i = 0; i < N; ++i) ret[i] = lol::radians(a[i]); return ret; @@ -1161,7 +1164,7 @@ static inline vec radians(vec const &a) #if LOL_FEATURE_CXX11_RELAXED_UNIONS template -inline vec& vec::operator =(vec that) +inline vec_t& vec_t::operator =(vec_t that) { for (int i = 0; i < N; ++i) (*this)[i] = that[i]; diff --git a/src/math/constants.cpp b/src/math/constants.cpp index 9b07fcf6..05e9809e 100644 --- a/src/math/constants.cpp +++ b/src/math/constants.cpp @@ -16,45 +16,45 @@ namespace lol { -#define LOL_VEC_2_CONST(type, name, a, b) \ +#define LOL_VEC_2_CONST(T, name, a, b) \ template<> \ - vec<2,type> const vec<2,type>::name = vec<2,type>((type)a, (type)b); + vec_t const vec_t::name = vec_t((T)a, (T)b); -#define LOL_VEC_3_CONST(type, name, a, b, c) \ +#define LOL_VEC_3_CONST(T, name, a, b, c) \ template<> \ - vec<3,type> const vec<3,type>::name = vec<3,type>((type)a, (type)b, (type)c); + vec_t const vec_t::name = vec_t((T)a, (T)b, (T)c); -#define LOL_VEC_4_CONST(type, name, a, b, c, d) \ +#define LOL_VEC_4_CONST(T, name, a, b, c, d) \ template<> \ - vec<4,type> const vec<4,type>::name = vec<4,type>((type)a, (type)b, (type)c, (type)d); + vec_t const vec_t::name = vec_t((T)a, (T)b, (T)c, (T)d); -#define LOL_MAT_CONST(type, name, a) \ +#define LOL_MAT_CONST(T, name, a) \ template<> \ - mat<2,2,type> const mat<2,2,type>::name = mat<2,2,type>((type)a); \ + mat_t const mat_t::name = mat_t((T)a); \ \ template<> \ - mat<3,3,type> const mat<3,3,type>::name = mat<3,3,type>((type)a); \ + mat_t const mat_t::name = mat_t((T)a); \ \ template<> \ - mat<4,4,type> const mat<4,4,type>::name = mat<4,4,type>((type)a); + mat_t const mat_t::name = mat_t((T)a); -#define LOL_ALL_CONST_INNER(type) \ - LOL_VEC_2_CONST(type, zero, 0, 0) \ - LOL_VEC_2_CONST(type, axis_x, 1, 0) \ - LOL_VEC_2_CONST(type, axis_y, 0, 1) \ +#define LOL_ALL_CONST_INNER(T) \ + LOL_VEC_2_CONST(T, zero, 0, 0) \ + LOL_VEC_2_CONST(T, axis_x, 1, 0) \ + LOL_VEC_2_CONST(T, axis_y, 0, 1) \ \ - LOL_VEC_3_CONST(type, zero, 0, 0, 0) \ - LOL_VEC_3_CONST(type, axis_x, 1, 0, 0) \ - LOL_VEC_3_CONST(type, axis_y, 0, 1, 0) \ - LOL_VEC_3_CONST(type, axis_z, 0, 0, 1) \ + LOL_VEC_3_CONST(T, zero, 0, 0, 0) \ + LOL_VEC_3_CONST(T, axis_x, 1, 0, 0) \ + LOL_VEC_3_CONST(T, axis_y, 0, 1, 0) \ + LOL_VEC_3_CONST(T, axis_z, 0, 0, 1) \ \ - LOL_VEC_4_CONST(type, zero, 0, 0, 0, 0) \ - LOL_VEC_4_CONST(type, axis_x, 1, 0, 0, 0) \ - LOL_VEC_4_CONST(type, axis_y, 0, 1, 0, 0) \ - LOL_VEC_4_CONST(type, axis_z, 0, 0, 1, 0) \ - LOL_VEC_4_CONST(type, axis_w, 0, 0, 0, 1) \ + LOL_VEC_4_CONST(T, zero, 0, 0, 0, 0) \ + LOL_VEC_4_CONST(T, axis_x, 1, 0, 0, 0) \ + LOL_VEC_4_CONST(T, axis_y, 0, 1, 0, 0) \ + LOL_VEC_4_CONST(T, axis_z, 0, 0, 1, 0) \ + LOL_VEC_4_CONST(T, axis_w, 0, 0, 0, 1) \ \ - LOL_MAT_CONST(type, identity, 1) + LOL_MAT_CONST(T, identity, 1) LOL_ALL_CONST_INNER(half) LOL_ALL_CONST_INNER(float) diff --git a/src/math/vector.cpp b/src/math/vector.cpp index 1cb71ba4..69524d61 100644 --- a/src/math/vector.cpp +++ b/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::mat(quat const &q) +template<> mat3::mat_t(quat const &q) { float n = norm(q); @@ -405,7 +405,7 @@ template<> mat3::mat(quat const &q) (*this)[2][2] = 1.0f - s * (q.x * q.x + q.y * q.y); } -template<> mat4::mat(quat const &q) +template<> mat4::mat_t(quat const &q) { *this = mat4(mat3(q), 1.f); } @@ -448,12 +448,12 @@ static inline void MatrixToQuat(quat &that, mat3 const &m) } } -template<> quat::Quat(mat3 const &m) +template<> quat::quat_t(mat3 const &m) { MatrixToQuat(*this, m); } -template<> quat::Quat(mat4 const &m) +template<> quat::quat_t(mat4 const &m) { MatrixToQuat(*this, mat3(m)); } diff --git a/test/physics/easyphysics.cpp b/test/physics/easyphysics.cpp index 976554b7..99ca411a 100644 --- a/test/physics/easyphysics.cpp +++ b/test/physics/easyphysics.cpp @@ -166,7 +166,7 @@ void EasyPhysic::BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol { mat4 ThisMatrixLoc = NewMatrixLoc * inverse(PreviousMatrixLoc) * lol::mat4::translate(m_local_to_world[3].xyz); mat4 ThisMatrixRot = NewMatrixRot * inverse(PreviousMatrixRot) * lol::mat4(lol::quat(m_local_to_world)); - SetTransform(ThisMatrixLoc[3].xyz, lol::mat4(lol::quat(ThisMatrixRot))); + SetTransform(ThisMatrixLoc[3].xyz, lol::quat(ThisMatrixRot)); } }