Forráskód Böngészése

Added C++ 11 initializer list for matrix types

Christophe Riccio 12 éve
szülő
commit
9b1f079856

+ 7 - 0
glm/core/type_mat2x2.hpp

@@ -82,6 +82,13 @@ namespace detail
 			col_type const & v1,
 			col_type const & v2);
 
+#if(GLM_HAS_INITIALIZER_LISTS)
+		template <typename U>
+		GLM_FUNC_DECL tmat2x2(std::initializer_list<U> m);
+
+		GLM_FUNC_DECL tmat2x2(std::initializer_list<tvec2<T, P> > m);
+#endif//GLM_HAS_INITIALIZER_LISTS
+
 		//////////////////////////////////////
 		// Conversions
 		template <typename U> 

+ 21 - 0
glm/core/type_mat2x2.inl

@@ -141,6 +141,27 @@ namespace detail
 		this->value[1] = v1;
 	}
 
+#if(GLM_HAS_INITIALIZER_LISTS)
+	template <typename T, precision P>
+	template <typename U>
+	GLM_FUNC_QUALIFIER tmat2x2<T, P>::tmat2x2(std::initializer_list<U> m)
+	{
+		assert(m.size() >= this->length());
+
+		typename std::initializer_list<U>::iterator p = m.begin();
+
+		this->value[0] = tvec2<T, P>(*(p +  0), *(p +  1));
+		this->value[1] = tvec2<T, P>(*(p +  2), *(p +  3));
+	}
+
+	template <typename T, precision P>
+	GLM_FUNC_QUALIFIER tmat2x2<T, P>::tmat2x2(std::initializer_list<tvec2<T, P> > m)
+	{
+		this->value[0] = m.begin()[0];
+		this->value[1] = m.begin()[1];
+	}
+#endif//GLM_HAS_INITIALIZER_LISTS
+
 	//////////////////////////////////////
 	// Conversion constructors
 	template <typename T, precision P>

+ 7 - 0
glm/core/type_mat2x3.hpp

@@ -76,6 +76,13 @@ namespace detail
 			col_type const & v0,
 			col_type const & v1);
 
+#if(GLM_HAS_INITIALIZER_LISTS)
+		template <typename U>
+		GLM_FUNC_DECL tmat2x3(std::initializer_list<U> m);
+
+		GLM_FUNC_DECL tmat2x3(std::initializer_list<tvec3<T, P> > m);
+#endif//GLM_HAS_INITIALIZER_LISTS
+
 		//////////////////////////////////////
 		// Conversions
 		template <typename U>

+ 21 - 0
glm/core/type_mat2x3.inl

@@ -140,6 +140,27 @@ namespace detail
 		this->value[1] = v1;
 	}
 
+#if(GLM_HAS_INITIALIZER_LISTS)
+	template <typename T, precision P>
+	template <typename U>
+	GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3(std::initializer_list<U> m)
+	{
+		assert(m.size() >= this->length());
+
+		typename std::initializer_list<U>::iterator p = m.begin();
+
+		this->value[0] = tvec3<T, P>(*(p +  0), *(p +  1), *(p +  2));
+		this->value[1] = tvec3<T, P>(*(p +  3), *(p +  4), *(p +  5));
+	}
+
+	template <typename T, precision P>
+	GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3(std::initializer_list<tvec3<T, P> > m)
+	{
+		this->value[0] = m.begin()[0];
+		this->value[1] = m.begin()[1];
+	}
+#endif//GLM_HAS_INITIALIZER_LISTS
+
 	//////////////////////////////////////
 	// Conversion constructors
 	template <typename T, precision P>

+ 7 - 0
glm/core/type_mat2x4.hpp

@@ -76,6 +76,13 @@ namespace detail
 			col_type const & v0, 
 			col_type const & v1);
 
+#if(GLM_HAS_INITIALIZER_LISTS)
+		template <typename U>
+		GLM_FUNC_DECL tmat2x4(std::initializer_list<U> m);
+
+		GLM_FUNC_DECL tmat2x4(std::initializer_list<tvec4<T, P> > m);
+#endif//GLM_HAS_INITIALIZER_LISTS
+
 		//////////////////////////////////////
 		// Conversions
 		template <typename U>

+ 21 - 0
glm/core/type_mat2x4.inl

@@ -143,6 +143,27 @@ namespace detail
 		this->value[1] = v1;
 	}
 
