Skip to content

Commit

Permalink
Use initializer lists for matrix constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Groovounet committed Jul 10, 2018
1 parent d746c1e commit dee806e
Show file tree
Hide file tree
Showing 11 changed files with 1,025 additions and 475 deletions.
2 changes: 1 addition & 1 deletion glm/detail/setup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@
#elif (GLM_LANG & GLM_LANG_CXX14_FLAG) && (GLM_ARCH == GLM_ARCH_PURE)
# define GLM_HAS_CONSTEXPR_CXX14 1
#else
# define GLM_HAS_CONSTEXPR_CXX14 ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (GLM_ARCH == GLM_ARCH_PURE) && (\
# define GLM_HAS_CONSTEXPR_CXX14 ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (GLM_ARCH == GLM_ARCH_PURE) && GLM_HAS_INITIALIZER_LISTS && (\
((GLM_COMPILER & GLM_COMPILER_GCC) && (GLM_COMPILER >= GLM_COMPILER_GCC50)) || \
((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_COMPILER >= GLM_COMPILER_INTEL17)) || \
((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC15))))
Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_mat2x2.inl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ namespace glm
# endif
{
# if !GLM_HAS_INITIALIZER_LISTS
this->value[0] = m.value[0];
this->value[1] = m.value[1];
this->value[0] = m[0];
this->value[1] = m[1];
# endif
}

Expand Down
126 changes: 98 additions & 28 deletions glm/detail/type_mat2x3.inl
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ namespace glm

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 3, T, Q>::mat(T scalar)
# if GLM_HAS_INITIALIZER_LISTS
: value{col_type(scalar, 0, 0), col_type(0, scalar, 0)}
# endif
{
this->value[0] = col_type(scalar, 0, 0);
this->value[1] = col_type(0, scalar, 0);
# if !GLM_HAS_INITIALIZER_LISTS
this->value[0] = col_type(scalar, 0, 0);
this->value[1] = col_type(0, scalar, 0);
# endif
}

template<typename T, qualifier Q>
Expand All @@ -45,16 +50,26 @@ namespace glm
T x0, T y0, T z0,
T x1, T y1, T z1
)
# if GLM_HAS_INITIALIZER_LISTS
: value{col_type(x0, y0, z0), col_type(x1, y1, z1)}
# endif
{
this->value[0] = col_type(x0, y0, z0);
this->value[1] = col_type(x1, y1, z1);
# if !GLM_HAS_INITIALIZER_LISTS
this->value[0] = col_type(x0, y0, z0);
this->value[1] = col_type(x1, y1, z1);
# endif
}

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 3, T, Q>::mat(col_type const& v0, col_type const& v1)
# if GLM_HAS_INITIALIZER_LISTS
: value{col_type(v0), col_type(v1)}
# endif
{
this->value[0] = v0;
this->value[1] = v1;
# if !GLM_HAS_INITIALIZER_LISTS
this->value[0] = col_type(v0);
this->value[1] = col_type(v1);
# endif
}

// -- Conversion constructors --
Expand All @@ -68,83 +83,138 @@ namespace glm
X1 x1, Y1 y1, Z1 z1,
X2 x2, Y2 y2, Z2 z2
)
# if GLM_HAS_INITIALIZER_LISTS
: value{col_type(static_cast<T>(x1), value_type(y1), value_type(z1)), col_type(static_cast<T>(x2), value_type(y2), value_type(z2))}
# endif
{
this->value[0] = col_type(static_cast<T>(x1), value_type(y1), value_type(z1));
this->value[1] = col_type(static_cast<T>(x2), value_type(y2), value_type(z2));
# if !GLM_HAS_INITIALIZER_LISTS
this->value[0] = col_type(static_cast<T>(x1), value_type(y1), value_type(z1));
this->value[1] = col_type(static_cast<T>(x2), value_type(y2), value_type(z2));
# endif
}

template<typename T, qualifier Q>
template<typename V1, typename V2>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 3, T, Q>::mat(vec<3, V1, Q> const& v1, vec<3, V2, Q> const& v2)
# if GLM_HAS_INITIALIZER_LISTS
: value{col_type(v1), col_type(v2)}
# endif
{
this->value[0] = col_type(v1);
this->value[1] = col_type(v2);
# if !GLM_HAS_INITIALIZER_LISTS
this->value[0] = col_type(v1);
this->value[1] = col_type(v2);
# endif
}

