From a9abab820ee589676bf86c8b14f96856bf9e3df5 Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 11 Jun 2018 19:50:58 +0200 Subject: [PATCH] Don't try to strafe at angles of NaN --- .../model/anim/BasicEasingInterpolator.java | 5 +++++ .../java/com/minelittlepony/pony/data/PonyData.java | 4 ++-- .../render/player/RenderPonyPlayer.java | 12 ++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/minelittlepony/model/anim/BasicEasingInterpolator.java b/src/main/java/com/minelittlepony/model/anim/BasicEasingInterpolator.java index 2c23e362..9354e201 100644 --- a/src/main/java/com/minelittlepony/model/anim/BasicEasingInterpolator.java +++ b/src/main/java/com/minelittlepony/model/anim/BasicEasingInterpolator.java @@ -21,6 +21,11 @@ public class BasicEasingInterpolator implements IInterpolator { from += (to - from) / scalingFactor; + if (Float.isNaN(from) || Float.isInfinite(from)) { + System.err.println("Error: Animation frame for " + key + " is NaN or Infinite."); + from = to; + } + properties.put(key, from); return from; diff --git a/src/main/java/com/minelittlepony/pony/data/PonyData.java b/src/main/java/com/minelittlepony/pony/data/PonyData.java index 1dfd3d74..eb11e93c 100644 --- a/src/main/java/com/minelittlepony/pony/data/PonyData.java +++ b/src/main/java/com/minelittlepony/pony/data/PonyData.java @@ -47,7 +47,7 @@ public class PonyData implements IPonyData { @Override public PonyRace getRace() { - return race.isHuman() ? race : PonyRace.PEGASUS; + return race; } @Override @@ -77,7 +77,7 @@ public class PonyData implements IPonyData { @Override public boolean isWearing(PonyWearable wearable) { - return true;//wearables[wearable.ordinal()]; + return wearables[wearable.ordinal()]; } @Override diff --git a/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java b/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java index 5feb01b9..4e973f13 100644 --- a/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java +++ b/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java @@ -43,7 +43,13 @@ public class RenderPonyPlayer extends RenderPonyBase { } // 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 might be zero, in which case Math.pow produces +Infinity. Anything x Infinity = NaN. + double pow = roll != 0 ? Math.pow(Math.abs(roll), -0.191) : 0; + + roll *= horMotion * 5 * (3.6884f * pow); + + assert !Float.isNaN((float)roll); return MathHelper.clamp(roll, -54, 54); } @@ -67,7 +73,9 @@ public class RenderPonyPlayer extends RenderPonyBase { GlStateManager.rotate(ponyModel.motionPitch, 1, 0, 0); - float roll = getPony().getMetadata().getInterpolator().interpolate("pegasusRoll", (float)calculateRoll(player, motionX, motionY, motionZ), 10); + float roll = (float)calculateRoll(player, motionX, motionY, motionZ); + + roll = getPony().getMetadata().getInterpolator().interpolate("pegasusRoll", roll, 10); GlStateManager.rotate((float)roll, 0, 0, 1);