Browse Source

Add additional swizzle constructors

Ben 14 years ago
parent
commit
bcc8926ebf
4 changed files with 84 additions and 3 deletions
  1. 12 0
      glm/core/type_vec3.hpp
  2. 36 0
      glm/core/type_vec4.hpp
  3. 0 3
      test/core/core_type_vec3.cpp
  4. 36 0
      test/core/core_type_vec4.cpp

+ 12 - 0
glm/core/type_vec3.hpp

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

+ 36 - 0
glm/core/type_vec4.hpp

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

+ 0 - 3
test/core/core_type_vec3.cpp

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

+ 36 - 0
test/core/core_type_vec4.cpp

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