@@ -40,6 +40,7 @@ template<typename T, int COLS, int ROWS> struct mat_t; | |||||
template<typename T> struct cmplx_t; | template<typename T> struct cmplx_t; | ||||
template<typename T> struct quat_t; | template<typename T> struct quat_t; | ||||
template<typename T> struct dualquat_t; | template<typename T> struct dualquat_t; | ||||
template<typename T> struct sqt_t; | |||||
/* | /* | ||||
* Generic GLSL-like type names | * Generic GLSL-like type names | ||||
@@ -89,6 +90,7 @@ _T(mat_t<, _C 4 _C 3>, mat4x3) | |||||
_T(cmplx_t<, >, cmplx) | _T(cmplx_t<, >, cmplx) | ||||
_T(quat_t<, >, quat) | _T(quat_t<, >, quat) | ||||
_T(dualquat_t<, >, dualquat) | _T(dualquat_t<, >, dualquat) | ||||
_T(sqt_t<, >, sqt) | |||||
#undef _C | #undef _C | ||||
#undef _T | #undef _T | ||||
@@ -250,6 +250,56 @@ static_assert(sizeof(f16quat) == 8, "sizeof(f16quat) == 8"); | |||||
static_assert(sizeof(quat) == 16, "sizeof(quat) == 16"); | static_assert(sizeof(quat) == 16, "sizeof(quat) == 16"); | ||||
static_assert(sizeof(dquat) == 32, "sizeof(dquat) == 32"); | static_assert(sizeof(dquat) == 32, "sizeof(dquat) == 32"); | ||||
/* | |||||
* SQT transforms: scale / rotation / translation | |||||
*/ | |||||
template<typename T> | |||||
struct sqt_t | |||||
{ | |||||
/* Default constructor and copy constructor */ | |||||
inline constexpr sqt_t() : s(), q(), t() {} | |||||
inline constexpr sqt_t(sqt_t<T> const &other) | |||||
: q(other.q), t(other.t), s(other.s) {} | |||||
/* Explicit constructor for type conversion */ | |||||
template<typename U> | |||||
explicit inline constexpr sqt_t(sqt_t<U> const &other) | |||||
: q(other.q), t(other.t), s(other.s) {} | |||||
/* Various explicit constructors */ | |||||
inline constexpr sqt_t(T const &s_, | |||||
quat_t<T> const &q_, | |||||
vec_t<T,3> const &t_) | |||||
: s(s_), q(q_), t(t_) {} | |||||
inline vec_t<T,3> transform(vec_t<T,3> const &v) const | |||||
{ | |||||
return t + q.transform(s * v); | |||||
} | |||||
inline vec_t<T,4> transform(vec_t<T,4> const &v) const | |||||
{ | |||||
// XXX: needs serious testing | |||||
vec_t<T,4> tmp = q.transform(vec_t<T,4>(s * v.xyz, v.w)); | |||||
return vec_t<T,4>(tmp.xyz, 0.f) + vec_t<T,4>(t, 1.f) * tmp.w; | |||||
} | |||||
inline vec_t<T,3> operator *(vec_t<T,3> const &v) const | |||||
{ | |||||
return transform(v); | |||||
} | |||||
inline vec_t<T,4> operator *(vec_t<T,4> const &v) const | |||||
{ | |||||
return transform(v); | |||||
} | |||||
quat_t<T> q; | |||||
vec_t<T,3> t; | |||||
T s; | |||||
}; | |||||
/* | /* | ||||
* Common operations on transforms | * Common operations on transforms | ||||
*/ | */ | ||||
@@ -21,7 +21,7 @@ test_math_SOURCES = test-common.cpp \ | |||||
math/cmplx.cpp math/half.cpp math/interp.cpp math/matrix.cpp \ | math/cmplx.cpp math/half.cpp math/interp.cpp math/matrix.cpp \ | ||||
math/quat.cpp math/rand.cpp math/real.cpp math/rotation.cpp \ | math/quat.cpp math/rand.cpp math/real.cpp math/rotation.cpp \ | ||||
math/trig.cpp math/vector.cpp math/polynomial.cpp math/noise/simplex.cpp \ | math/trig.cpp math/vector.cpp math/polynomial.cpp math/noise/simplex.cpp \ | ||||
math/bigint.cpp | |||||
math/bigint.cpp math/sqt.cpp | |||||
test_math_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/tools/lolunit | test_math_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/tools/lolunit | ||||
test_math_DEPENDENCIES = @LOL_DEPS@ | test_math_DEPENDENCIES = @LOL_DEPS@ | ||||
@@ -51,6 +51,7 @@ | |||||
<ClCompile Include="math\rand.cpp" /> | <ClCompile Include="math\rand.cpp" /> | ||||
<ClCompile Include="math\real.cpp" /> | <ClCompile Include="math\real.cpp" /> | ||||
<ClCompile Include="math\rotation.cpp" /> | <ClCompile Include="math\rotation.cpp" /> | ||||
<ClCompile Include="math\sqt.cpp" /> | |||||
<ClCompile Include="math\trig.cpp" /> | <ClCompile Include="math\trig.cpp" /> | ||||
<ClCompile Include="math\vector.cpp" /> | <ClCompile Include="math\vector.cpp" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
@@ -23,7 +23,7 @@ au Syntax cpp | |||||
" GLSL types and the Lol Engine extensions | " GLSL types and the Lol Engine extensions | ||||
au Syntax cpp | au Syntax cpp | ||||
\ syn match cType | \ syn match cType | ||||
\ "\<\(f16\|\|f64\|f128\|r\|[iu]\(8\|16\|\|64\)\)\(vec\([23456789]\|1[012]\)\|cmplx\|quat\|dualquat\|mat\([234]\|2x3\|3x2\|3x4\|4x3\|2x4\|4x2\)\)\>" | |||||
\ "\<\(f16\|\|f64\|f128\|r\|[iu]\(8\|16\|\|64\)\)\(vec\([23456789]\|1[012]\)\|cmplx\|quat\|dualquat\|sqt\|mat\([234]\|2x3\|3x2\|3x4\|4x3\|2x4\|4x2\)\)\>" | |||||
" HLSL types and the Lol Engine extensions | " HLSL types and the Lol Engine extensions | ||||
au Syntax cpp | au Syntax cpp | ||||