mirror of
https://github.com/g-truc/glm.git
synced 2025-04-08 06:43:10 +00:00
Added mat4 initializer experiment
This commit is contained in:
parent
71855943e0
commit
5dc52c722c
6 changed files with 97 additions and 11 deletions
|
@ -1000,46 +1000,46 @@ namespace detail
|
|||
|
||||
GLM_FUNC_QUALIFIER int floatBitsToInt(float const & v)
|
||||
{
|
||||
return *reinterpret_cast<int*>(const_cast<float*>(&v));
|
||||
return reinterpret_cast<int&>(const_cast<float&>(v));
|
||||
}
|
||||
|
||||
template <template <typename, precision> class vecType, precision P>
|
||||
GLM_FUNC_QUALIFIER vecType<int, P> floatBitsToInt(vecType<float, P> const & v)
|
||||
{
|
||||
return *reinterpret_cast<vecType<int, P>*>(const_cast<vecType<float, P>*>(&v));
|
||||
return reinterpret_cast<vecType<int, P>&>(const_cast<vecType<float, P>&>(v));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint floatBitsToUint(float const & v)
|
||||
{
|
||||
return *reinterpret_cast<uint*>(const_cast<float*>(&v));
|
||||
return reinterpret_cast<uint&>(const_cast<float&>(v));
|
||||
}
|
||||
|
||||
template <template <typename, precision> class vecType, precision P>
|
||||
GLM_FUNC_QUALIFIER vecType<uint, P> floatBitsToUint(vecType<float, P> const & v)
|
||||
{
|
||||
return *reinterpret_cast<vecType<uint, P>*>(const_cast<vecType<float, P>*>(&v));
|
||||
return reinterpret_cast<vecType<uint, P>&>(const_cast<vecType<float, P>&>(v));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER float intBitsToFloat(int const & v)
|
||||
{
|
||||
return *reinterpret_cast<float*>(const_cast<int*>(&v));
|
||||
return reinterpret_cast<float&>(const_cast<int&>(v));
|
||||
}
|
||||
|
||||
template <template <typename, precision> class vecType, precision P>
|
||||
GLM_FUNC_QUALIFIER vecType<float, P> intBitsToFloat(vecType<int, P> const & v)
|
||||
{
|
||||
return *reinterpret_cast<vecType<float, P>*>(const_cast<vecType<int, P>*>(&v));
|
||||
return reinterpret_cast<vecType<float, P>&>(const_cast<vecType<int, P>&>(v));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER float uintBitsToFloat(uint const & v)
|
||||
{
|
||||
return *reinterpret_cast<float*>(const_cast<uint*>(&v));
|
||||
return reinterpret_cast<float&>(const_cast<uint&>(v));
|
||||
}
|
||||
|
||||
template <template <typename, precision> class vecType, precision P>
|
||||
GLM_FUNC_QUALIFIER vecType<float, P> uintBitsToFloat(vecType<uint, P> const & v)
|
||||
{
|
||||
return *reinterpret_cast<vecType<float, P>*>(const_cast<vecType<uint, P>*>(&v));
|
||||
return reinterpret_cast<vecType<float, P>&>(const_cast<vecType<uint, P>&>(v));
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
|
|
|
@ -514,7 +514,7 @@
|
|||
// N2672
|
||||
#define GLM_HAS_INITIALIZER_LISTS ( \
|
||||
(GLM_LANG & GLM_LANG_CXX11_FLAG) || \
|
||||
((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC2012)) || \
|
||||
((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC2013)) || \
|
||||
((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (GLM_COMPILER & GLM_COMPILER_GCC) && (GLM_COMPILER >= GLM_COMPILER_GCC44)) || \
|
||||
__has_feature(cxx_generalized_initializers))
|
||||
|
||||
|
|
|
@ -32,7 +32,11 @@
|
|||
#include "../fwd.hpp"
|
||||
#include "type_vec4.hpp"
|
||||
#include "type_mat.hpp"
|
||||
#if(GLM_HAS_INITIALIZER_LISTS)
|
||||
# include <initializer_list>
|
||||
#endif //GLM_HAS_INITIALIZER_LISTS
|
||||
#include <limits>
|
||||
#include <cstddef>
|
||||
|
||||
namespace glm{
|
||||
namespace detail
|
||||
|
@ -85,6 +89,14 @@ namespace detail
|
|||
col_type const & v2,
|
||||
col_type const & v3);
|
||||
|
||||
#if(GLM_HAS_INITIALIZER_LISTS)
|
||||
template <typename U>
|
||||
GLM_FUNC_DECL tmat4x4(std::initializer_list<U> const & m);
|
||||
|
||||
template <typename U>
|
||||
GLM_FUNC_DECL tmat4x4(std::initializer_list<tvec4<U, P> > const & m);
|
||||
#endif//GLM_HAS_INITIALIZER_LISTS
|
||||
|
||||
//////////////////////////////////////
|
||||
// Conversions
|
||||
template <typename U>
|
||||
|
|
|
@ -174,11 +174,35 @@ namespace detail
|
|||
this->value[3] = col_type(m[3]);
|
||||
}
|
||||
|
||||
#if(GLM_HAS_INITIALIZER_LISTS)
|
||||
template <typename T, precision P>
|
||||
template <typename U>
|
||||
GLM_FUNC_QUALIFIER tmat4x4<T, P>::tmat4x4(std::initializer_list<U> const & m)
|
||||
{
|
||||
assert(m.size() >= this->length());
|
||||
|
||||
this->value[0] = static_cast<tvec4<T, P> >(reinterpret_cast<tvec4<U, P>&>(const_cast<U&>(m.begin()[0])));
|
||||
this->value[1] = static_cast<tvec4<T, P> >(reinterpret_cast<tvec4<U, P>&>(const_cast<U&>(m.begin()[4])));
|
||||
this->value[2] = static_cast<tvec4<T, P> >(reinterpret_cast<tvec4<U, P>&>(const_cast<U&>(m.begin()[8])));
|
||||
this->value[3] = static_cast<tvec4<T, P> >(reinterpret_cast<tvec4<U, P>&>(const_cast<U&>(m.begin()[12])));
|
||||
}
|
||||
|
||||
template <typename T, precision P>
|
||||
template <typename U>
|
||||
GLM_FUNC_QUALIFIER tmat4x4<T, P>::tmat4x4(std::initializer_list<tvec4<U, P> > const & m)
|
||||
{
|
||||
this->value[0] = static_cast<tvec4<T, P> >(m.begin()[0]);
|
||||
this->value[1] = static_cast<tvec4<T, P> >(m.begin()[1]);
|
||||
this->value[2] = static_cast<tvec4<T, P> >(m.begin()[2]);
|
||||
this->value[3] = static_cast<tvec4<T, P> >(m.begin()[3]);
|
||||
}
|
||||
#endif//GLM_HAS_INITIALIZER_LISTS
|
||||
|
||||
//////////////////////////////////////
|
||||
// Conversion constructors
|
||||
template <typename T, precision P>
|
||||
template <typename U>
|
||||
GLM_FUNC_DECL tmat4x4<T, P>::tmat4x4
|
||||
GLM_FUNC_QUALIFIER tmat4x4<T, P>::tmat4x4
|
||||
(
|
||||
U const & s
|
||||
)
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <glm/core/type_mat4x4.hpp>
|
||||
#include <glm/gtc/epsilon.hpp>
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
|
||||
void print(glm::dmat4 const & Mat0)
|
||||
{
|
||||
|
@ -122,10 +123,53 @@ int test_inverse()
|
|||
return Error;
|
||||
}
|
||||
|
||||
int test_ctr()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
#if(GLM_HAS_INITIALIZER_LISTS)
|
||||
glm::mat4 m1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
|
||||
|
||||
glm::mat4 m2{
|
||||
{0, 1, 2, 3},
|
||||
{4, 5, 6, 7},
|
||||
{8, 9, 10, 11},
|
||||
{12, 13, 14, 15}};
|
||||
|
||||
std::initializer_list<glm::mat4> m3{
|
||||
{0, 1, 2, 3},
|
||||
{4, 5, 6, 7},
|
||||
{8, 9, 10, 11},
|
||||
{12, 13, 14, 15}};
|
||||
|
||||
glm::mat4 m4{m3};
|
||||
|
||||
/*
|
||||
std::vector<glm::mat4> v{
|
||||
{
|
||||
{ 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 }
|
||||
}
|
||||
};
|
||||
*/
|
||||
#endif//GLM_HAS_INITIALIZER_LISTS
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_ctr();
|
||||
Error += test_inverse_dmat4x4();
|
||||
Error += test_inverse_mat4x4();
|
||||
Error += test_operators();
|
||||
|
|
|
@ -41,7 +41,13 @@ int test_vec4_ctor()
|
|||
int Error = 0;
|
||||
|
||||
#if(GLM_HAS_INITIALIZER_LISTS)
|
||||
glm::vec4 v{0, 1, 2, 3};
|
||||
{
|
||||
glm::vec4 a{ 0, 1, 2, 3 };
|
||||
std::vector<glm::vec4> v = {
|
||||
{0, 1, 2, 3},
|
||||
{4, 5, 6, 7},
|
||||
{8, 9, 0, 1}};
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue