I'm adding frustum culling into my game engine, but I have some design issues regarding the frustum and the cameras. Should the frustum be a member of the camera, or vice versa ? Should a camera be built from a frustum or should the camera build and maintain it's own frustum ?
|
|
Short Answer Make your frustum class independent from any camera implementation - it only requires a combined view-projection matrix to be created. Then, add a frustum instance to your camera class. Think about it - it makes sense to think that a Long Answer A As for how to build the Finally, as for whether one class should contain the other, my opinion is that, if anything, your camera class could manage a frustum object and keep it in sync. I think doing it the other way around would be a bad design choice, because the frustum is a lower level concept than the camera, and the frustum shouldn't have to rely on a specific camera implementation. Or the simple argument that composition should be used to implement Example In sum, something like this for the frustum class (just to give you an idea, it might have other members and features too):
With your camera class being something like (once again not a complete example):
|
|||||||||
|