Browse Source

Added GLM_FORCE_EXPLICIT_CTOR to require explicit type conversions #269

Christophe Riccio 11 years ago
parent
commit
3adf263341

BIN
doc/glm.docx


+ 8 - 2
glm/detail/type_mat2x2.hpp

@@ -92,8 +92,14 @@ namespace glm
 
 
 		//////////////////////////////////////
 		//////////////////////////////////////
 		// Matrix conversions
 		// 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(tmat3x3<T, P> const & x);
 		GLM_FUNC_DECL explicit tmat2x2(tmat4x4<T, P> const & x);
 		GLM_FUNC_DECL explicit tmat2x2(tmat4x4<T, P> const & x);

+ 9 - 2
glm/detail/type_mat2x3.hpp

@@ -75,6 +75,7 @@ namespace glm
 
 
 		//////////////////////////////////////
 		//////////////////////////////////////
 		// Conversions
 		// Conversions
+
 		template <typename X1, typename Y1, typename Z1, typename X2, typename Y2, typename Z2>
 		template <typename X1, typename Y1, typename Z1, typename X2, typename Y2, typename Z2>
 		GLM_FUNC_DECL tmat2x3(
 		GLM_FUNC_DECL tmat2x3(
 			X1 const & x1, Y1 const & y1, Z1 const & z1,
 			X1 const & x1, Y1 const & y1, Z1 const & z1,
@@ -87,8 +88,14 @@ namespace glm
 
 
 		//////////////////////////////////////
 		//////////////////////////////////////
 		// Matrix conversion
 		// 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(tmat2x2<T, P> const & x);
 		GLM_FUNC_DECL explicit tmat2x3(tmat3x3<T, P> const & x);
 		GLM_FUNC_DECL explicit tmat2x3(tmat3x3<T, P> const & x);

+ 8 - 2
glm/detail/type_mat2x4.hpp

@@ -89,8 +89,14 @@ namespace glm
 
 
 		//////////////////////////////////////
 		//////////////////////////////////////
 		// Matrix conversions
 		// 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(tmat2x2<T, P> const & x);
 		GLM_FUNC_DECL explicit tmat2x4(tmat3x3<T, P> const & x);
 		GLM_FUNC_DECL explicit tmat2x4(tmat3x3<T, P> const & x);

+ 10 - 2
glm/detail/type_mat3x2.hpp

@@ -77,6 +77,7 @@ namespace glm
 
 
 		//////////////////////////////////////
 		//////////////////////////////////////
 		// Conversions
 		// Conversions
+
 		template<
 		template<
 			typename X1, typename Y1,
 			typename X1, typename Y1,
 			typename X2, typename Y2,
 			typename X2, typename Y2,
@@ -92,9 +93,16 @@ namespace glm
 			tvec2<V2, P> const & v2,
 			tvec2<V2, P> const & v2,
 			tvec2<V3, P> const & v3);
 			tvec2<V3, P> const & v3);
 
 
+		//////////////////////////////////////
 		// Matrix conversions
 		// 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(tmat2x2<T, P> const & x);
 		GLM_FUNC_DECL explicit tmat3x2(tmat3x3<T, P> const & x);
 		GLM_FUNC_DECL explicit tmat3x2(tmat3x3<T, P> const & x);

+ 10 - 2
glm/detail/type_mat3x3.hpp

@@ -81,6 +81,7 @@ namespace glm
 
 
 		//////////////////////////////////////
 		//////////////////////////////////////
 		// Conversions
 		// Conversions
+
 		template<
 		template<
 			typename X1, typename Y1, typename Z1,
 			typename X1, typename Y1, typename Z1,
 			typename X2, typename Y2, typename Z2,
 			typename X2, typename Y2, typename Z2,
@@ -96,9 +97,16 @@ namespace glm
 			tvec3<V2, P> const & v2,
 			tvec3<V2, P> const & v2,
 			tvec3<V3, P> const & v3);
 			tvec3<V3, P> const & v3);
 
 
+		//////////////////////////////////////
 		// Matrix conversions
 		// 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(tmat2x2<T, P> const & x);
 		GLM_FUNC_DECL explicit tmat3x3(tmat4x4<T, P> const & x);
 		GLM_FUNC_DECL explicit tmat3x3(tmat4x4<T, P> const & x);

+ 9 - 2
glm/detail/type_mat3x4.hpp

@@ -92,9 +92,16 @@ namespace glm
 			tvec4<V2, P> const & v2,
 			tvec4<V2, P> const & v2,
 			tvec4<V3, P> const & v3);
 			tvec4<V3, P> const & v3);
 
 
+		//////////////////////////////////////
 		// Matrix conversion
 		// 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(tmat2x2<T, P> const & x);
 		GLM_FUNC_DECL explicit tmat3x4(tmat3x3<T, P> const & x);
 		GLM_FUNC_DECL explicit tmat3x4(tmat3x3<T, P> const & x);

+ 9 - 2
glm/detail/type_mat4x2.hpp

@@ -98,9 +98,16 @@ namespace glm
 			tvec2<V3, P> const & v3,
 			tvec2<V3, P> const & v3,
 			tvec2<V4, P> const & v4);
 			tvec2<V4, P> const & v4);
 
 
+		//////////////////////////////////////
 		// Matrix conversions
 		// 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(tmat2x2<T, P> const & x);
 		GLM_FUNC_DECL explicit tmat4x2(tmat3x3<T, P> const & x);
 		GLM_FUNC_DECL explicit tmat4x2(tmat3x3<T, P> const & x);

+ 10 - 3
glm/detail/type_mat4x3.hpp