// -- Matrix conversions --

template<typename T, qualifier Q>
template<typename U, qualifier P>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 3, T, Q>::mat(mat<2, 3, U, P> const& m)
# if GLM_HAS_INITIALIZER_LISTS
: value{col_type(m[0]), col_type(m[1])}
# endif
{
this->value[0] = col_type(m[0]);
this->value[1] = col_type(m[1]);
# if !GLM_HAS_INITIALIZER_LISTS
this->value[0] = col_type(m[0]);
this->value[1] = col_type(m[1]);
# endif
}

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 3, T, Q>::mat(mat<2, 2, T, Q> const& m)
# if GLM_HAS_INITIALIZER_LISTS
: value{col_type(m[0], 0), col_type(m[1], 0)}
# endif
{
this->value[0] = col_type(m[0], 0);
this->value[1] = col_type(m[1], 0);
# if !GLM_HAS_INITIALIZER_LISTS
this->value[0] = col_type(m[0], 0);
this->value[1] = col_type(m[1], 0);
# endif
}

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 3, T, Q>::mat(mat<3, 3, T, Q> const& m)
# if GLM_HAS_INITIALIZER_LISTS
: value{col_type(m[0]), col_type(m[1])}
# endif
{
this->value[0] = col_type(m[0]);
this->value[1] = col_type(m[1]);
# if !GLM_HAS_INITIALIZER_LISTS
this->value[0] = col_type(m[0]);
this->value[1] = col_type(m[1]);
# endif
}

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 3, T, Q>::mat(mat<4, 4, T, Q> const& m)
# if GLM_HAS_INITIALIZER_LISTS
: value{col_type(m[0]), col_type(m[1])}
# endif
{
this->value[0] = col_type(m[0]);
this->value[1] = col_type(m[1]);
# if !GLM_HAS_INITIALIZER_LISTS
this->value[0] = col_type(m[0]);
this->value[1] = col_type(m[1]);
# endif
}

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 3, T, Q>::mat(mat<2, 4, T, Q> const& m)
# if GLM_HAS_INITIALIZER_LISTS
: value{col_type(m[0]), col_type(m[1])}
# endif
{
this->value[0] = col_type(m[0]);
this->value[1] = col_type(m[1]);
# if !GLM_HAS_INITIALIZER_LISTS
this->value[0] = col_type(m[0]);
this->value[1] = col_type(m[1]);
# endif
}

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 3, T, Q>::mat(mat<3, 2, T, Q> const& m)
# if GLM_HAS_INITIALIZER_LISTS
: value{col_type(m[0], 0), col_type(m[1], 0)}
# endif
{
this->value[0] = col_type(m[0], 0);
this->value[1] = col_type(m[1], 0);
# if !GLM_HAS_INITIALIZER_LISTS
this->value[0] = col_type(m[0], 0);
this->value[1] = col_type(m[1], 0);
# endif
}

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 3, T, Q>::mat(mat<3, 4, T, Q> const& m)
# if GLM_HAS_INITIALIZER_LISTS
: value{col_type(m[0]), col_type(m[1])}
# endif
{
this->value[0] = col_type(m[0]);
this->value[1] = col_type(m[1]);
# if !GLM_HAS_INITIALIZER_LISTS
this->value[0] = col_type(m[0]);
this->value[1] = col_type(m[1]);
# endif
}

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 3, T, Q>::mat(mat<4, 2, T, Q> const& m)
# if GLM_HAS_INITIALIZER_LISTS
: value{col_type(m[0], 0), col_type(m[1], 0)}
# endif
{
this->value[0] = col_type(m[0], 0);
this->value[1] = col_type(m[1], 0);
# if !GLM_HAS_INITIALIZER_LISTS
this->value[0] = col_type(m[0], 0);
this->value[1] = col_type(m[1], 0);
# endif
}

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 3, T, Q>::mat(mat<4, 3, T, Q> const& m)
# if GLM_HAS_INITIALIZER_LISTS
: value{col_type(m[0]), col_type(m[1])}
# endif
{
this->value[0] = m[0];
this->value[1] = m[1];
# if !GLM_HAS_INITIALIZER_LISTS
this->value[0] = col_type(m[0]);
this->value[1] = col_type(m[1]);
# endif
}

// -- Accesses --
Expand Down
Loading

0 comments on commit dee806e

Please sign in to comment.