Browse Source

Implement #1370 (reflection matrix calculation)

mariob92 6 tháng trước cách đây
mục cha
commit
5f9187f0f2
3 tập tin đã thay đổi với 30 bổ sung27 xóa
  1. 1 0
      .gitignore
  2. 4 3
      glm/gtx/transform2.hpp
  3. 25 24
      glm/gtx/transform2.inl

+ 1 - 0
.gitignore

@@ -47,6 +47,7 @@ test/gtc/*.dds
 Makefile
 Makefile
 *.cbp
 *.cbp
 *.user
 *.user
+.idea/
 
 
 # Misc.
 # Misc.
 *.log
 *.log

+ 4 - 3
glm/gtx/transform2.hpp

@@ -57,9 +57,10 @@ namespace glm
 	// Identity + tan(angle) * cross(Normal, OnPlaneVector)     0
 	// Identity + tan(angle) * cross(Normal, OnPlaneVector)     0
 	// - dot(PointOnPlane, normal) * OnPlaneVector              1
 	// - dot(PointOnPlane, normal) * OnPlaneVector              1
 
 
-	// Reflect functions seem to don't work
-	//template<typename T> mat<3, 3, T, Q> reflect2D(const mat<3, 3, T, Q> & m, const vec<3, T, Q>& normal){return reflect2DGTX(m, normal);}									//!< \brief Build a reflection matrix (from GLM_GTX_transform2 extension)
-	//template<typename T> mat<4, 4, T, Q> reflect3D(const mat<4, 4, T, Q> & m, const vec<3, T, Q>& normal){return reflect3DGTX(m, normal);}									//!< \brief Build a reflection matrix (from GLM_GTX_transform2 extension)
+	//! Build a reflection matrix.
+	//! From GLM_GTX_transform2 extension.
+	template<typename T, qualifier Q>
+	GLM_FUNC_DECL mat<4, 4, T, Q> reflect3D(vec<3, T, Q> const& normal, T distance);
 
 
 	//! Build planar projection matrix along normal axis.
 	//! Build planar projection matrix along normal axis.
 	//! From GLM_GTX_transform2 extension.
 	//! From GLM_GTX_transform2 extension.

+ 25 - 24
glm/gtx/transform2.inl

@@ -45,33 +45,34 @@ namespace glm
 		return m * r;
 		return m * r;
 	}
 	}
 
 
-	template<typename T, qualifier Q>
-	GLM_FUNC_QUALIFIER mat<3, 3, T, Q> reflect2D(mat<3, 3, T, Q> const& m, vec<3, T, Q> const& normal)
-	{
-		mat<3, 3, T, Q> r(static_cast<T>(1));
-		r[0][0] = static_cast<T>(1) - static_cast<T>(2) * normal.x * normal.x;
-		r[0][1] = -static_cast<T>(2) * normal.x * normal.y;
-		r[1][0] = -static_cast<T>(2) * normal.x * normal.y;
-		r[1][1] = static_cast<T>(1) - static_cast<T>(2) * normal.y * normal.y;
-		return m * r;
-	}
+	// template<typename T, qualifier Q>
+	// GLM_FUNC_QUALIFIER mat<3, 3, T, Q> reflect2D(mat<3, 3, T, Q> const& m, vec<3, T, Q> const& normal)
+	// {
+	// 	mat<3, 3, T, Q> r(static_cast<T>(1));
+	// 	r[0][0] = static_cast<T>(1) - static_cast<T>(2) * normal.x * normal.x;
+	// 	r[0][1] = -static_cast<T>(2) * normal.x * normal.y;
+	// 	r[1][0] = -static_cast<T>(2) * normal.x * normal.y;
+	// 	r[1][1] = static_cast<T>(1) - static_cast<T>(2) * normal.y * normal.y;
+	// 	return m * r;
+	// }
 
 
 	template<typename T, qualifier Q>
 	template<typename T, qualifier Q>
-	GLM_FUNC_QUALIFIER mat<4, 4, T, Q> reflect3D(mat<4, 4, T, Q> const& m, vec<3, T, Q> const& normal)
+	GLM_FUNC_DECL mat<4, 4, T, Q> reflect3D(vec<3, T, Q> const& normal, T distance)
 	{
 	{
-		mat<4, 4, T, Q> r(static_cast<T>(1));
-		r[0][0] = static_cast<T>(1) - static_cast<T>(2) * normal.x * normal.x;
-		r[0][1] = -static_cast<T>(2) * normal.x * normal.y;
-		r[0][2] = -static_cast<T>(2) * normal.x * normal.z;
-
-		r[1][0] = -static_cast<T>(2) * normal.x * normal.y;
-		r[1][1] = static_cast<T>(1) - static_cast<T>(2) * normal.y * normal.y;
-		r[1][2] = -static_cast<T>(2) * normal.y * normal.z;
-
-		r[2][0] = -static_cast<T>(2) * normal.x * normal.z;
-		r[2][1] = -static_cast<T>(2) * normal.y * normal.z;
-		r[2][2] = static_cast<T>(1) - static_cast<T>(2) * normal.z * normal.z;
-		return m * r;
+		mat<4, 4, T, Q> result(static_cast<T>(1));
+		result[0][0] = static_cast<T>(1) - static_cast<T>(2) * normal.x * normal.x;
+		result[0][1] = -static_cast<T>(2) * normal.y * normal.x;
+		result[0][2] = -static_cast<T>(2) * normal.z * normal.x;
+		result[1][0] = -static_cast<T>(2) * normal.x * normal.y;
+		result[1][1] = static_cast<T>(1) - static_cast<T>(2) * normal.y * normal.y;
+		result[1][2] = -static_cast<T>(2) * normal.z * normal.y;
+		result[2][0] = -static_cast<T>(2) * normal.x * normal.z;
+		result[2][1] = -static_cast<T>(2) * normal.y * normal.z;
+		result[2][2] = static_cast<T>(1) - static_cast<T>(2) * normal.z * normal.z;
+		result[3][0] = -static_cast<T>(2) * normal.x * distance;
+		result[3][1] = -static_cast<T>(2) * normal.y * distance;
+		result[3][2] = -static_cast<T>(2) * normal.z * distance;
+		return result;
 	}
 	}
 
 
 	template<typename T, qualifier Q>
 	template<typename T, qualifier Q>