3
\$\begingroup\$

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?

\$\endgroup\$

3 Answers 3

3
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ 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? \$\endgroup\$
    – timemirror
    Commented Aug 29, 2011 at 16:03
  • \$\begingroup\$ only is useful to know the objects that are inside the camera frustum. what do you need? \$\endgroup\$
    – Blau
    Commented Aug 29, 2011 at 22:59
  • \$\begingroup\$ 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? \$\endgroup\$
    – timemirror
    Commented Sep 1, 2011 at 15:50
0
\$\begingroup\$

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

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .