Matrix Problems

I have an application where the user can rotate or translate around a model and zoom. This is achieved using glTranslatef glRotatef etc.

I have implemented a reset view button which resets the model view matrix.

I need to add a fit view option which resets any transformations so that the model is in the middle of the viewport but does not affect the rotation of the model.

How would I best achieve this? Is it possible by purely changing the model view matrix? Perhaps I should cahnge my code so that translation is done my moving the camera and therefore I could reset this matrix leaving the one which affects the model.

Thanks in advance,

Rob

You can project the model location onto the view vector (a dot product of vector to model and unit view vector * unit view vec I think). This will give you the new model location (if you consider the eye position) and subtracting the old location will give you a translation vector for the to place it in front of the viewer but at the same distance.

If you need it to be closer you need to use the bounds to figure out the required viewing distance. This can give you a more direct translation to the viewer, it is pretty easy to simply translate from old position to new position along the view vector.

Obviously this requires eye position and view vector in world space but if you don’t have that it should be simple to produce.

Dr Dorbie,

I am also need solution for problem similar to the one posted by Rob

But I didn’t understood solution posted by you. A few lines of source can throw more light on.

How to implement the following

a dot product of vector to model and unit view vector * unit view vec in opengl

Rajesh.R
IRIS, CAIR,
Bangalore - 1