@@ -97,10 +97,17 @@ namespace glm
 			tvec3<V3, P> const & v3,
 			tvec3<V3, P> const & v3,
 			tvec3<V4, P> const & v4);
 			tvec3<V4, P> const & v4);
 
 
+		//////////////////////////////////////
 		// Matrix conversions
 		// 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(tmat2x2<T, P> const & x);
 		GLM_FUNC_DECL explicit tmat4x3(tmat3x3<T, P> const & x);
 		GLM_FUNC_DECL explicit tmat4x3(tmat3x3<T, P> const & x);
 		GLM_FUNC_DECL explicit tmat4x3(tmat4x4<T, P> const & x);
 		GLM_FUNC_DECL explicit tmat4x3(tmat4x4<T, P> const & x);

+ 12 - 5
glm/detail/type_mat4x4.hpp

@@ -95,17 +95,24 @@ namespace glm
 			X2 const & x2, Y2 const & y2, Z2 const & z2, W2 const & w2,
 			X2 const & x2, Y2 const & y2, Z2 const & z2, W2 const & w2,
 			X3 const & x3, Y3 const & y3, Z3 const & z3, W3 const & w3,
 			X3 const & x3, Y3 const & y3, Z3 const & z3, W3 const & w3,
 			X4 const & x4, Y4 const & y4, Z4 const & z4, W4 const & w4);
 			X4 const & x4, Y4 const & y4, Z4 const & z4, W4 const & w4);
-			
+
 		template <typename V1, typename V2, typename V3, typename V4>
 		template <typename V1, typename V2, typename V3, typename V4>
 		GLM_FUNC_DECL tmat4x4(
 		GLM_FUNC_DECL tmat4x4(
 			tvec4<V1, P> const & v1,
 			tvec4<V1, P> const & v1,
 			tvec4<V2, P> const & v2,
 			tvec4<V2, P> const & v2,
 			tvec4<V3, P> const & v3,
 			tvec4<V3, P> const & v3,
 			tvec4<V4, P> const & v4);
 			tvec4<V4, P> const & v4);
-	
+
+		//////////////////////////////////////
 		// Matrix conversions
 		// 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(tmat2x2<T, P> const & x);
 		GLM_FUNC_DECL explicit tmat4x4(tmat3x3<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>
 	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);
 	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>
 	template <typename T, precision P>
 	GLM_FUNC_DECL tmat2x4<T, P> operator*(tmat4x4<T, P> const & m1, tmat2x4<T, P> const & m2);
 	GLM_FUNC_DECL tmat2x4<T, P> operator*(tmat4x4<T, P> const & m1, tmat2x4<T, P> const & m2);
 
 

+ 9 - 0
glm/gtc/quaternion.hpp

@@ -95,6 +95,14 @@ namespace glm
 		//////////////////////////////////////
 		//////////////////////////////////////
 		// Convertions
 		// 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
 		/// Create a quaternion from two normalized axis
 		/// 
 		/// 
 		/// @param u A first normalized axis
 		/// @param u A first normalized axis
@@ -102,6 +110,7 @@ namespace glm
 		/// @see gtc_quaternion
 		/// @see gtc_quaternion
 		/// @see http://lolengine.net/blog/2013/09/18/beautiful-maths-quaternion-from-vectors
 		/// @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);
 		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.
 		/// 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(tvec3<T, P> const & eulerAngles);
 		GLM_FUNC_DECL explicit tquat(tmat3x3<T, P> const & m);
 		GLM_FUNC_DECL explicit tquat(tmat3x3<T, P> const & m);

+ 10 - 1
glm/gtc/quaternion.inl

@@ -106,12 +106,21 @@ namespace detail
 
 
 	template <typename T, precision P>
 	template <typename T, precision P>
 	GLM_FUNC_QUALIFIER tquat<T, P>::tquat(T const & w, T const & x, T const & y, T const & z)
 	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
 	// 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> 
 	//template <typename valType> 
 	//GLM_FUNC_QUALIFIER tquat<valType>::tquat
 	//GLM_FUNC_QUALIFIER tquat<valType>::tquat
 	//(
 	//(

+ 8 - 0
glm/gtx/dual_quaternion.hpp

@@ -89,6 +89,14 @@ namespace glm
 		//////////////////////////////////////////////////////////////
 		//////////////////////////////////////////////////////////////
 		// tdualquat conversions
 		// 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(tmat2x4<T, P> const & holder_mat);
 		GLM_FUNC_DECL explicit tdualquat(tmat3x4<T, P> const & aug_mat);
 		GLM_FUNC_DECL explicit tdualquat(tmat3x4<T, P> const & aug_mat);
 		
 		

+ 10 - 1
glm/gtx/dual_quaternion.inl

@@ -56,7 +56,8 @@ namespace glm
 	template <typename T, precision P>
 	template <typename T, precision P>
 	template <precision Q>
 	template <precision Q>
 	GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(tdualquat<T, Q> const & d)
 	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
 	// 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>
 	template <typename T, precision P>
 	GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(tmat2x4<T, P> const & m)
 	GLM_FUNC_QUALIFIER tdualquat<T, P>::tdualquat(tmat2x4<T, P> const & m)
 	{
 	{

+ 1 - 0
readme.txt

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

File diff suppressed because it is too large
+ 458 - 423
test/core/core_func_common.cpp


+ 2 - 9
test/core/core_type_mat4x4.cpp

@@ -13,16 +13,9 @@
 #include <cstdio>
 #include <cstdio>
 #include <vector>
 #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("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[0][0], Mat0[0][1], Mat0[0][2], Mat0[0][3]);

Some files were not shown because too many files changed in this diff