Jump to content
  • Advertisement
Sign in to follow this  
rulfen

gluLookAt - Camera rotation

This topic is 3152 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
Advertisement
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!