Implement #1370 (reflection matrix calculation)

This commit is contained in:
mariob92
2025-05-21 14:19:19 +02:00
committed by Christophe
parent a583c59e16
commit 5f9187f0f2
3 changed files with 30 additions and 27 deletions

1
.gitignore vendored
View File

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

View File

@@ -57,9 +57,10 @@ namespace glm
// Identity + tan(angle) * cross(Normal, OnPlaneVector) 0
// - 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.
//! From GLM_GTX_transform2 extension.

View File

@@ -45,33 +45,34 @@ namespace glm
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>
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>