diff --git a/src/lol/math/geometry.h b/src/lol/math/geometry.h index 82c80047..a6e43d1e 100644 --- a/src/lol/math/geometry.h +++ b/src/lol/math/geometry.h @@ -261,6 +261,39 @@ bool TestRayVsPlane(const TV &ray_p0, const TV &ray_p1, return true; } +/* A safe enum for Primitive edge face. */ +struct PlaneIntersection +{ + enum Value + { + Invalid=-1, + Back, + Front, + Plane, + + MAX + } + m_value; + + inline PlaneIntersection() : m_value(Invalid) {} + inline PlaneIntersection(Value v) : m_value(v) {} + inline PlaneIntersection(int v) : m_value((Value)v) {} + inline operator Value() { return m_value; } +}; + +//Point/Plane : Normal must be given normalized. +template +PlaneIntersection TestPointVsPlane(const TV &point, const TV &plane_p, const TV &plane_n) +{ + float d = dot(normalize(point - plane_p), plane_n); + if (d > TestEpsilon::Get()) + return PlaneIntersection::Front; + else if (d < -TestEpsilon::Get()) + return PlaneIntersection::Back; + else + return PlaneIntersection::Plane; +} + //Project points functions //Plane template