Jump to content
  • Advertisement
Sign in to follow this  
elias4444

OpenGL Most efficient method for on-screen check?

This topic is 3544 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

Ok, I use openGL, and have several objects being rendered in a scene (several = up to around 100). The camera's position, including rotation, is regularly changing. I can check each object's screen position each frame by using gluProject(), but it's rather expensive on the framerate just to determine if the object is on the screen or not (to decide whether or not to render it). I know this is a VERY common issue with openGL programming, and so I'm guessing that it's been solved time and time again. Would someone please share the secret? I searched the forums, but couldn't find any solution other than using gluProject().

Share this post


Link to post
Share on other sites
Advertisement
Sphere-Frustum intersections are usually implemented as a set of 5-6 sphere-plane tests, which are very straightforward. more info. For greater performance, consider the use of a spatial culling structure.

Share this post


Link to post
Share on other sites
A faster method might be to check to see if the object's bounding box (or part of it) is in the view volume. Check out "occlusion culling" or "View frustum culling".

Share this post


Link to post
Share on other sites
You are looking at the problem upside down.

Instead of checking if the an object is where you clicked by projecting every object onto the screen manually:

You need to get the position of the click, calculate the ray (with an inverse matrix of projection/modelview) and test this ray intersection with bounding box/sphere of your objects.

Share this post


Link to post
Share on other sites
The hint about searching for View Frustum Culling was what I needed. After searching on that, I found several tutorials that worked quite well.

Thanks to all who offered help!

Share this post


Link to post
Share on other sites
Just a heads up, there are a few ways you can do View Frustum culling.

The simple and fast method is to create AABBs for each object in the world, then do half-space tests on each of the planes. AABBs are typically faster, since (if properly done) they contain only positional checks. Spheres are just a tad slower. If you are only ever going to use spheres in your world, it's probably faster to use spheres as bounding volumes for accuracy (such that non-visible spheres will never be rendered). However, it typically goes such that spheres are more desirable for objects whose orientation may change, and AABBs are more desirable for objects who retain their orientation.

A nice tutorial on view frustum culling: http://www.lighthouse3d.com/opengl/viewfrustum/

The more complex but very fast method is to create a spacial partitioning system and couple it with the frustum culling. If you're not familiar with spacial partitioning, I would suggest looking up some tutorials. I will go as far as to say that any major game these days has SOME form of spatial partitioning.

A few different spatial partitioning systems are: K-DOPS, KD-Trees, Octrees, Quadtrees, and Binary Spatial Partitioning (BSP Tree).

Also, if you really want to speed things up, you can implement occlusion culling on the objects that are still on the screen.

If you still want to optimize, let me know and I'll see what I can cook up! Have a nice day! :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!