Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ test/gtc/*.dds
Makefile
*.cbp
*.user
.idea/

# Misc.
*.log
Expand Down
12 changes: 9 additions & 3 deletions glm/gtx/transform2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,15 @@ 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)
//! Reflects a matrix on an arbitrary plane.
//! From GLM_GTX_transform2 extension.
template<typename T, qualifier Q>
GLM_FUNC_DECL mat<3, 3, T, Q> reflect2D(mat<3, 3, T, Q> const& m, vec<2, T, Q> const& normal, T distance);

//! Reflects a matrix on an arbitrary plane.
//! From GLM_GTX_transform2 extension.
template<typename T, qualifier Q>
GLM_FUNC_DECL mat<4, 4, T, Q> reflect3D(mat<4, 4, T, Q> const& m, vec<3, T, Q> const& normal, T distance);

//! Build planar projection matrix along normal axis.
//! From GLM_GTX_transform2 extension.
Expand Down
19 changes: 11 additions & 8 deletions glm/gtx/transform2.inl
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,34 @@ namespace glm
}

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<2, T, Q> const& normal, T distance)
{
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[0][1] = -static_cast<T>(2) * normal.y * normal.x;
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[2][0] = -static_cast<T>(2) * normal.x * distance;
r[2][1] = -static_cast<T>(2) * normal.y * distance;
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_QUALIFIER mat<4, 4, T, Q> reflect3D(mat<4, 4, T, Q> const& m, 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[0][1] = -static_cast<T>(2) * normal.y * normal.x;
r[0][2] = -static_cast<T>(2) * normal.z * normal.x;
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[1][2] = -static_cast<T>(2) * normal.z * normal.y;
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;
r[3][0] = -static_cast<T>(2) * normal.x * distance;
r[3][1] = -static_cast<T>(2) * normal.y * distance;
r[3][2] = -static_cast<T>(2) * normal.z * distance;
return m * r;
}

Expand Down
1 change: 1 addition & 0 deletions test/gtx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ glmCreateTestGTC(gtx_spline)
glmCreateTestGTC(gtx_string_cast)
glmCreateTestGTC(gtx_structured_bindings)
glmCreateTestGTC(gtx_texture)
glmCreateTestGTC(gtx_transform2)
glmCreateTestGTC(gtx_type_aligned)
glmCreateTestGTC(gtx_type_trait)
glmCreateTestGTC(gtx_vec_swizzle)
Expand Down
135 changes: 135 additions & 0 deletions test/gtx/gtx_transform2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#include <glm/glm.hpp>
#include <glm/gtc/epsilon.hpp>

#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/transform2.hpp>

static int test_reflect2D()
{
int Error = 0;

{
const glm::mat3 m3(
1, 0, 0,
0, 1, 0,
1, 2, 1
);

const glm::mat3 eam3(
1, 0, 0,
0, -1, 0,
1, 2, 1
);

const glm::mat3 am3 = glm::reflect2D(
m3,
glm::vec2(0, 1),
static_cast<glm::mat3::row_type::value_type>(0)
);

Error += glm::all(glm::bvec3(
glm::all(glm::epsilonEqual(eam3[0], am3[0], glm::epsilon<float>())),
glm::all(glm::epsilonEqual(eam3[1], am3[1], glm::epsilon<float>())),
glm::all(glm::epsilonEqual(eam3[2], am3[2], glm::epsilon<float>())))) ? 0 : 1;
}

{
const glm::mat3 m3(
1, 0, 0,
0, 1, 0,
1, 2, 1
);

const glm::mat3 eam3(
0, 1, 0,
1, 0, 0,
1, 2, 1
);

const glm::mat3 am3 = glm::reflect2D(
m3,
glm::vec2(-0.70710678, 0.70710678),
static_cast<glm::mat3::row_type::value_type>(0)
);

Error += glm::all(glm::bvec3(
glm::all(glm::epsilonEqual(eam3[0], am3[0], glm::epsilon<float>())),
glm::all(glm::epsilonEqual(eam3[1], am3[1], glm::epsilon<float>())),
glm::all(glm::epsilonEqual(eam3[2], am3[2], glm::epsilon<float>())))) ? 0 : 1;
}

return Error;
}

static int test_reflect3D()
{
int Error = 0;

{
const glm::mat4 m4(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
);

const glm::mat4 eam4(
1, 0, 0, 0,
0, -1, 0, 0,
0, 0, 1, 0,
0, -2, 0, 1
);

const glm::mat4 am4 = glm::reflect3D(
m4,
glm::vec3(0, 1, 0),
static_cast<glm::mat4::row_type::value_type>(1)
);

Error += glm::all(glm::bvec4(
glm::all(glm::epsilonEqual(eam4[0], am4[0], glm::epsilon<float>())),
glm::all(glm::epsilonEqual(eam4[1], am4[1], glm::epsilon<float>())),
glm::all(glm::epsilonEqual(eam4[2], am4[2], glm::epsilon<float>())),
glm::all(glm::epsilonEqual(eam4[3], am4[3], glm::epsilon<float>())))) ? 0 : 1;
}

{
const glm::mat4 m4(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
);

const glm::mat4 eam4(
0, 1, 0, 0,
1, 0, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
);

const glm::mat4 am4 = glm::reflect3D(
m4,
glm::vec3(-0.70710678, 0.70710678, 0.0),
static_cast<glm::mat4::row_type::value_type>(0)
);

Error += glm::all(glm::bvec4(
glm::all(glm::epsilonEqual(eam4[0], am4[0], glm::epsilon<float>())),
glm::all(glm::epsilonEqual(eam4[1], am4[1], glm::epsilon<float>())),
glm::all(glm::epsilonEqual(eam4[2], am4[2], glm::epsilon<float>())),
glm::all(glm::epsilonEqual(eam4[3], am4[3], glm::epsilon<float>())))) ? 0 : 1;
}

return Error;
}

int main()
{
int Error = 0;

Error += test_reflect2D();
Error += test_reflect3D();

return Error;
}