Sign in to follow this  

gluLookAt - Camera rotation

This topic is 2848 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

Hi! I have some problem with a simple camera im trying to implement. For some reason the rotation switches at some positions in the world. A rotation up becomes a rotation down at some positions. Here is some of my code. vector3f cameraPos = vector3f(0.0f,0.0f,0.0f); vector3f cameraView = vector3f(0.0f,0.0f,1.0f); vector3f cameraUp = vector3f(0.0f,1.0f,0.0f); -----In the main loop, in a renderScene method----- // Select and set up the projection matrix glMatrixMode( GL_PROJECTION ); glLoadIdentity(); // Handle interactive zoom by changing FOV (scaling would cause clipping) gluPerspective( 45.0f/*/zoom*/, (GLfloat)width/(GLfloat)height, 1.0f, 1000.0f ); glViewport( 0, 0, width, height ); // Select and set up the modelview matrix glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); // Handle interactive pan, tilt and rotation gluLookAt( cameraPos.x,cameraPos.y,cameraPos.z, cameraView.x,cameraView.y,cameraView.z, cameraUp.x,cameraUp.y,cameraUp.z); -----In the main loop after the renderScene method----- // - Create a simple camera for navigation - // Get mouse coordinates glfwGetMousePos( &mouseX, &mouseY ); // Get middle window mouse coordinates glfwGetWindowSize( &width, &height ); middleX = width / 2; middleY = height / 2; // Get camera rotation glfwSetMousePos(middleX, middleY); cameraAngleX = (middleX - mouseX)*cameraSens; cameraAngleY = (middleY - mouseY)*cameraSens; // Rotate camera cameraRotationAxis = cameraView - cameraPos; cameraRotationAxis = cameraRotationAxis.crossProduct(cameraUp); cameraRotationAxis.normalize(); cameraRotationX.rotate(-cameraAngleX,cameraUp); cameraRotationY.rotate(-cameraAngleY,cameraRotationAxis); cameraRotation = cameraRotationX*cameraRotationY; cameraRotation.transformVector(&cameraView); Is this the correct way to use the gluLookAt method? Thanks in advance!

Share this post


Link to post
Share on other sites

This topic is 2848 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