🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Strafing left and right

Started by
0 comments, last by Hector 24 years, 7 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;
}

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

This topic is closed to new replies.

Advertisement