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); }