Panning and rotation...

Started by
0 comments, last by Farfadet 16 years, 11 months ago
I'm trying to make a simple model viewer that does mouse panning and rotation. I got panning and rotation to work in isolation, but I can't seem to combine them in the way I'd like. Here's what I'd like to happen: Panning around changes the 'center' of the model. Any further rotations will be about this new center point. What I got right now is like this: glTranslatef(0.0f, 0.0f, -10.0f); // move away from the model a bit glTranslatef(xoffset, -yoffset, 0.0f); // pan DoRotation(); Render(); This results in correct panning, but the rotation is still centered about the model's origin. Swapping the pan translation and DoRotation() works for the first pan, but subsequent rotations mess up the panning.
Advertisement
To rotate about the center of your model, you must first apply the rotation matrix, then translation. Any subsequent call to glRotation will again rotate about the origin, so what you have to do is keep the global (cumulated) translation and rotation in some variables of your app, and each time call

glLoadIdentity
rotate
translate

This topic is closed to new replies.

Advertisement