Added GLM_FORCE_EXPLICIT_CTOR to require explicit type conversions #269

This commit is contained in:
Christophe Riccio 2014-11-17 22:59:10 +01:00
parent 9c62eee507
commit 3adf263341
17 changed files with 620 additions and 493 deletions

Binary file not shown.

View File

@ -92,8 +92,14 @@ namespace glm
//////////////////////////////////////
// Matrix conversions
template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat2x2(tmat2x2<U, Q> const & m);
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat2x2(tmat2x2<U, Q> const & m);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tmat2x2(tmat2x2<U, Q> const & m);
# endif
GLM_FUNC_DECL explicit tmat2x2(tmat3x3<T, P> const & x);
GLM_FUNC_DECL explicit tmat2x2(tmat4x4<T, P> const & x);

View File

@ -75,6 +75,7 @@ namespace glm
//////////////////////////////////////
// Conversions
template <typename X1, typename Y1, typename Z1, typename X2, typename Y2, typename Z2>
GLM_FUNC_DECL tmat2x3(
X1 const & x1, Y1 const & y1, Z1 const & z1,
@ -87,8 +88,14 @@ namespace glm
//////////////////////////////////////
// Matrix conversion
template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat2x3(tmat2x3<U, Q> const & m);
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat2x3(tmat2x3<U, Q> const & m);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tmat2x3(tmat2x3<U, Q> const & m);
# endif
GLM_FUNC_DECL explicit tmat2x3(tmat2x2<T, P> const & x);
GLM_FUNC_DECL explicit tmat2x3(tmat3x3<T, P> const & x);

View File

@ -89,8 +89,14 @@ namespace glm
//////////////////////////////////////
// Matrix conversions
template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat2x4(tmat2x4<U, Q> const & m);
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat2x4(tmat2x4<U, Q> const & m);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tmat2x4(tmat2x4<U, Q> const & m);
# endif
GLM_FUNC_DECL explicit tmat2x4(tmat2x2<T, P> const & x);
GLM_FUNC_DECL explicit tmat2x4(tmat3x3<T, P> const & x);

View File

@ -77,6 +77,7 @@ namespace glm
//////////////////////////////////////
// Conversions
template<
typename X1, typename Y1,
typename X2, typename Y2,
@ -92,9 +93,16 @@ namespace glm
tvec2<V2, P> const & v2,
tvec2<V3, P> const & v3);
//////////////////////////////////////
// Matrix conversions
template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat3x2(tmat3x2<U, Q> const & m);
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat3x2(tmat3x2<U, Q> const & m);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tmat3x2(tmat3x2<U, Q> const & m);
# endif
GLM_FUNC_DECL explicit tmat3x2(tmat2x2<T, P> const & x);
GLM_FUNC_DECL explicit tmat3x2(tmat3x3<T, P> const & x);

View File

@ -81,6 +81,7 @@ namespace glm
//////////////////////////////////////
// Conversions
template<
typename X1, typename Y1, typename Z1,
typename X2, typename Y2, typename Z2,
@ -96,9 +97,16 @@ namespace glm
tvec3<V2, P> const & v2,
tvec3<V3, P> const & v3);
//////////////////////////////////////
// Matrix conversions
template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat3x3(tmat3x3<U, Q> const & m);
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat3x3(tmat3x3<U, Q> const & m);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tmat3x3(tmat3x3<U, Q> const & m);
# endif
GLM_FUNC_DECL explicit tmat3x3(tmat2x2<T, P> const & x);
GLM_FUNC_DECL explicit tmat3x3(tmat4x4<T, P> const & x);

View File

@ -92,9 +92,16 @@ namespace glm
tvec4<V2, P> const & v2,
tvec4<V3, P> const & v3);
//////////////////////////////////////
// Matrix conversion
template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat3x4(tmat3x4<U, Q> const & m);
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat3x4(tmat3x4<U, Q> const & m);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tmat3x4(tmat3x4<U, Q> const & m);
# endif
GLM_FUNC_DECL explicit tmat3x4(tmat2x2<T, P> const & x);
GLM_FUNC_DECL explicit tmat3x4(tmat3x3<T, P> const & x);

View File

@ -98,9 +98,16 @@ namespace glm
tvec2<V3, P> const & v3,
tvec2<V4, P> const & v4);
//////////////////////////////////////
// Matrix conversions
template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat4x2(tmat4x2<U, Q> const & m);
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat4x2(tmat4x2<U, Q> const & m);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tmat4x2(tmat4x2<U, Q> const & m);
# endif
GLM_FUNC_DECL explicit tmat4x2(tmat2x2<T, P> const & x);
GLM_FUNC_DECL explicit tmat4x2(tmat3x3<T, P> const & x);

View File

@ -97,10 +97,17 @@ namespace glm
tvec3<V3, P> const & v3,
tvec3<V4, P> const & v4);
//////////////////////////////////////
// Matrix conversions
template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat4x3(tmat4x3<U, Q> const & m);
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat4x3(tmat4x3<U, Q> const & m);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tmat4x3(tmat4x3<U, Q> const & m);
# endif
GLM_FUNC_DECL explicit tmat4x3(tmat2x2<T, P> const & x);
GLM_FUNC_DECL explicit tmat4x3(tmat3x3<T, P> const & x);
GLM_FUNC_DECL explicit tmat4x3(tmat4x4<T, P> const & x);

View File

