From 829e52d47339c9b69641e7f515b19cd8e0072428 Mon Sep 17 00:00:00 2001 From: asofold Date: Mon, 21 Apr 2014 14:10:43 +0200 Subject: [PATCH] Add methods to check and correct yaw and pitch to LocUtil. --- .../nocheatplus/checks/moving/LocUtil.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/LocUtil.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/LocUtil.java index 0fd6af00..c353168f 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/LocUtil.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/LocUtil.java @@ -99,5 +99,80 @@ public class LocUtil { return world; } } + + /** + * Quick out of bounds check for yaw. + * @param yaw + * @return + */ + public static final boolean needsYawCorrection(final float yaw) { + return yaw == Float.NaN || yaw < 0f || yaw >= 360f; + } + + /** + * Quick out of bounds check for pitch. + * @param pitch + * @return + */ + public static final boolean needsPitchCorrection(final float pitch) { + return pitch == Float.NaN || pitch < -90f || pitch > 90f; + } + + /** + * Quick out of bounds check for yaw and pitch. + * @param yaw + * @param pitch + * @return + */ + public static final boolean needsDirectionCorrection(final float yaw, final float pitch) { + return needsYawCorrection(yaw) || needsPitchCorrection(pitch); + } + + /** + * Ensure 0 <= yaw < 360. + * @param yaw + * @return + */ + public static final float correctYaw(float yaw) { + if (yaw == Float.NaN) { + return 0f; + } + if (yaw >= 360f) { + if (yaw > 10000f) { + yaw = 0f; + } else { + while (yaw > 360f) { + yaw -= 360f; + } + } + } + if (yaw < 0f) { + if (yaw < -10000f) { + yaw = 0f; + } else { + while (yaw < 0f) { + yaw += 360f; + } + } + } + return yaw; + } + + /** + * Ensure -90 <= pitch <= 90. + * @param pitch + * @return + */ + public static final float correctPitch(float pitch) { + if (pitch == Float.NaN) { + return 0f; + } else if (pitch < -90f) { + return -90f; + } else if (pitch > 90f) { + return 90f; + } else { + return pitch; + } + } }