diff --git a/glm/detail/type_vec2.hpp b/glm/detail/type_vec2.hpp index 5803bf1d..5e884826 100644 --- a/glm/detail/type_vec2.hpp +++ b/glm/detail/type_vec2.hpp @@ -115,7 +115,7 @@ namespace detail # if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE)) template - GLM_FUNC_DECL tvec2(_swizzle<2,T, P, tvec2, E0, E1,-1,-2> const & that) + GLM_FUNC_DECL tvec2(_swizzle<2, T, P, tvec2, E0, E1,-1,-2> const & that) { *this = that(); } diff --git a/glm/detail/type_vec3.hpp b/glm/detail/type_vec3.hpp index 465e1f4c..b6bde237 100644 --- a/glm/detail/type_vec3.hpp +++ b/glm/detail/type_vec3.hpp @@ -104,17 +104,35 @@ namespace detail template GLM_FUNC_DECL tvec3(tvec3 const & v); + ////////////////////////////////////// + // Swizzle constructors + +# if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE)) + template + GLM_FUNC_DECL tvec3(_swizzle<3, T, P, tvec3, E0, E1, E2, -1> const & that) + { + *this = that(); + } + + template + GLM_FUNC_DECL tvec3(_swizzle<2, T, P, tvec2, E0, E1, -1, -2> const & v, T const & s) + { + *this = tvec3(v(), s); + } + + template + GLM_FUNC_DECL tvec3(T const & s, _swizzle<2, T, P, tvec2, E0, E1, -1, -2> const & v) + { + *this = tvec3(s, v()); + } +# endif//(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE)) + ////////////////////////////////////// // Explicit basic constructors - GLM_FUNC_DECL explicit tvec3( - ctor); - GLM_FUNC_DECL explicit tvec3( - T const & s); - GLM_FUNC_DECL tvec3( - T const & s1, - T const & s2, - T const & s3); + GLM_FUNC_DECL explicit tvec3(ctor); + GLM_FUNC_DECL explicit tvec3(T const & s); + GLM_FUNC_DECL tvec3(T const & s1, T const & s2, T const & s3); ////////////////////////////////////// // Conversion scalar constructors @@ -142,29 +160,6 @@ namespace detail template GLM_FUNC_DECL explicit tvec3(tvec4 const & v); - ////////////////////////////////////// - // Swizzle constructors - -# if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE)) - template - GLM_FUNC_DECL tvec3(_swizzle<3, T, P, tvec3, E0, E1, E2, -1> const & that) - { - *this = that(); - } - - template - GLM_FUNC_DECL tvec3(_swizzle<2, T, P, tvec2, E0, E1, -1, -2> const & v, T const & s) - { - *this = tvec3(v(), s); - } - - template - GLM_FUNC_DECL tvec3(T const & s, _swizzle<2, T, P, tvec2, E0, E1, -1, -2> const & v) - { - *this = tvec3(s, v()); - } -# endif//(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE)) - ////////////////////////////////////// // Unary arithmetic operators diff --git a/test/core/core_type_vec1.cpp b/test/core/core_type_vec1.cpp index 0b773012..47247390 100644 --- a/test/core/core_type_vec1.cpp +++ b/test/core/core_type_vec1.cpp @@ -7,6 +7,7 @@ // File : test/core/type_vec1.cpp /////////////////////////////////////////////////////////////////////////////////////////////////// +#define GLM_SWIZZLE #define GLM_FORCE_RADIANS #include diff --git a/test/core/core_type_vec2.cpp b/test/core/core_type_vec2.cpp index 94b9e65a..3dcd6504 100644 --- a/test/core/core_type_vec2.cpp +++ b/test/core/core_type_vec2.cpp @@ -7,6 +7,7 @@ // File : test/core/type_vec2.cpp /////////////////////////////////////////////////////////////////////////////////////////////////// +#define GLM_SWIZZLE #define GLM_FORCE_RADIANS #include #include @@ -219,6 +220,19 @@ int test_vec2_ctor() } #endif +#if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE)) + { + glm::vec2 A = glm::vec2(1.0f, 2.0f); + glm::vec2 B = A.xy; + glm::vec2 C(A.xy); + glm::vec2 D(A.xy()); + + Error += glm::all(glm::equal(A, B)) ? 0 : 1; + Error += glm::all(glm::equal(A, C)) ? 0 : 1; + Error += glm::all(glm::equal(A, D)) ? 0 : 1; + } +#endif//(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE)) + { glm::vec2 A = glm::vec2(2.0f); glm::vec2 B = glm::vec2(2.0f, 3.0f); diff --git a/test/core/core_type_vec3.cpp b/test/core/core_type_vec3.cpp index 4cce22fc..9db97f94 100644 --- a/test/core/core_type_vec3.cpp +++ b/test/core/core_type_vec3.cpp @@ -39,6 +39,27 @@ int test_vec3_ctor() } #endif +#if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE)) + { + glm::vec3 A = glm::vec3(1.0f, 2.0f, 3.0f); + glm::vec3 B = A.xyz; + glm::vec3 C(A.xyz); + glm::vec3 D(A.xyz()); + glm::vec3 E(A.x, A.yz); + glm::vec3 F(A.x, A.yz()); + glm::vec3 G(A.xy, A.z); + glm::vec3 H(A.xy(), A.z); + + Error += glm::all(glm::equal(A, B)) ? 0 : 1; + Error += glm::all(glm::equal(A, C)) ? 0 : 1; + Error += glm::all(glm::equal(A, D)) ? 0 : 1; + Error += glm::all(glm::equal(A, E)) ? 0 : 1; + Error += glm::all(glm::equal(A, F)) ? 0 : 1; + Error += glm::all(glm::equal(A, G)) ? 0 : 1; + Error += glm::all(glm::equal(A, H)) ? 0 : 1; + } +#endif//(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE)) + { glm::vec3 A(1); glm::vec3 B(1, 1, 1); diff --git a/test/core/core_type_vec4.cpp b/test/core/core_type_vec4.cpp index c341b88b..907fa2ce 100644 --- a/test/core/core_type_vec4.cpp +++ b/test/core/core_type_vec4.cpp @@ -7,6 +7,7 @@ // File : test/core/type_vec4.cpp /////////////////////////////////////////////////////////////////////////////////////////////////// +#define GLM_SWIZZLE #define GLM_FORCE_RADIANS #include #include @@ -60,6 +61,37 @@ int test_vec4_ctor() } #endif +#if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE)) + { + glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f); + glm::vec4 B = A.xyzw; + glm::vec4 C(A.xyzw); + glm::vec4 D(A.xyzw()); + glm::vec4 E(A.x, A.yzw); + glm::vec4 F(A.x, A.yzw()); + glm::vec4 G(A.xyz, A.w); + glm::vec4 H(A.xyz(), A.w); + glm::vec4 I(A.xy, A.zw); + glm::vec4 J(A.xy(), A.zw()); + glm::vec4 K(A.x, A.y, A.zw); + glm::vec4 L(A.x, A.yz, A.w); + glm::vec4 M(A.xy, A.z, A.w); + + Error += glm::all(glm::equal(A, B)) ? 0 : 1; + Error += glm::all(glm::equal(A, C)) ? 0 : 1; + Error += glm::all(glm::equal(A, D)) ? 0 : 1; + Error += glm::all(glm::equal(A, E)) ? 0 : 1; + Error += glm::all(glm::equal(A, F)) ? 0 : 1; + Error += glm::all(glm::equal(A, G)) ? 0 : 1; + Error += glm::all(glm::equal(A, H)) ? 0 : 1; + Error += glm::all(glm::equal(A, I)) ? 0 : 1; + Error += glm::all(glm::equal(A, J)) ? 0 : 1; + Error += glm::all(glm::equal(A, K)) ? 0 : 1; + Error += glm::all(glm::equal(A, L)) ? 0 : 1; + Error += glm::all(glm::equal(A, M)) ? 0 : 1; + } +#endif//(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE)) + { glm::vec4 A(1); glm::vec4 B(1, 1, 1, 1);