What the frustum!

I started working on writing a frustum culler (a thing that makes sure only objects in view are rendered) yesterday. I figured the hardest part would be the math for setting up the frustum shape, as it does require some linear algebra foo. It turned out to be much easier than I thought, as the ViewProjection matrix happens to have everything needed already in it. The frustum culling checks themselves were also pretty straight forward.

Everything was good until I ran the iPhone app. My scene of 64 physics cubes would initially load correctly, but as soon as I started to pan the camera groups of cubes would be randomly culled off the screen. This was at around 10:00pm. Since my ViewProjection matrix had worked flawlessly for all other rendering tasks, I assumed the issue must have been with the way the frustum was being generated. By around 12:00am I had tried every possible combination of creating my frustum, including treating the matrix as left/right-handed, row/column major and turning on and off normalization of the output planes. Nada. Rendering the planes in Graphing Calculator, minus the far plane, looked right:

So if the frustum construction code is right, then the ViewProjection matrix must somehow be wrong? Or maybe the frustum checks? Enter several more hours of no success, and an acceptance of defeat at 2:30 AM.

This morning I realized that my cubes’ position variables were not being set. The physics update code was copying the new positions directly into their mTransformMatrix variables and leaving the mPosition value at its starting position. The culler uses the position variable to determine where the object is. Dammit.

Needless to say, the frustum culler is now working. In fact, it’s the frustum culler from 10:00pm last night that works correctly. 😡



2 responses to “What the frustum!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: