light: add MakePlane function

This commit is contained in:
Eric Wasylishen 2017-12-10 21:28:35 -07:00
parent 6c529fb0c3
commit d31d3621bc
3 changed files with 11 additions and 0 deletions

View File

@ -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];

View File

@ -322,6 +322,7 @@ bool GLM_EdgePlanes_PointInside(const std::vector<qvec4f> &edgeplanes, const qve
float GLM_EdgePlanes_PointInsideDist(const std::vector<qvec4f> &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<qvec3f> &points);

View File

@ -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);