I’ve managed to get hold of a bit of code that calculates a camera position when the forward or backwards cursor key is pressed:
if (keys[VK_UP])
{
// Move On The X-Plane Based On Player Direction
xpos -= (float)sin(heading * piover180) * 0.05f;
// Move On The Z-Plane Based On Player Direction
zpos -= (float)cos(heading * piover180) * 0.05f;
}
if (keys[VK_DOWN])
{
// Move On The X-Plane Based On Player Direction
xpos += (float)sin(heading * piover180) * 0.05f;
// Move On The Z-Plane Based On Player Direction
zpos += (float)cos(heading * piover180) * 0.05f;
}
“A new location for the camera is calculated using the sine and cosine calculations (some trigonometry required :-). Piover180 is simply a conversion factor for converting between degrees and radians.”
Does anyone know how I would modify this code to allow movement on the Y-Plane? (i.e. so you can head up or down) I have already written the rotation code but I don’t understand the trigonometry for this part.
Thanks in advance