Skip to main content
gamedev.net
🔒 Locked

Fit View Operation

Started by robertstone Jan 25, 2006 at 4:30 AM 2 replies 1.5k views
Original Post
robertstone
robertstone
Hi everyone, I have a program where the user can rotate and translate around an OpenGl model as well as zooming. I have a reset view button which cancels all of these by reseting the model view matrix. I wish to add a "fit" button which moves the model to the centre of the viewport and sets the zoom so that it fills the viewport but does not change the rotation of the model. I'm not sure how to do this, I have experimented with: gluLookAt(0,0,0,m_contentCentre[0],m_contentCentre[1],m_contentCentre[2],0,1,0); but I cannot get this to work. Can someone please tell me the best way to achieve this. Thanks in advance, Rob
Libe
Libe
Quote:
Original post by robertstone
I wish to add a "fit" button which moves the model to the centre of the viewport and sets the zoom so that it fills the viewport but does not change the rotation of the model.

I'm doing it in this way, I think other ways exist but here's a pretty simple one:

float r = wBoundSphere.GetRadius();Point c = wBoundSphere.GetCenter(); float dz = r / tanf( Radians( frustumInfo.fovy * 0.5 ) );newPos = c + k * dz; 


Basically, once you get a bounding sphere of your scene, you can imagine to start moving backward, from the center of it, along your camera view vector (k, in the code above), till the radius is entirely visible (and so the objects inside of the bounding sphere). A little trig does the trick.

Ciao
Libe




Libero Spagnolini
robertstone
robertstone
Thanks for the reply,

I kind of hoped there would be a function to do this as part of openGl as it is something lots of people would want to do.

Thanks again,

Rob
vancom
vancom
Hi Robertstone

can you post a code how did you implement rotate, translate and zooming.

thanx

vanCom

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.