public static Vector3 VectorAngles(Vector3 forward) { float yaw; float pitch; if (forward.X == 0 && forward.Y == 0) { yaw = 0; pitch = forward.Z > 0.0f ? 270.0f : 90.0f; } else { yaw = MathF.RadiansToDegrees((float)Math.Atan2(forward.Y, forward.X)); if (yaw < 0) { yaw += 360.0f; } pitch = MathF.RadiansToDegrees((float)Math.Atan2(-forward.Z, Math.Sqrt(forward.X * forward.X + forward.Y * forward.Y))); if (pitch < 0) { pitch += 360; } } return(new Vector3(pitch, yaw, 0)); }
public static Vector3 CalcAngle(Vector3 source, Vector3 dest) { var ret = new Vector3(); var delta = source - dest; float hyp = (float)Math.Sqrt(delta.X * delta.X + delta.Y * delta.Y); ret.X = MathF.RadiansToDegrees((float)Math.Atan(delta.Z / hyp)); ret.Y = MathF.RadiansToDegrees((float)Math.Atan(delta.Y / delta.X)); if (delta.X >= 0.0f) { ret.Y += 180.0f; } return(ret); }