From 2dff61c925925b4fbeed3ab30430ac97b968e869 Mon Sep 17 00:00:00 2001 From: PolyacovYury Date: Sat, 9 Jun 2018 05:18:01 +0300 Subject: [PATCH] Implemented player strafing calculation from change in model rotation angle (since a strafing model that doesn't turn anywhere would look silly and would be exponentially hard to implement) --- .../render/player/RenderPonyPlayer.java | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java b/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java index 53a4b9b0..1c26a817 100644 --- a/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java +++ b/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java @@ -30,6 +30,13 @@ public class RenderPonyPlayer extends RenderPonyBase { GlStateManager.translate(0, player.isSneaking() ? 0.2F : -1, 0); } + private float sensibleAngle(float angle) { + angle %= 360; // if you need to copy-paste a portion of code more than 2 times - make a function + if (angle > 180) angle -= 360; + if (angle < -180) angle += 360; + return angle; + } + @Override protected void transformPegasusFlight(AbstractClientPlayer player, double motionX, double motionY, double motionZ, float yaw, float pitch, float ticks) { double dist = Math.sqrt(motionX * motionX + motionZ * motionZ); @@ -52,16 +59,21 @@ public class RenderPonyPlayer extends RenderPonyBase { double horMotion = Math.sqrt(motionX * motionX + motionZ * motionZ); if (horMotion > 0) { - - yaw = player.cameraYaw - player.rotationYawHead; - - double roll = (Math.toDegrees(Math.atan2(motionX, motionZ)) - yaw) % 360; - - if (roll < -180) roll += 360; - if (roll > 180) roll -= 360; - - roll *= horMotion * 2; - roll = MathHelper.clamp(roll, -54, 54); + yaw = sensibleAngle(player.cameraYaw - player.rotationYawHead); // will need later + // since model roll should probably be calculated from model rotation rather than entity rotation... + double roll = sensibleAngle(player.prevRenderYawOffset - player.renderYawOffset); + float modelYaw = sensibleAngle(player.renderYawOffset); + // filtering ugly jitter that occurs in Vanilla code if motion changes from sideways to diagonal + if (Math.abs(roll) > 0.5f && Math.abs(sensibleAngle(modelYaw + yaw)) > 40) { + return; + } + // detecting that we're flying backwards and roll must be inverted + if (Math.abs(sensibleAngle((float) Math.toDegrees(Math.atan2(motionX, motionZ)) + modelYaw)) > 90) { + roll *= -1; // because inline ifs are not in favor + } + // ayyy magic numbers (after 5 - an approximation of nice looking coefficients calculated by hand) + roll *= horMotion * 5 * (3.6884f * Math.pow(Math.abs(roll), -0.191)); + roll = MathHelper.clamp(roll, -54, 54); // safety measure, shouldn't be required anymore GlStateManager.rotate((float)roll, 0, 0, 1); }