Sign in to follow this  
rrk

OpenGL Fit To screen/window

Recommended Posts

Hi, I was working on openGl for over 2 + years. Have some exposure to DirectX. Now due to client requirement, a CAD graphics engine needs to work on DirectX. I am able to resolve most of the grey areas with online resources and msdn examples. Thanks for posting online books. They are really useful. However, I was unable to find a way to fit a body (D3D mesh) on to screen. My requirement is as follows. Given: I have an axis aligned bounding box, bounding sphere encompassing the mesh being rendered. 1. I donot want to change the viewing direction. 2. I would like to modify the projection matrix and call render() once to manipulate the viewing area just wide enough to fit the mesh being rendered. {Fit to Screen}. 3. Would like to implement Zoom window. Any code snippets, links to webpages or ur suggestion will be welcome. Thanks.

Share this post


Link to post
Share on other sites
I don't think you want to change the projection matrix... ever. If you keep looking in the same direction, you will want to change the world matrix for the mesh to be "perfectly" viewable.
If this is the case, your world matrix will be depend on the size of your object, the direction of your view, and the projection matrix's field of view. The aspect ratio is important but can be neglected if the monitor is wider than it is tall. So do some math based on the field of view and the size of the object to determine the distance necessary. Then move that distance from the eye/camera position, along the view vector.

Hope that helps.

Share this post


Link to post
Share on other sites
Thanks for your reply.

In openGL, I am aware of Model_View matrix(4x4)and Projection_matrix(4x4). The effect of fit to screen is achived by panning and Zooming + or -. This combined camera position change can be achived by manipulating the projection matrix.
The World matric you are mentioning might at some stage be applied on the camera if I am not wrong.

My problem is how do I find this matrix which will produce the desired effect.
I have the math for OpenGl and somehow it does not seem to work in DirectX. The matrix in DirectX is the transpose of the representation in OpenGL. I have taken care of the most obvious pitfalls but it still does not work. If you think I may be missing something, then do let me know. If you have some example or code snippet, Please do share it with me.
Thanks in advance.

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