This calculation can take a pitch and yaw value and convert it into a directional 3D vector.
theagentd simplification(recommended)
// pitch and yaw are in degrees
Vector3D getDirectionVector() {
double pitchRadians = Math.toRadians(pitch);
double yawRadians = Math.toRadians(yaw);
double sinPitch = Math.sin(pitchRadians);
double cosPitch = Math.cos(pitchRadians);
double sinYaw = Math.sin(yawRadians);
double cosYaw = Math.cos(yawRadians);
return new Vector3D(-cosPitch * sinYaw, sinPitch, -cosPitch * cosYaw);
}
In this circumstance, pitch and yaw are easier to keep in degrees, personally. But for improved performance, by all means, translate this to go to radians(just put pitch or yaw instead of (pitch or yaw) * PI / 180)