I want to move forward no matter which direction the eye is facing using a key on the keyboard. I am updating the parameters to gluLookAt() in a function called moveForward() to move forward. the below code causes the camera to start moving to the right after it has moved forward a few times.
forward is in the z direction. In this code if the eye is not facing perpendicular to the x-axis it does not work as I have stated. Any ideas? thanks in advance.
void moveForward()
{
if(eyeX==centerX){
eyeZ-=delta;
centerZ-=delta;
}
else
{
float eyetocenter=sqrt(pow(abs(centerX-eyeX),2)+pow(abs(centerZ-eyeZ),2));
float eyetoorigin = sqrt(pow(eyeX,2)+pow(eyeZ,2));
float origintocenter = sqrt(pow(centerX,2)+pow(centerZ,2));
eyeX+=cos(origintocenter/eyetocenter)*delta;
centerX+=cos(origintocenter/eyetocenter)*delta;
eyeZ-=sin(eyetoorigin/eyetocenter)*delta;
centerZ-=sin(eyetoorigin/eyetocenter)*delta;
}
}