camera movement problems

Started by
2 comments, last by C3rial 16 years, 1 month ago
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:)
CrazyPoly
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

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.
Thanx guys!:) Works like a charm!
CrazyPoly

This topic is closed to new replies.

Advertisement