Add additional swizzle constructors

This commit is contained in:
Ben 2011-10-05 11:14:59 -07:00
parent 5f287430f4
commit bcc8926ebf
4 changed files with 84 additions and 3 deletions

View File

@ -158,6 +158,18 @@ namespace detail
*this = that();
}
template <int E0, int E1>
GLM_FUNC_DECL tvec3(glm::detail::swizzle<2, T, tvec2<T>, E0, E1, -1, -2> const & v, T const & s)
{
*this = tvec3<T>(v(), s);
}
template <int E0, int E1>
GLM_FUNC_DECL tvec3(T const & s, glm::detail::swizzle<2, T, tvec2<T>, E0, E1, -1, -2> const & v)
{
*this = tvec3<T>(s, v());
}
//////////////////////////////////////
// Unary arithmetic operators

View File

@ -159,6 +159,42 @@ namespace detail
*this = that();
}
template <int E0, int E1, int F0, int F1>
GLM_FUNC_DECL tvec4(glm::detail::swizzle<2, T, tvec2<T>, E0, E1, -1, -2> const & v, glm::detail::swizzle<2, T, tvec2<T>, F0, F1, -1, -2> const & u)
{
*this = tvec4<T>(v(), u());
}
template <int E0, int E1>
GLM_FUNC_DECL tvec4(T const & x, T const & y, glm::detail::swizzle<2, T, tvec2<T>, E0, E1, -1, -2> const & v)
{
*this = tvec4<T>(x, y, v());
}
template <int E0, int E1>
GLM_FUNC_DECL tvec4(T const & x, glm::detail::swizzle<2, T, tvec2<T>, E0, E1, -1, -2> const & v, T const & w)
{
*this = tvec4<T>(x, v(), w);
}
template <int E0, int E1>
GLM_FUNC_DECL tvec4(glm::detail::swizzle<2, T, tvec2<T>, E0, E1, -1, -2> const & v, T const & z, T const & w)
{
*this = tvec4<T>(v(), z, w);
}
template <int E0, int E1, int E2>
GLM_FUNC_DECL tvec4(glm::detail::swizzle<3, T, tvec3<T>, E0, E1, E2, -1> const & v, T const & w)
{
*this = tvec4<T>(v(), w);
}
template <int E0, int E1, int E2>
GLM_FUNC_DECL tvec4(T const & x, glm::detail::swizzle<3, T, tvec3<T>, E0, E1, E2, -1> const & v)
{
*this = tvec4<T>(x, v());
}
//////////////////////////////////////
// Swizzle constructors

View File

@ -391,19 +391,16 @@ int test_vec3_swizzle_partial()
{
glm::vec3 B(A.xy, 3.0f);
Error += A == B ? 0 : 1;
}
{
glm::vec3 B(1.0f, A.yz);
Error += A == B ? 0 : 1;
}
{
glm::vec3 B(A.xyz);
Error += A == B ? 0 : 1;
}

View File

@ -213,6 +213,41 @@ int test_vec4_size()
return Error;
}
int test_vec4_swizzle_partial()
{
int Error = 0;
glm::vec4 A(1, 2, 3, 4);
{
glm::vec4 B(A.xy, A.zw);
Error += A == B ? 0 : 1;
}
{
glm::vec4 B(A.xy, 3.0f, 4.0f);
Error += A == B ? 0 : 1;
}
{
glm::vec4 B(1.0f, A.yz, 4.0f);
Error += A == B ? 0 : 1;
}
{
glm::vec4 B(1.0f, 2.0f, A.zw);
Error += A == B ? 0 : 1;
}
{
glm::vec4 B(A.xyz, 4.0f);
Error += A == B ? 0 : 1;
}
{
glm::vec4 B(1.0f, A.yzw);
Error += A == B ? 0 : 1;
}
return Error;
}
int main()
{
//__m128 DataA = swizzle<X, Y, Z, W>(glm::vec4(1.0f, 2.0f, 3.0f, 4.0f));
@ -223,6 +258,7 @@ int main()
Error += test_vec4_size();
Error += test_vec4_operators();
Error += test_hvec4();
Error += test_vec4_swizzle_partial();
return Error;
}