Sfoglia il codice sorgente

math: add a new sqt type for scale/rotation/translation transforms.

undefined
Sam Hocevar 9 anni fa
parent
commit
7166760eaf
5 ha cambiato i file con 55 aggiunte e 2 eliminazioni
  1. +2
    -0
      src/lol/base/types.h
  2. +50
    -0
      src/lol/math/transform.h
  3. +1
    -1
      src/t/Makefile.am
  4. +1
    -0
      src/t/test-math.vcxproj
  5. +1
    -1
      tools/vimlol/vimlol.vim

+ 2
- 0
src/lol/base/types.h Vedi File

@@ -40,6 +40,7 @@ template<typename T, int COLS, int ROWS> struct mat_t;
template<typename T> struct cmplx_t;
template<typename T> struct quat_t;
template<typename T> struct dualquat_t;
template<typename T> 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


+ 50
- 0
src/lol/math/transform.h Vedi File

@@ -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<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
*/


+ 1
- 1
src/t/Makefile.am Vedi File

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



+ 1
- 0
src/t/test-math.vcxproj Vedi File

@@ -51,6 +51,7 @@
<ClCompile Include="math\rand.cpp" />
<ClCompile Include="math\real.cpp" />
<ClCompile Include="math\rotation.cpp" />
<ClCompile Include="math\sqt.cpp" />
<ClCompile Include="math\trig.cpp" />
<ClCompile Include="math\vector.cpp" />
</ItemGroup>


+ 1
- 1
tools/vimlol/vimlol.vim Vedi File

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


Caricamento…
Annulla
Salva