diff --git a/src/lol/math/geometry.h b/src/lol/math/geometry.h index e3932397..03fb100d 100644 --- a/src/lol/math/geometry.h +++ b/src/lol/math/geometry.h @@ -184,7 +184,7 @@ vec3 ProjPointOnPlane(vec3 const &point, vec3 const &planeP, vec3 const &planeN) bool RayIsectPlane(vec3 const &rayP0, vec3 const &rayP1, vec3 const &planeP, vec3 const &planeN, vec3 &vIsec, bool test_line_only = false); - +bool TestPointInFrustum(const vec3& point, const mat4& frustum, vec3* result_point=nullptr); } /* namespace lol */ #endif // __LOL_MATH_GEOMETRY_H__ diff --git a/src/math/geometry.cpp b/src/math/geometry.cpp index 376b55f8..25644f02 100644 --- a/src/math/geometry.cpp +++ b/src/math/geometry.cpp @@ -289,5 +289,18 @@ namespace lol return true; } + //-- + bool TestPointInFrustum(const vec3& point, const mat4& frustum, vec3* result_point) + { + vec4 proj_point = frustum * vec4(point, 1.f); + proj_point /= proj_point.w; + + if (result_point) + *result_point = proj_point.xyz; + for (int i = 0; i < 3; i++) + if (lol::abs(proj_point[i]) > 1.f) + return false; + return true; + } } /* namespace lol */