Skip to main content
gamedev.net
🔒 Locked

Viewing

Started by beginnerfurqan 0 replies 750+ views
Original Post
beginnerfurqan
beginnerfurqan
this is the code im using to move an object: static int shoulder = 0, elbow = 0, fingerone = 0; static void myDisplay(void) .. glRotatef (shoulder, 0.0, 0.0, 1.0); //create object void myKeyboard switch (key) { case 's': shoulder = (shoulder + 5) % 360; glutPostRedisplay (); break; case 'S': however, this rotates the objects. what i would like to do is move the camera instead. what command would i need? can anyone help please.
Zakwayda
Zakwayda
Let's say your camera has position camX, camY, camZ, and a rotation camRot about some axis. Given that, the following code should rotate and position your camera and object correctly:

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(-camRot, 0.0, 1.0, 0.0); // Or whatever axis you want to rotate around
glTranslatef(-camX, -camY, -camZ);
glTranslatef(shoulderX, shoulderY, shoulderZ); // If you want to translate your object also
glRotatef(shoulder, 0.0, 0.0, 1.0);

As to the why's, that's a fairly big subject. I'd start with the Red Book, if you have it, and look at the sections on coordinate systems and camera and object transforms.

Topic Locked

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

Sign in to reply to this topic.