Sign in to follow this  

Frustum culling against a sphere

This topic is 2005 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using OpenGL and trying to culling spheres against the frustum... When I rotate around with the camera objects that should be on screen aren't and sometimes they are.

So I am not sure what is wrong, but with the planes normalized, I am assuming I need to pass in a normalized center point of the sphere?

Share this post


Link to post
Share on other sites
[code]

inline bool SphereInFrustum(const cml::vector<T, cml::fixed<3>>& sc, T radius)
{
for(int i = 0; i < PLANE_TOTAL; ++i)
{
T dist = planes[i][0] * sc[0] +
planes[i][1] * sc[1] +
planes[i][2] * sc[2] +
planes[i][3];
if(dist <= -radius)
return false;
}
return true;
}

inline void Update(void)
{
glGetFloatv(GL_PROJECTION_MATRIX, projection.data());
glGetFloatv(GL_MODELVIEW_MATRIX, modelview.data());
mvp = projection * modelview;
cml::extract_frustum_planes(mvp, planes, cml::z_clip_neg_one, true);
cml::get_frustum_corners(planes, corners);
}

if(frustum.SphereInFrustum((*it)->GetBoundingSphere().s.center, (*it)->GetBoundingSphere().s.radius))
{
}
[/code]

Share this post


Link to post
Share on other sites
It depends upon whether you are doing the frustrum culling yourself or using some API to do the culling. A built-in API which takes whole objects or polygons should be smart enough to take care of it. If you're doing it yourself, you need to ensure that you draw an object if any part of it could appear on-screen. Sometimes this is done by testing if any part of a bounding box is within the frustrum.

From a quick Google I found an example:
[url="http://www.flipcode.com/archives/Frustum_Culling.shtml"]http://www.flipcode.com/archives/Frustum_Culling.shtml[/url]

Under "Fundamental Methods 1" it shows an example for a sphere and an axis-aligned box.

Share this post


Link to post
Share on other sites
F! ME!

Sigh.................................................. hit head against wall........................... more..........

I misplaced a f'n glPopMatrix(); ;( SHOOT ME NOW!!!!!!


Thanks all!

Share this post


Link to post
Share on other sites

This topic is 2005 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this