Links of Interest
Main
Download
Prerequisites
Screenshots

Articles/Code Snippets
DBP Warmup Entries
Blog feed icon
Contact/Feedback

Quick Downloads:
bullet Diaspora
bullet XNA Requirements Installer

External Links
Heather [layout designer]
XNA

Viewport Culling
A simple way to check to see whether an object should be rendered is to use the BoundingFrustum class. Declare a viewFrustum, and whenever you change the view or projection matrices, make sure you update the viewFrustum variable.

BoundingFrustum viewFrustum;
viewFrustum = new BoundingFrustum(view * projection);

And to use it, I do a check within a game entity. There are three possible return values, Contains, Intersects, and Disjoint. Since we want to objects even if only part of it is visible, you want Contains and Intersects. You can either check to see whether is is !ContainmentType.Disjoint, but then if any more ContainmentTypes are added, your code could be broken. The safest way is as follows:

public override void Draw(GameTime gameTime)
{
    if(viewFrustum.Contains(model.Meshes[0].BoundingSphere) == ContainmentType.Contains ||
        viewFrustum.Contains(model.Meshes[0].BoundingSphere) == ContainmentType.Intersects)
    {
        // Draw the model
    }
}

This website and its content are the property of ascii reversal of the ascii of the hex reversal of the hex of the bit inverse of 11001111 11001111 11001000 11001010 11000110 11001001 10111100 11001001 10111100 11001001 11000110 11001001 11001110 11001001 10111011 11001001 11001111 11001101 10111100 11001011 11000110 11001001.