Browse Source

math: add vec5, vec6, etc. types up to 12 for convenience.

undefined
Sam Hocevar 10 years ago
parent
commit
d812101ae5
3 changed files with 48 additions and 3 deletions
  1. +24
    -0
      src/lol/base/types.h
  2. +21
    -0
      src/lol/math/vector.h
  3. +3
    -3
      tools/vimlol/vimlol.vim

+ 24
- 0
src/lol/base/types.h View File

@@ -65,6 +65,14 @@ template<typename T> struct dualquat_t;
_T(vec_t<, _C 2>, vec2)
_T(vec_t<, _C 3>, vec3)
_T(vec_t<, _C 4>, vec4)
_T(vec_t<, _C 5>, vec5)
_T(vec_t<, _C 6>, vec6)
_T(vec_t<, _C 7>, vec7)
_T(vec_t<, _C 8>, vec8)
_T(vec_t<, _C 9>, vec9)
_T(vec_t<, _C 10>, vec10)
_T(vec_t<, _C 11>, vec11)
_T(vec_t<, _C 12>, vec12)

_T(mat_t<, _C 2 _C 2>, mat2)
_T(mat_t<, _C 3 _C 3>, mat3)
@@ -91,6 +99,14 @@ _T(dualquat_t<, >, dualquat)
typedef vec2 float2;
typedef vec3 float3;
typedef vec4 float4;
typedef vec5 float5;
typedef vec6 float6;
typedef vec7 float7;
typedef vec8 float8;
typedef vec9 float9;
typedef vec10 float10;
typedef vec11 float11;
typedef vec12 float12;
typedef mat2 float2x2;
typedef mat3 float3x3;
typedef mat4 float4x4;
@@ -117,6 +133,14 @@ typedef f16mat4x3 half4x3;
typedef ivec2 int2;
typedef ivec3 int3;
typedef ivec4 int4;
typedef ivec5 int5;
typedef ivec6 int6;
typedef ivec7 int7;
typedef ivec8 int8;
typedef ivec9 int9;
typedef ivec10 int10;
typedef ivec11 int11;
typedef ivec12 int12;
typedef imat2 int2x2;
typedef imat3 int3x3;
typedef imat4 int4x4;


+ 21
- 0
src/lol/math/vector.h View File

@@ -20,6 +20,7 @@
#include <lol/math/ops.h>

#include <ostream>
#include <type_traits>

namespace lol
{
@@ -118,6 +119,14 @@ struct vec_t<T, N, FULL_SWIZZLE>
}
inline ~vec_t() {}

/* Explicit constructor that takes exactly N arguments thanks to SFINAE. */
template<typename... ARGS>
explicit inline vec_t(typename std::enable_if<sizeof...(ARGS) == N - 1, T>
::type const &x, ARGS... args)
{
internal_init(m_data, x, args...);
}

/* Explicit constructor for type conversion */
template<typename U>
explicit inline vec_t(vec_t<U, N> const &v)
@@ -148,6 +157,18 @@ struct vec_t<T, N, FULL_SWIZZLE>
inline T const& operator[](size_t n) const { return m_data[n]; }

private:
template<typename... ARGS>
static inline void internal_init(T *data, T const &x, ARGS... args)
{
*data++ = x;
internal_init(data, args...);
}

static inline void internal_init(T *data)
{
UNUSED(data);
}

T m_data[count];
};



+ 3
- 3
tools/vimlol/vimlol.vim View File

@@ -23,12 +23,12 @@ 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[234]\|cmplx\|quat\|mat\([234]\|2x3\|3x2\|3x4\|4x3\|2x4\|4x2\)\)\>"
\ "\<\(f16\|\|f64\|f128\|r\|[iu]\(8\|16\|\|64\)\)\(vec\([23456789]\|1[012]\)\|cmplx\|quat\|dualquat\|mat\([234]\|2x3\|3x2\|3x4\|4x3\|2x4\|4x2\)\)\>"

" HLSL types
" HLSL types and the Lol Engine extensions
au Syntax cpp
\ syn match cType
\ "\<\(int\|half\|float\)[234]\(\|x[234]\)\>"
\ "\<\(int\|half\|float\)\([23456789]\|1[012]\|[234]x[234]\)\>"

" More GLSL-like types from the Lol Engine
au Syntax cpp


Loading…
Cancel
Save