Added C++ 11 initializer list for matrix types

This commit is contained in:
Christophe Riccio 2013-10-01 01:12:21 +02:00
parent 2badec664f
commit 9b1f079856
18 changed files with 304 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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