+#if(GLM_HAS_INITIALIZER_LISTS)
+	template <typename T, precision P>
+	template <typename U>
+	GLM_FUNC_QUALIFIER tmat2x4<T, P>::tmat2x4(std::initializer_list<U> m)
+	{
+		assert(m.size() >= this->length());
+
+		typename std::initializer_list<U>::iterator p = m.begin();
+
+		this->value[0] = tvec4<T, P>(*(p +  0), *(p +  1), *(p +  2), *(p +  3));
+		this->value[1] = tvec4<T, P>(*(p +  4), *(p +  5), *(p +  6), *(p +  7));
+	}
+
+	template <typename T, precision P>
+	GLM_FUNC_QUALIFIER tmat2x4<T, P>::tmat2x4(std::initializer_list<tvec4<T, P> > m)
+	{
+		this->value[0] = m.begin()[0];
+		this->value[1] = m.begin()[1];
+	}
+#endif//GLM_HAS_INITIALIZER_LISTS
+
 	//////////////////////////////////////
 	// Conversion constructors
 	template <typename T, precision P>

+ 7 - 0
glm/core/type_mat3x2.hpp

@@ -78,6 +78,13 @@ namespace detail
 			col_type const & v1,
 			col_type const & v2);
 
+#if(GLM_HAS_INITIALIZER_LISTS)
+		template <typename U>
+		GLM_FUNC_DECL tmat3x2(std::initializer_list<U> m);
+
+		GLM_FUNC_DECL tmat3x2(std::initializer_list<tvec2<T, P> > m);
+#endif//GLM_HAS_INITIALIZER_LISTS
+
 		//////////////////////////////////////
 		// Conversions
 		template <typename U>

+ 23 - 0
glm/core/type_mat3x2.inl

@@ -148,6 +148,29 @@ namespace detail
 		this->value[2] = v2;
 	}
 
+#if(GLM_HAS_INITIALIZER_LISTS)
+	template <typename T, precision P>
+	template <typename U>
+	GLM_FUNC_QUALIFIER tmat3x2<T, P>::tmat3x2(std::initializer_list<U> m)
+	{
+		assert(m.size() >= this->length());
+
+		typename std::initializer_list<U>::iterator p = m.begin();
+
+		this->value[0] = tvec2<T, P>(*(p + 0), *(p + 1));
+		this->value[1] = tvec2<T, P>(*(p + 2), *(p + 3));
+		this->value[2] = tvec2<T, P>(*(p + 4), *(p + 5));
+	}
+
+	template <typename T, precision P>
+	GLM_FUNC_QUALIFIER tmat3x2<T, P>::tmat3x2(std::initializer_list<tvec2<T, P> > m)
+	{
+		this->value[0] = m.begin()[0];
+		this->value[1] = m.begin()[1];
+		this->value[2] = m.begin()[2];
+	}
+#endif//GLM_HAS_INITIALIZER_LISTS
+
 	//////////////////////////////////////
 	// Conversion constructors
 	template <typename T, precision P>

+ 7 - 0
glm/core/type_mat3x3.hpp

@@ -83,6 +83,13 @@ namespace detail
 			col_type const & v1,
 			col_type const & v2);
 
+#if(GLM_HAS_INITIALIZER_LISTS)
+		template <typename U>
+		GLM_FUNC_DECL tmat3x3(std::initializer_list<U> m);
+
+		GLM_FUNC_DECL tmat3x3(std::initializer_list<tvec3<T, P> > m);
+#endif//GLM_HAS_INITIALIZER_LISTS
+
 		//////////////////////////////////////
 		// Conversions
 		template <typename U>

+ 23 - 0
glm/core/type_mat3x3.inl

@@ -151,6 +151,29 @@ namespace detail
 		this->value[2] = v2;
 	}
 
+#if(GLM_HAS_INITIALIZER_LISTS)
+	template <typename T, precision P>
+	template <typename U>
+	GLM_FUNC_QUALIFIER tmat3x3<T, P>::tmat3x3(std::initializer_list<U> m)
+	{
+		assert(m.size() >= this->length());
+
+		typename std::initializer_list<U>::iterator p = m.begin();
+
+		this->value[0] = tvec3<T, P>(*(p + 0), *(p + 1), *(p + 2));
+		this->value[1] = tvec3<T, P>(*(p + 3), *(p + 4), *(p + 5));
+		this->value[2] = tvec3<T, P>(*(p + 6), *(p + 7), *(p + 8));
+	}
+
+	template <typename T, precision P>
+	GLM_FUNC_QUALIFIER tmat3x3<T, P>::tmat3x3(std::initializer_list<tvec3<T, P> > m)
+	{
+		this->value[0] = m.begin()[0];
+		this->value[1] = m.begin()[1];
+		this->value[2] = m.begin()[2];
+	}
+#endif//GLM_HAS_INITIALIZER_LISTS
+
 	//////////////////////////////////////
 	// Conversion constructors
 	template <typename T, precision P>

