diff --git a/common/mathlib.cc b/common/mathlib.cc index 89d5efd7..e91c92ed 100644 --- a/common/mathlib.cc +++ b/common/mathlib.cc @@ -558,6 +558,11 @@ GLM_TriangleArea(const qvec3f &v0, const qvec3f &v1, const qvec3f &v2) return 0.5f * qv::length(qv::cross(v2 - v0, v1 - v0)); } +qvec4f GLM_MakePlane(const qvec3f &normal, const qvec3f &point) +{ + return qvec4f(normal[0], normal[1], normal[2], qv::dot(point, normal)); +} + float GLM_DistAbovePlane(const qvec4f &plane, const qvec3f &point) { return qv::dot(qvec3f(plane), point) - plane[3]; diff --git a/include/common/mathlib.hh b/include/common/mathlib.hh index ededf084..b2cfdcb6 100644 --- a/include/common/mathlib.hh +++ b/include/common/mathlib.hh @@ -322,6 +322,7 @@ bool GLM_EdgePlanes_PointInside(const std::vector &edgeplanes, const qve float GLM_EdgePlanes_PointInsideDist(const std::vector &edgeplanes, const qvec3f &point); qvec3f GLM_TriangleCentroid(const qvec3f &v0, const qvec3f &v1, const qvec3f &v2); float GLM_TriangleArea(const qvec3f &v0, const qvec3f &v1, const qvec3f &v2); +qvec4f GLM_MakePlane(const qvec3f &normal, const qvec3f &point); float GLM_DistAbovePlane(const qvec4f &plane, const qvec3f &point); qvec3f GLM_ProjectPointOntoPlane(const qvec4f &plane, const qvec3f &point); float GLM_PolyArea(const std::vector &points); diff --git a/light/test_light.cc b/light/test_light.cc index 4fa97560..5a2d4da6 100644 --- a/light/test_light.cc +++ b/light/test_light.cc @@ -282,6 +282,11 @@ TEST(mathlib, RotateFromUpToSurfaceNormal) { } } +TEST(mathlib, MakePlane) { + EXPECT_EQ(qvec4f(0, 0, 1, 10), GLM_MakePlane(qvec3f(0,0,1), qvec3f(0,0,10))); + EXPECT_EQ(qvec4f(0, 0, 1, 10), GLM_MakePlane(qvec3f(0,0,1), qvec3f(100,100,10))); +} + TEST(mathlib, DistAbovePlane) { qvec4f plane(0, 0, 1, 10); qvec3f point(100, 100, 100);