Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Just starting out using XNA to draw 3D scenes and have a question about determining which objects are currently visible.

If I load many thousands of sprites and shapes in a scene, then render the current view from a camera, is it possible to actually find (e.g. list to a text file) the IDs of those visible objects?

I guess another way to ask this is to say: how can I get a list of objects (e.g. sprites) which are being drawn in the current viewport?

share|improve this question

migrated from stackoverflow.com Aug 28 '11 at 22:29

This question came from our site for professional and enthusiast programmers.

3 Answers 3

up vote 3 down vote accepted

You can check if the object's bounding is inside of the camera frustum.

you have the class BoundingFrustum that can manage intersections with BoundingBoxes or BoundingSpheres.

share|improve this answer
    
Thanks for your answer. I'll take a proper look now, but do you know if it reports all objects which are in the BoundingFrustrum regardless of it they're behind other objects (ie out of view).... or does it take this into account also? –  timemirror Aug 29 '11 at 16:03
    
only is useful to know the objects that are inside the camera frustum. what do you need? –  Blau Aug 29 '11 at 22:59
    
I'm trying to get a list of which objects are currently in view... as in they're not only within the bounding frustrum, but are visible to the user rather then hidden behind other objects. So essentially be able to have a list of current items being drawn on the screen... if that makes sense? –  timemirror Sep 1 '11 at 15:50

To go along with @Blau's answer, here is the MSDN documentation for BoundingFrustrum and related classes/methods:
http://msdn.microsoft.com/en-us/library/bb313876.aspx

share|improve this answer

To determine if a draw call rendered any pixels on screen what you need is an occlusion query.

You'll also need to do some extra work to get accurate results, as if you render a far away object first, then a nearby object afterwards that covers it will say both rendered pixels. The solution to that is to render everything in a near-far order.

Also note that you want to read the result of the query a frame or so after you issue it, to give the GPU enough time to output the result. If you don't wait it can affect performance significantly.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.