Sign in to follow this  
giugio

OpenGL gllookat and center mesh from bounding sphere

Recommended Posts

Hello.
I have a big opengl model (formed by many meshes)and his bounding sphere.
How i can set the camera with gllookat so as center the camera on the model ?
Pratically ,I would see the entire model .
and in webgl is the same ?
because i need both(opengl and webgl)

Share this post


Link to post
Share on other sites
You view is defined by two transformations:

[list][*]Camera orientation (view matrix) - this is the one you are setting with lookAt. Basically this is the real world placement of camera - position and direction.[*]Projection matrix - this defines the "optical parameters" of the camera - field of vision and near and far clipping planes.[/list]To make the whole of your object visible, you have first to decide camera position. If you do not care, choose something like 4 x radius from the center of your object in some direction.

Then you can set the camera orientation with gluLookAt, giving the camera position, bounding sphere center and up direction as parameters.

Projection has to be set separately with glFrustum / gluPerspective (perspective) or glOrtho (isometric). Calculating proper parameters for glFrustum needs some trigonometry.

You can take look at [url="http://www.opengl.org/resources/faq/technical/viewing.htm"]http://www.opengl.org/resources/faq/technical/viewing.htm[/url] for more examples and explanations.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this