+ 7 - 0
glm/core/type_mat3x4.hpp

@@ -78,6 +78,13 @@ namespace detail
 			col_type const & v1,
 			col_type const & v2);
 
+#if(GLM_HAS_INITIALIZER_LISTS)
+		template <typename U>
+		GLM_FUNC_DECL tmat3x4(std::initializer_list<U> m);
+
+		GLM_FUNC_DECL tmat3x4(std::initializer_list<tvec4<T, P> > m);
+#endif//GLM_HAS_INITIALIZER_LISTS
+
 		//////////////////////////////////////
 		// Conversions
 		template <typename U>

+ 23 - 0
glm/core/type_mat3x4.inl

@@ -195,6 +195,29 @@ namespace detail
 		this->value[2] = col_type(v3);
 	}
 
+#if(GLM_HAS_INITIALIZER_LISTS)
+	template <typename T, precision P>
+	template <typename U>
+	GLM_FUNC_QUALIFIER tmat3x4<T, P>::tmat3x4(std::initializer_list<U> m)
+	{
+		assert(m.size() >= this->length());
+
+		typename std::initializer_list<U>::iterator p = m.begin();
+
+		this->value[0] = tvec4<T, P>(*(p +  0), *(p +  1), *(p +  2), *(p +  3));
+		this->value[1] = tvec4<T, P>(*(p +  4), *(p +  5), *(p +  6), *(p +  7));
+		this->value[2] = tvec4<T, P>(*(p +  8), *(p +  9), *(p + 10), *(p + 11));
+	}
+
+	template <typename T, precision P>
+	GLM_FUNC_QUALIFIER tmat3x4<T, P>::tmat3x4(std::initializer_list<tvec4<T, P> > m)
+	{
+		this->value[0] = m.begin()[0];
+		this->value[1] = m.begin()[1];
+		this->value[2] = m.begin()[2];
+	}
+#endif//GLM_HAS_INITIALIZER_LISTS
+	
 	// Conversion
 	template <typename T, precision P>
 	template <typename U, precision Q>

+ 7 - 0
glm/core/type_mat4x2.hpp

@@ -80,6 +80,13 @@ namespace detail
 			col_type const & v2,
 			col_type const & v3);
 
+#if(GLM_HAS_INITIALIZER_LISTS)
+		template <typename U>
+		GLM_FUNC_DECL tmat4x2(std::initializer_list<U> m);
+
+		GLM_FUNC_DECL tmat4x2(std::initializer_list<tvec2<T, P> > m);
+#endif//GLM_HAS_INITIALIZER_LISTS
+
 		//////////////////////////////////////
 		// Conversions
 		template <typename U> 

+ 26 - 0
glm/core/type_mat4x2.inl

@@ -206,6 +206,32 @@ namespace detail
 		this->value[3] = col_type(v4);
 	}
 
+#if(GLM_HAS_INITIALIZER_LISTS)
+	template <typename T, precision P>
+	template <typename U>
+	GLM_FUNC_QUALIFIER tmat4x2<T, P>::tmat4x2(std::initializer_list<U> m)
+	{
+		assert(m.size() >= this->length());
+
+		typename std::initializer_list<U>::iterator p = m.begin();
+
+		this->value[0] = tvec2<T, P>(*(p + 0), *(p + 1));
+		this->value[1] = tvec2<T, P>(*(p + 2), *(p + 3));
+		this->value[2] = tvec2<T, P>(*(p + 4), *(p + 5));
+		this->value[3] = tvec2<T, P>(*(p + 6), *(p + 7));
+	}
+
+	template <typename T, precision P>
+	GLM_FUNC_QUALIFIER tmat4x2<T, P>::tmat4x2(std::initializer_list<tvec2<T, P> > m)
+	{
+		this->value[0] = m.begin()[0];
+		this->value[1] = m.begin()[1];
+		this->value[2] = m.begin()[2];
+		this->value[3] = m.begin()[3];
+	}
+#endif//GLM_HAS_INITIALIZER_LISTS
+
+	//////////////////////////////////////
 	// Conversion
 	template <typename T, precision P>
 	template <typename U, precision Q>

+ 7 - 0
glm/core/type_mat4x3.hpp

@@ -80,6 +80,13 @@ namespace detail
 			col_type const & v2,
 			col_type const & v3);
 
