Browse Source

Fixed contructor of mat2 and added tests

Christophe Riccio 14 years ago
parent
commit
6fab8113d7
4 changed files with 88 additions and 3 deletions
  1. 19 0
      glm/core/type_mat2x2.hpp
  2. 40 2
      glm/core/type_mat2x2.inl
  3. 1 1
      glm/core/type_vec2.hpp
  4. 28 0
      test/gtc/gtc_half_float.cpp

+ 19 - 0
glm/core/type_mat2x2.hpp

@@ -56,10 +56,12 @@ namespace glm
 			GLM_FUNC_DECL tmat2x2<T> _inverse() const;
 
 		private:
+			//////////////////////////////////////
 			// Data 
 			col_type value[2];
 
 		public:
+			//////////////////////////////////////
 			// Constructors
 			GLM_FUNC_DECL tmat2x2();
 			GLM_FUNC_DECL tmat2x2(
@@ -76,6 +78,23 @@ namespace glm
 				col_type const & v1, 
 				col_type const & v2);
 
+			//////////////////////////////////////
+			// Convertion constructors
+			template <typename U> 
+			GLM_FUNC_DECL explicit tmat2x2(
+				U const & x);
+			
+			template <typename U, typename V, typename M, typename N> 
+			GLM_FUNC_DECL explicit tmat2x2(
+				U const & x1, V const & y1, 
+				M const & x2, N const & y2);
+			
+			//template <typename U, typename V, typename M, typename N> 
+			//GLM_FUNC_DECL explicit tmat2x2(
+			//	tvec2<U, V> const & v1, 
+			//	tvec2<M, N> const & v2);
+
+			//////////////////////////////////////
 			// Conversions
 			template <typename U> 
 			GLM_FUNC_DECL explicit tmat2x2(tmat2x2<U> const & m);

+ 40 - 2
glm/core/type_mat2x2.inl

@@ -107,8 +107,46 @@ namespace detail
         this->value[1] = v1;
     }
 
+	//////////////////////////////////////
+	// Convertion constructors
+	template <typename T> 
+	template <typename U> 
+	GLM_FUNC_DECL tmat2x2<T>::tmat2x2
+	(
+		U const & s
+	)
+	{
+		value_type const Zero(0);
+        this->value[0] = tvec2<T>(value_type(s), Zero);
+        this->value[1] = tvec2<T>(Zero, value_type(s));
+	}
+	
+	template <typename T> 
+	template <typename U, typename V, typename M, typename N> 
+	GLM_FUNC_DECL tmat2x2<T>::tmat2x2
+	(
+		U const & x1, V const & y1, 
+		M const & x2, N const & y2
+	)		
+	{
+        this->value[0] = col_type(value_type(x1), value_type(y1));
+        this->value[1] = col_type(value_type(x2), value_type(y2));
+	}
+	
+	//template <typename T> 
+	//template <typename U, typename V, typename M, typename N> 
+	//GLM_FUNC_DECL tmat2x2<T>::tmat2x2
+	//(
+	//	tvec2<U, V> const & v1, 
+	//	tvec2<M, N> const & v2
+	//)		
+	//{
+ //       this->value[0] = col_type(v1);
+ //       this->value[1] = col_type(v2);
+	//}
+
     //////////////////////////////////////////////////////////////
-    // mat2 conversions
+    // mat2x2 conversions
 
     template <typename T> 
     template <typename U> 
@@ -215,7 +253,7 @@ namespace detail
     }
 
     //////////////////////////////////////////////////////////////
-    // mat3 operators
+    // mat2x2 operators
 
     // This function shouldn't required but it seems that VC7.1 have an optimisation bug if this operator wasn't declared
     template <typename T> 

+ 1 - 1
glm/core/type_vec2.hpp

@@ -93,7 +93,7 @@ namespace glm
 			tvec2(tref2<T> const & r);
 
 			//////////////////////////////////////
-			// Convertion scalar constructors
+			// Convertion constructors
 
 			//! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
 			template <typename U> 

+ 28 - 0
test/gtc/gtc_half_float.cpp

@@ -51,10 +51,38 @@ int test_half_precision_mat()
     return Error;
 }
 
+int test_half_ctor_mat2x2()
+{
+	int Error = 0;
+
+	{
+		glm::hvec2 A(1, 2);
+		glm::hvec2 B(3, 4);
+		glm::hmat2 C(A, B);//, 2.0f, 3.0f, 4.0f);
+		glm::hmat2 D(1, 2, 3, 4);
+
+		Error += C[0] == D[0] ? 0 : 1;
+		Error += C[1] == D[1] ? 0 : 1;
+	}
+
+	{
+		glm::hvec2 A(1, 2.0);
+		glm::hvec2 B(3, 4.0);
+		glm::hmat2 C(A, B);//, 2.0f, 3.0f, 4.0f);
+		glm::hmat2 D(1, 2.0, 3u, 4.0f);
+
+		Error += C[0] == D[0] ? 0 : 1;
+		Error += C[1] == D[1] ? 0 : 1;
+	}
+
+    return Error;
+}
+
 int main()
 {
 	int Error = 0;
 
+	Error += test_half_ctor_mat2x2();
 	Error += test_half_precision_scalar();
 	Error += test_half_precision_vec();
 	Error += test_half_precision_mat();