mirror of
https://github.com/g-truc/glm.git
synced 2026-06-08 02:23:48 +00:00
Implement #1370 (reflection matrix calculation)
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -47,6 +47,7 @@ test/gtc/*.dds
|
|||||||
Makefile
|
Makefile
|
||||||
*.cbp
|
*.cbp
|
||||||
*.user
|
*.user
|
||||||
|
.idea/
|
||||||
|
|
||||||
# Misc.
|
# Misc.
|
||||||
*.log
|
*.log
|
||||||
|
|||||||
@@ -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
|
//! Build a reflection matrix.
|
||||||
//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)
|
//! 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)
|
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.
|
||||||
|
|||||||
@@ -45,33 +45,34 @@ namespace glm
|
|||||||
return m * r;
|
return m * r;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, qualifier Q>
|
// 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)
|
// 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));
|
// 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][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][1] = -static_cast<T>(2) * normal.x * normal.y;
|
||||||
r[1][0] = -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;
|
// r[1][1] = static_cast<T>(1) - static_cast<T>(2) * normal.y * normal.y;
|
||||||
return m * r;
|
// 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));
|
mat<4, 4, T, Q> result(static_cast<T>(1));
|
||||||
r[0][0] = static_cast<T>(1) - static_cast<T>(2) * normal.x * normal.x;
|
result[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;
|
result[0][1] = -static_cast<T>(2) * normal.y * normal.x;
|
||||||
r[0][2] = -static_cast<T>(2) * normal.x * normal.z;
|
result[0][2] = -static_cast<T>(2) * normal.z * normal.x;
|
||||||
|
result[1][0] = -static_cast<T>(2) * normal.x * normal.y;
|
||||||
r[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;
|
||||||
r[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;
|
||||||
r[1][2] = -static_cast<T>(2) * normal.y * normal.z;
|
result[2][0] = -static_cast<T>(2) * normal.x * normal.z;
|
||||||
|
result[2][1] = -static_cast<T>(2) * normal.y * normal.z;
|
||||||
r[2][0] = -static_cast<T>(2) * normal.x * normal.z;
|
result[2][2] = static_cast<T>(1) - static_cast<T>(2) * normal.z * normal.z;
|
||||||
r[2][1] = -static_cast<T>(2) * normal.y * normal.z;
|
result[3][0] = -static_cast<T>(2) * normal.x * distance;
|
||||||
r[2][2] = static_cast<T>(1) - static_cast<T>(2) * normal.z * normal.z;
|
result[3][1] = -static_cast<T>(2) * normal.y * distance;
|
||||||
return m * r;
|
result[3][2] = -static_cast<T>(2) * normal.z * distance;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, qualifier Q>
|
template<typename T, qualifier Q>
|
||||||
|
|||||||
Reference in New Issue
Block a user