I’m trying to figure out how to size glOrtho so that it gets the tightest possible fit around a 3D box. Normally this would be simple – just make glOrtho’s dimensions the same as the box. But I rotate the box, so if I pass the box’s dimensions to glOrtho, vertices get rotated outside the view frustrum.

The first thing I tried was making all of the dimensions passed to glOrtho equal to the distance of the two farthest apart points of the box. This makes any rotation visible, but it’s not the best fit for any given rotation.

My trig skills are a little rusty. How can I figure out for a given rotation what the best fitting glOrtho parameters would be? I’m always drawing a rectangular box (i.e. not always all of the boxes dimensions are the same, could be 3x3x3 or 52x7x4).

After doing some googling, I managed to figure out that those are two different methods for doing collision detection. But, I can’t find instructions on how to do either and it isn’t obvious to me why either helps – a bounding box would fit directly around the box itself, not allowing rotation.

Thanks for the help, but I’m afraid it needs to be spelled out a little more for me. ‘Transform the box into camera space’ – that’s nontrivial for someone who’s just learned how to draw geoemetric primitives in OpenGL I’m not really sure what you mean.

Multiply the corner vertices of you bounding box with the current modelview matrix. This will give you the vertices as seen from camera. Take the min/max values of all eight transformed vertices and you have your new camera-space bounding box.

If you are still confused, you’ll probably want to hit the math books tonight

If you don’t understand at least the basics of coordinate spaces, it’s difficult to communicate simple concepts without getting bogged down in a lot of tangential mathematical detail. The math itself really isn’t difficult to learn, but it takes a good deal of time to explain, and it’s already covered in innumerable books and websites.