# glLookAt camera rotation help

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

## Recommended Posts

Ok im having a little trouble figuring this out. And yes this is (was) homework that is already handed in and i lost marks for not getting the camera motion correct. So maybe you guys can help. So what i have to do is use the glLookAt function to rotate my object up and down (x axis) left and right (y axis). We also have to zoom in and out which i got working fine. So this is what i have: P be a specific point centrally located on the submersible, this point is defined with center.x, center.y, center.z (struct) in glLookAt. The values are set in init().
glColor3f(0.0f, 0.0f, 1.0f); // set the color to blue
gluLookAt(eye.x, eye.y, eye.z, center.x, center.y, center.z, up.x, up.y, up.z);
glGetFloatv(GL_MODELVIEW_MATRIX, mm);

I also get the MODELVIEW Matrix and store it in an array to use for matrix multiplication and stuff. I am having trouble doing this: "Use the up and down arrow keys to rotate the center of projection up or down about point P." I know how to set the up and down keys and register it with glutSpecialFunc() but my matrix arithmetic is all messed up. This is my code:
// rotate sub up and down
case GLUT_KEY_UP:
// The transformed matrix of rotate left/right is constructed as:
// M = T(centerX, centerY, centerZ) * R(angle, mm[0], mm[4], mm[8]) * T(-centerX, -centerY, -centerZ)
// Initialize the transformed matrix..

// Translate to P(center.x, center.y, center.z).
// M = T(centerX, centerY, centerZ)

transformM.multMatrix(tempM);

// Rotate about X axis of eye coordinates.
// M = T(centerX, centerY, centerZ) * R(angle, mm[0], mm[4], mm[8])
transformM.multMatrix(tempM);

// Translate back.
// M = T(centerX, centerY, centerZ) * R(angle, mm[0], mm[4], mm[8]) * T(-centerX, -centerY, -centerZ)
transformM.multMatrix(tempM);
//eye.x++;
// Transform the EYE position.
eye = transformM.transformPoint(eye.x, eye.y, eye.z);
break;
case GLUT_KEY_DOWN:
// The transformed matrix of rotate left/right is constructed as:
// M = T(centerX, centerY, centerZ) * R(angle, mm[0], mm[4], mm[8]) * T(-centerX, -centerY, -centerZ)
// Initialize the transformed matrix..

// Translate to P(center.x, center.y, center.z).
// M = T(centerX, centerY, centerZ)

transformM.multMatrix(tempM);

// Rotate about X axis of eye coordinates.
// M = T(centerX, centerY, centerZ) * R(angle, mm[0], mm[4], mm[8])
transformM.multMatrix(tempM);

// Translate back.
// M = T(centerX, centerY, centerZ) * R(angle, mm[0], mm[4], mm[8]) * T(-centerX, -centerY, -centerZ)
transformM.multMatrix(tempM);
//eye.x++;
// Transform the EYE position.
eye = transformM.transformPoint(eye.x, eye.y, eye.z);
break;

It rotates around the x axis ok but when it gets to a certain point it just gets all screwed up. Can someone tell me if im doing this right? Im sure the commented code is good enough for explanation.

##### Share on other sites

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

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628686
• Total Posts
2984237

• 16
• 13
• 13
• 10
• 10