light: add GLM_ProjectPointOntoPlane

This commit is contained in:
Eric Wasylishen 2017-02-22 01:10:35 -07:00
parent 64e8090326
commit d88581e2da
3 changed files with 25 additions and 0 deletions

View File

@ -400,6 +400,14 @@ float GLM_DistAbovePlane(const glm::vec4 &plane, const glm::vec3 &point)
return dot(vec3(plane), point) - plane.w;
}
glm::vec3 GLM_ProjectPointOntoPlane(const glm::vec4 &plane, const glm::vec3 &point)
{
float dist = GLM_DistAbovePlane(plane, point);
vec3 move = -dist * vec3(plane);
return point + move;
}
glm::vec3 GLM_PolyCentroid(const std::vector<glm::vec3> &points)
{
Q_assert(points.size() >= 3);

View File

@ -329,6 +329,7 @@ float GLM_EdgePlanes_PointInsideDist(const std::vector<glm::vec4> &edgeplanes, c
glm::vec3 GLM_TriangleCentroid(const glm::vec3 &v0, const glm::vec3 &v1, const glm::vec3 &v2);
float GLM_TriangleArea(const glm::vec3 &v0, const glm::vec3 &v1, const glm::vec3 &v2);
float GLM_DistAbovePlane(const glm::vec4 &plane, const glm::vec3 &point);
glm::vec3 GLM_ProjectPointOntoPlane(const glm::vec4 &plane, const glm::vec3 &point);
glm::vec3 GLM_PolyCentroid(const std::vector<glm::vec3> &points);
glm::vec4 GLM_PolyPlane(const std::vector<glm::vec3> &points);
/// Returns the index of the polygon edge, and the closest point on that edge, to the given point

View File

@ -402,6 +402,22 @@ TEST(mathlib, BarycentricRandom) {
}
}
TEST(mathlib, DistAbovePlane) {
vec4 plane(0, 0, 1, 10);
vec3 point(100, 100, 100);
EXPECT_FLOAT_EQ(90, GLM_DistAbovePlane(plane, point));
}
TEST(mathlib, ProjectPointOntoPlane) {
vec4 plane(0, 0, 1, 10);
vec3 point(100, 100, 100);
vec3 projected = GLM_ProjectPointOntoPlane(plane, point);
EXPECT_FLOAT_EQ(100, projected.x);
EXPECT_FLOAT_EQ(100, projected.y);
EXPECT_FLOAT_EQ(10, projected.z);
}
TEST(mathlib, InterpolateNormals) {
// This test relies on the way GLM_InterpolateNormal is implemented