@ -95,17 +95,24 @@ namespace glm
X2 const & x2, Y2 const & y2, Z2 const & z2, W2 const & w2,
X3 const & x3, Y3 const & y3, Z3 const & z3, W3 const & w3,
X4 const & x4, Y4 const & y4, Z4 const & z4, W4 const & w4);
template <typename V1, typename V2, typename V3, typename V4>
GLM_FUNC_DECL tmat4x4(
tvec4<V1, P> const & v1,
tvec4<V2, P> const & v2,
tvec4<V3, P> const & v3,
tvec4<V4, P> const & v4);
//////////////////////////////////////
// Matrix conversions
template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat4x4(tmat4x4<U, Q> const & m);
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q>
GLM_FUNC_DECL explicit tmat4x4(tmat4x4<U, Q> const & m);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tmat4x4(tmat4x4<U, Q> const & m);
# endif
GLM_FUNC_DECL explicit tmat4x4(tmat2x2<T, P> const & x);
GLM_FUNC_DECL explicit tmat4x4(tmat3x3<T, P> const & x);
@ -179,7 +186,7 @@ namespace glm
template <typename T, precision P>
GLM_FUNC_DECL typename tmat4x4<T, P>::row_type operator*(typename tmat4x4<T, P>::col_type const & v, tmat4x4<T, P> const & m);
template <typename T, precision P>
GLM_FUNC_DECL tmat2x4<T, P> operator*(tmat4x4<T, P> const & m1, tmat2x4<T, P> const & m2);

View File

@ -95,6 +95,14 @@ namespace glm
//////////////////////////////////////
// Convertions
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q>
GLM_FUNC_DECL explicit tquat(tquat<U, Q> const & q);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tquat(tquat<U, Q> const & q);
# endif
/// Create a quaternion from two normalized axis
///
/// @param u A first normalized axis
@ -102,6 +110,7 @@ namespace glm
/// @see gtc_quaternion
/// @see http://lolengine.net/blog/2013/09/18/beautiful-maths-quaternion-from-vectors
GLM_FUNC_DECL explicit tquat(tvec3<T, P> const & u, tvec3<T, P> const & v);
/// Build a quaternion from euler angles (pitch, yaw, roll), in radians.
GLM_FUNC_DECL explicit tquat(tvec3<T, P> const & eulerAngles);
GLM_FUNC_DECL explicit tquat(tmat3x3<T, P> const & m);

View File

@ -106,12 +106,21 @@ namespace detail
template <typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P>::tquat(T const & w, T const & x, T const & y, T const & z)
: x(x), y(y), z(z), w(w)
: x(x), y(y), z(z), w(w)
{}
//////////////////////////////////////////////////////////////
// Conversions
template <typename T, precision P>
template <typename U, precision Q>
GLM_FUNC_QUALIFIER tquat<T, P>::tquat(tquat<U, Q> const & q)
: x(static_cast<T>(q.x))
, y(static_cast<T>(q.y))
, z(static_cast<T>(q.z))
, w(static_cast<T>(q.w))
{}
//template <typename valType>
//GLM_FUNC_QUALIFIER tquat<valType>::tquat
//(

View File

@ -89,6 +89,14 @@ namespace glm
//////////////////////////////////////////////////////////////
// tdualquat conversions
# ifdef GLM_FORCE_EXPLICIT_CTOR
template <typename U, precision Q>
GLM_FUNC_DECL explicit tdualquat(tdualquat<U, Q> const & q);
# else
template <typename U, precision Q>
GLM_FUNC_DECL tdualquat(tdualquat<U, Q> const & q);
# endif
GLM_FUNC_DECL explicit tdualquat(tmat2x4<T, P> const & holder_mat);
GLM_FUNC_DECL explicit tdualquat(tmat3x4<T, P> const & aug_mat);

View File

@ -56,7 +56,8 @@ namespace glm
template <typename T, precision P>
template <precision Q>
GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(tdualquat<T, Q> const & d)
: real(d.real), dual(d.dual)
: real(d.real)
, dual(d.dual)
{}
//////////////////////////////////////
@ -87,6 +88,14 @@ namespace glm
//////////////////////////////////////////////////////////////
// tdualquat conversions
template <typename T, precision P>
template <typename U, precision Q>
GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(tdualquat<U, Q> const & q)
: real(q.real)
, dual(q.dual)
{}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(tmat2x4<T, P> const & m)
{

View File

@ -57,6 +57,7 @@ Features:
- Added GTC_bitfield extension, promoted GTX_bit
- Added GTC_integer extension, promoted GTX_bit
- Added GTC_round extension, promoted GTX_bit
- Added GLM_FORCE_EXPLICIT_CTOR to require explicit type conversions #269
Improvements:
- Rely on C++11 to implement isinf and isnan

File diff suppressed because it is too large Load Diff

View File

@ -13,16 +13,9 @@
#include <cstdio>
#include <vector>
void print(glm::dmat4 const & Mat0)
{
printf("mat4(\n");
printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f)\n", Mat0[0][0], Mat0[0][1], Mat0[0][2], Mat0[0][3]);
printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f)\n", Mat0[1][0], Mat0[1][1], Mat0[1][2], Mat0[1][3]);
printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f)\n", Mat0[2][0], Mat0[2][1], Mat0[2][2], Mat0[2][3]);
printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f))\n\n", Mat0[3][0], Mat0[3][1], Mat0[3][2], Mat0[3][3]);
}
void print(glm::mat4 const & Mat0)
template <typename genType>
void print(genType const & Mat0)
{
printf("mat4(\n");
printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f)\n", Mat0[0][0], Mat0[0][1], Mat0[0][2], Mat0[0][3]);