+#if(GLM_HAS_INITIALIZER_LISTS)
+		template <typename U>
+		GLM_FUNC_DECL tmat4x3(std::initializer_list<U> m);
+
+		GLM_FUNC_DECL tmat4x3(std::initializer_list<tvec3<T, P> > m);
+#endif//GLM_HAS_INITIALIZER_LISTS
+
 		//////////////////////////////////////
 		// Conversions
 		template <typename U>

+ 25 - 0
glm/core/type_mat4x3.inl

@@ -152,6 +152,31 @@ namespace detail
 		this->value[3] = v3;
 	}
 
+#if(GLM_HAS_INITIALIZER_LISTS)
+	template <typename T, precision P>
+	template <typename U>
+	GLM_FUNC_QUALIFIER tmat4x3<T, P>::tmat4x3(std::initializer_list<U> m)
+	{
+		assert(m.size() >= this->length());
+
+		typename std::initializer_list<U>::iterator p = m.begin();
+
+		this->value[0] = tvec3<T, P>(*(p +  0), *(p +  1), *(p +  2));
+		this->value[1] = tvec3<T, P>(*(p +  3), *(p +  4), *(p +  5));
+		this->value[2] = tvec3<T, P>(*(p +  6), *(p +  7), *(p +  8));
+		this->value[3] = tvec3<T, P>(*(p +  9), *(p + 10), *(p + 11));
+	}
+
+	template <typename T, precision P>
+	GLM_FUNC_QUALIFIER tmat4x3<T, P>::tmat4x3(std::initializer_list<tvec3<T, P> > m)
+	{
+		this->value[0] = m.begin()[0];
+		this->value[1] = m.begin()[1];
+		this->value[2] = m.begin()[2];
+		this->value[3] = m.begin()[3];
+	}
+#endif//GLM_HAS_INITIALIZER_LISTS
+
 	//////////////////////////////////////
 	// Conversion constructors
 	template <typename T, precision P> 

+ 53 - 0
test/core/core_type_mat4x3.cpp

@@ -7,7 +7,9 @@
 // File    : test/core/type_mat4x3.cpp
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
+#include <glm/core/func_vector_relational.hpp>
 #include <glm/core/type_mat4x3.hpp>
+#include <vector>
 
 static int test_operators()
 {
@@ -28,10 +30,61 @@ static int test_operators()
 	return (S && !R) ? 0 : 1;
 }
 
+int test_ctr()
+{
+	int Error(0);
+
+#if(GLM_HAS_INITIALIZER_LISTS)
+	glm::mat4x3 m0(
+		glm::vec3(0, 1, 2), 
+		glm::vec3(3, 4, 5),
+		glm::vec3(6, 7, 8),
+		glm::vec3(9, 10, 11));
+
+	glm::mat4x3 m1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
+
+	glm::mat4x3 m2{
+		{0, 1, 2},
+		{3, 4, 5},
+		{6, 7, 8},
+		{9, 10, 11}};
+
+	for(int i = 0; i < m0.length(); ++i)
+		Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;
+
+	for(int i = 0; i < m1.length(); ++i)
+		Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
+
+	std::vector<glm::mat4x3> v1{
+		{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
+		{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
+	};
+
+	std::vector<glm::mat4x3> v2{
+		{
+			{ 0, 1, 2 },
+			{ 4, 5, 6 },
+			{ 8, 9, 10 },
+			{ 12, 13, 14 }
+		},
+		{
+			{ 0, 1, 2 },
+			{ 4, 5, 6 },
+			{ 8, 9, 10 },
+			{ 12, 13, 14 }
+		}
+	};
+
+#endif//GLM_HAS_INITIALIZER_LISTS
+
+	return Error;
+}
+
 int main()
 {
 	int Error = 0;
 
+	Error += test_ctr();
 	Error += test_operators();
 
 	return Error;

+ 12 - 0
test/core/core_type_mat4x4.cpp

@@ -128,6 +128,12 @@ int test_ctr()
 	int Error(0);
 
 #if(GLM_HAS_INITIALIZER_LISTS)
+	glm::mat4 m0(
+		glm::vec4(0, 1, 2, 3), 
+		glm::vec4(4, 5, 6, 7),
+		glm::vec4(8, 9, 10, 11),
+		glm::vec4(12, 13, 14, 15));
+
 	glm::mat4 m1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
 
 	glm::mat4 m2{
@@ -136,6 +142,12 @@ int test_ctr()
 		{8, 9, 10, 11},
 		{12, 13, 14, 15}};
 
+	for(int i = 0; i < m0.length(); ++i)
+		Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;
+
+	for(int i = 0; i < m1.length(); ++i)
+		Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
+
 	std::vector<glm::mat4> m3{
 		{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
 		{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},