|
Links of Interest
MainDownload Prerequisites Screenshots Articles/Code Snippets DBP Warmup Entries Blog Contact/Feedback Quick Downloads:
Diaspora
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;
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:
viewFrustum = new BoundingFrustum(view * projection); 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 } } |