How do I calculate 3D movement based on yaw, pitch and roll?

548 Views Asked by At

I'm creating a 3D game demo and I need to calculate the position of the player in the space (i.e. the player's x, y and z coordinates). I understand that this would be affected based on the camera position when the player moves, so is there a particular equation for calculating the player's position based on certain camera rotations?

Example:

The player moves along the z-axis by 5. This movement would be affected by the yaw and pitch. If yaw and pitch are both equal to zero, the player's position in the z-axis would change by 5. If the yaw or pitch were an actual value, the position would change by a different value. If the yaw were 45 degrees, for example, the position would change by 2.5 (I think that's what should happen). If the yaw were 45 degrees and the pitch were also 45 degrees, the position would change by 1.25. What equation correlates to these value?