Advertisement

Strafing left and right

Started by November 08, 1999 06:59 AM
0 comments, last by Hector 24 years, 10 months ago
What is the formula to strafe left or right?
In the following code fragment, FORWARD and BACKWARD work perfectly but LEFT and RIGHT only work properly when the angle is 0, PI/2, PI, 3PI/2 or 2PI. Another thing I noticed is that when the angle is PI/4, 3PI/4, 5PI/4 or 7PI/4 and I hold down FORWARD and LEFT or BACK and RIGHT the camera strafes left and right properly. I am useing a fixed cordinate system with the camera moving parallel to the x and z plane.

switch (key)
{
< >case FORWARD:
< >cameraz -= cos(angle);
< >camerax += sin(angle);
< >glutPostRedisplay();
< >break;
< >case BACK:
< >cameraz += cos(angle);
< >camerax -= sin(angle);
< >glutPostRedisplay();
< >break;
< >case LEFT:
< >cameraz += sin(angle);
< >camerax -= cos(angle);
< >glutPostRedisplay();
< >break;
< >case RIGHT:
< >cameraz -= sin(angle);
< >camerax += cos(angle);
< >glutPostRedisplay();
< >break;
< >default:
< >break;
}

What happens when it is not working properly?
In which direction does it go?

This topic is closed to new replies.

Advertisement