PDA

View Full Version : glOrtho + Bounding Box problem



jimwalks
08-16-2011, 02:30 PM
Hi Everyone,

I'm currently writing a program to visualize STL files using OpenGL. The problem I face is that the STL objects are dynamic in size and therefore I need to initialize my camera settings dynamically.

From what I have researched, so far I have computed a bounding box by finding the minimum and maximum x,y and z points in the scene. From this I have tried to input these coordinates into glOrtho and aimed the camera to the center of the scene using gluLookAt. However, this gives incorrect results and often the model is outside of the scope of the window.

Could anyone tell me if I am going about this correctly? Or have any example code of how to set up an opengl scene using a bounding box.

Thanks so much,

Jim

AleaIactaEst
08-16-2011, 03:41 PM
There is no such thing like a camera when you're using an orthographic projection, so you should not use gluLookAt.

If your model is still (partially) outside of the viewing volume you should check your algorithm that calculates the bounding box, that's were i'd search first.

jimwalks
08-16-2011, 03:51 PM
Thanks for your response.

Do I only need to use glOrtho by itself? With the correct bounding box coordinates entered into glOrtho should this work?

Alfonse Reinheart
08-16-2011, 05:26 PM
Could anyone tell me if I am going about this correctly?

Your problem is one of spaces. The camera transform comes before the orthographic projection.

Your glOrtho calls create an orthographic projection that is centered around the object. But you center it around the object in world space, not camera space. glOrtho's values are supposed to be in camera space.

So basically, you need to take your bounding box and transform it by your gluLookAt matrix.


There is no such thing like a camera when you're using an orthographic projection

Yes there is. An orthographic projection is a 3D projection, just like a perspective one. There is nothing that says you can't have a camera if you're orthographically projecting the world.