• Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

# Frustum culling against a sphere

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

6 replies to this topic

### #1MARS_999  GDNet+   -  Reputation: 820

Like
0Likes
Like

Posted 17 June 2012 - 07:49 PM

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?

### #2CulDeVu  Members   -  Reputation: 149

Like
0Likes
Like

Posted 17 June 2012 - 07:58 PM

The problem that I see (with the limited information) is that just because the center of the sphere is outside the frustrum doesn't mean that the entire sphere is.

### #3MARS_999  GDNet+   -  Reputation: 820

Like
0Likes
Like

Posted 17 June 2012 - 08:03 PM

```

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

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

}

{

}

```

### #4jefferytitan  Members   -  Reputation: 1006

Like
0Likes
Like

Posted 17 June 2012 - 08:07 PM

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:
http://www.flipcode.com/archives/Frustum_Culling.shtml

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

### #5dpadam450  Members   -  Reputation: 536

Like
0Likes
Like

Posted 17 June 2012 - 08:13 PM

Take it down to 1 object and observe what happens in a bunch of cases. Just looking at objects disappear randomly will not help.
Could be in your extract function. What is sc?

### #6MARS_999  GDNet+   -  Reputation: 820

Like
0Likes
Like

Posted 17 June 2012 - 08:15 PM

sphere center

The extraction is from

http://cmldev.net/

### #7MARS_999  GDNet+   -  Reputation: 820

Like
0Likes
Like

Posted 17 June 2012 - 08:40 PM

F! ME!

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

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

Thanks all!

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS