Jump to content
  • Advertisement
Sign in to follow this  

Rotating the camera around a certain point instead of viewpoint

This topic is 3623 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()

       //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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!