Sign in to follow this  

Rotating the camera around a certain point instead of viewpoint

This topic is 3318 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Right now, in my application, you can move around in a 3D world with the arrow keys. When you press the right key, the camera rotates about the y axis, when you press the up key, you move forward, etc. But I recently got an MD2 model loader working and want the user to be able to control a model. The only problem arises when rotating the model (with the right/left keys), as the rotation takes place about the viewpoint and not the model, which is 3 units away from the viewpoint. The way I control rotation is by modifying a float variable which is rotation when the keys are pressed and applying these rotations right before drawing the scene. Here's how:
...
if (arrows[ARROW_LEFT] == 1)
{
	rotY -= 0.24;
	if (rotY < -360) rotY += 360;
}
...
void updateCamera()
{
	glRotatef(rotX, 1.0, 0.0, 0.0);
	glRotatef(rotY, 0.0, 1.0, 0.0);
	glTranslatef(-posX, -posY, -posZ);
}
...
void drawScene()
{
        glMatrixMode(GL_MODELVIEW);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
        updateCamera();

       //Draw stuff
}


So how can I perform the rotation about the model's y axis?

Share this post


Link to post
Share on other sites

This topic is 3318 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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