Browse Source

Added Test Point in Frustum

undefined
Benjamin ‘Touky’ Huet Sam Hocevar <sam@hocevar.net> 10 years ago
parent
commit
88a4859287
2 changed files with 14 additions and 1 deletions
  1. +1
    -1
      src/lol/math/geometry.h
  2. +13
    -0
      src/math/geometry.cpp

+ 1
- 1
src/lol/math/geometry.h View File

@@ -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__


+ 13
- 0
src/math/geometry.cpp View File

@@ -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 */


Loading…
Cancel
Save