From b5ddd17131b355cc69b05cd191b568f1953b3695 Mon Sep 17 00:00:00 2001 From: Brady Date: Tue, 7 Aug 2018 19:36:51 -0500 Subject: [PATCH] Clean up angle calculation --- src/main/java/baritone/bot/utils/Utils.java | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/bot/utils/Utils.java b/src/main/java/baritone/bot/utils/Utils.java index 20452532..4f697e24 100755 --- a/src/main/java/baritone/bot/utils/Utils.java +++ b/src/main/java/baritone/bot/utils/Utils.java @@ -25,11 +25,14 @@ public final class Utils { * @return Rotation {@link Rotation} */ public static Rotation calcRotationFromVec3d(Vec3d orig, Vec3d dest) { - double yaw = Math.atan2(orig.x - dest.x, -orig.z + dest.z); - double dist = Math.sqrt((orig.x - dest.x) * (orig.x - dest.x) + (-orig.z + dest.z) * (-orig.z + dest.z)); - double pitch = Math.atan2(orig.y - dest.y, dist); - return new Rotation((float) (yaw * 180 / Math.PI), - (float) (pitch * 180 / Math.PI)); + double[] delta = { orig.x - dest.x, orig.y - dest.y, orig.z - dest.z }; + double yaw = Math.atan2(delta[0], -delta[2]); + double dist = Math.sqrt(delta[0] * delta[0] + delta[2] * delta[2]); + double pitch = Math.atan2(delta[1], dist); + return new Rotation( + (float) radToDeg(yaw), + (float) radToDeg(pitch) + ); } /** @@ -71,4 +74,12 @@ public final class Utils { double zdiff = z - (pos.getZ() + 0.5D); return Math.sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff); } + + public static double degToRad(double deg) { + return deg * Math.PI / 180.0; + } + + public static double radToDeg(double rad) { + return rad * 180.0 / Math.PI; + } }