diff --git a/src/lol/base/types.h b/src/lol/base/types.h index def8769d..df43c74d 100644 --- a/src/lol/base/types.h +++ b/src/lol/base/types.h @@ -40,6 +40,7 @@ template struct mat_t; template struct cmplx_t; template struct quat_t; template struct dualquat_t; +template struct sqt_t; /* * Generic GLSL-like type names @@ -89,6 +90,7 @@ _T(mat_t<, _C 4 _C 3>, mat4x3) _T(cmplx_t<, >, cmplx) _T(quat_t<, >, quat) _T(dualquat_t<, >, dualquat) +_T(sqt_t<, >, sqt) #undef _C #undef _T diff --git a/src/lol/math/transform.h b/src/lol/math/transform.h index 5071a20f..2d2fd32b 100644 --- a/src/lol/math/transform.h +++ b/src/lol/math/transform.h @@ -250,6 +250,56 @@ static_assert(sizeof(f16quat) == 8, "sizeof(f16quat) == 8"); static_assert(sizeof(quat) == 16, "sizeof(quat) == 16"); static_assert(sizeof(dquat) == 32, "sizeof(dquat) == 32"); +/* + * SQT transforms: scale / rotation / translation + */ + +template +struct sqt_t +{ + /* Default constructor and copy constructor */ + inline constexpr sqt_t() : s(), q(), t() {} + inline constexpr sqt_t(sqt_t const &other) + : q(other.q), t(other.t), s(other.s) {} + + /* Explicit constructor for type conversion */ + template + explicit inline constexpr sqt_t(sqt_t const &other) + : q(other.q), t(other.t), s(other.s) {} + + /* Various explicit constructors */ + inline constexpr sqt_t(T const &s_, + quat_t const &q_, + vec_t const &t_) + : s(s_), q(q_), t(t_) {} + + inline vec_t transform(vec_t const &v) const + { + return t + q.transform(s * v); + } + + inline vec_t transform(vec_t const &v) const + { + // XXX: needs serious testing + vec_t tmp = q.transform(vec_t(s * v.xyz, v.w)); + return vec_t(tmp.xyz, 0.f) + vec_t(t, 1.f) * tmp.w; + } + + inline vec_t operator *(vec_t const &v) const + { + return transform(v); + } + + inline vec_t operator *(vec_t const &v) const + { + return transform(v); + } + + quat_t q; + vec_t t; + T s; +}; + /* * Common operations on transforms */ diff --git a/src/t/Makefile.am b/src/t/Makefile.am index 60c1109f..d379f835 100644 --- a/src/t/Makefile.am +++ b/src/t/Makefile.am @@ -21,7 +21,7 @@ test_math_SOURCES = test-common.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/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_DEPENDENCIES = @LOL_DEPS@ diff --git a/src/t/test-math.vcxproj b/src/t/test-math.vcxproj index 88f538b5..d99663c4 100644 --- a/src/t/test-math.vcxproj +++ b/src/t/test-math.vcxproj @@ -51,6 +51,7 @@ + diff --git a/tools/vimlol/vimlol.vim b/tools/vimlol/vimlol.vim index f3e9b4e0..bf58cc85 100644 --- a/tools/vimlol/vimlol.vim +++ b/tools/vimlol/vimlol.vim @@ -23,7 +23,7 @@ au Syntax cpp " GLSL types and the Lol Engine extensions au Syntax cpp \ 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 au Syntax cpp