Jump to content
  • Advertisement
Sign in to follow this  

camera movement problems

This topic is 3720 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'm having some difficulties with my camera movements. Here's what I'm using in my code: float camPosX = 0; float camPosY = 10; float camPosZ = 1; float camViewX = 0; float camViewY = 10; float camViewZ = 10; float camUpX = 0; float camUpY = 1; float camUpZ = 0; In init(): gluPerspective(45.0, 800/600, 1, 500); In Main_Loop(): (Yes, using GLFW) if(glfwGetKey(GLFW_KEY_UP) == GLFW_PRESS) { camPosX = camPosX + (camViewX - camPosX) * moveSpeed; camPosZ = camPosZ + (camViewZ - camPosZ) * moveSpeed; camViewX = camViewX + (camViewX - camPosX) * moveSpeed; camViewZ = camViewZ + (camViewZ - camPosZ) * moveSpeed; } In Draw(): gluLookAt(camPosX,camPosY,camPosZ, camViewX,camViewY,camViewZ, camUpX,camUpY,camUpZ); Now, my problem is - when I first press the up arrow key, the camera leaps forward, and then it slows down....untill it's come to a complete stop. After that I can't move it at all. (Maybe the camPosZ- and camViewZ-variables has somehow gotten the same value?) Any help is greatly apprechiated:)

Share this post


Link to post
Share on other sites
Advertisement
try this

float diffX = camViewX - camPosX;
float diffZ = camViewZ - camPosZ;
camPosX = camPosX + diffX * moveSpeed;
camPosZ = camPosZ + diffZ * moveSpeed;
camViewX = camViewX + diffX * moveSpeed;
camViewZ = camViewZ + diffZ * moveSpeed;

it should help, i think

Share this post


Link to post
Share on other sites

Quote:
Original post by C3rial

camPosX = camPosX + (camViewX - camPosX) * moveSpeed;
camPosZ = camPosZ + (camViewZ - camPosZ) * moveSpeed;
camViewX = camViewX + (camViewX - camPosX) * moveSpeed;
camViewZ = camViewZ + (camViewZ - camPosZ) * moveSpeed;


The way the new positions are calculated, the camPos will slowly get closer to the viewPos. So, the camera will eventually slow to a stop.

Try something like:

float xMove = (camViewX - camPosX) * moveSpeed;
float zMove = (camViewZ - camPosZ) * moveSpeed;
camPosX = camPosX + xMove;
camPosZ = camPosZ + zMove;
camViewX = camViewX + xMove;
camViewZ = camViewZ + zMove;

that way the amount to move camView will not be calculated differently from the amount to move camPos.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!