From 9be30c44cd5fd8665f2727632e04ad4de80ab6de Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Wed, 17 Oct 2018 14:52:15 +0200 Subject: [PATCH] [libgdx] Fixed tangents at position 0. Calculating the tangent requires more precision than the position. http://esotericsoftware.com/forum/Glitch-with-the-bones-constrained-to-the-path-10969 Repro: http://n4te.com/x/173-path-tangent-precision.spine --- .../esotericsoftware/spine/PathConstraint.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PathConstraint.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PathConstraint.java index 377f034b3..e759d75e3 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PathConstraint.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PathConstraint.java @@ -430,14 +430,23 @@ public class PathConstraint implements Constraint { private void addCurvePosition (float p, float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2, float[] out, int o, boolean tangents) { - if (p < epsilon || Float.isNaN(p)) p = epsilon; + if (p < epsilon || Float.isNaN(p)) { + out[o] = x1; + out[o + 1] = y1; + out[o + 2] = (float)Math.atan2(cy1 - y1, cx1 - x1); + return; + } float tt = p * p, ttt = tt * p, u = 1 - p, uu = u * u, uuu = uu * u; float ut = u * p, ut3 = ut * 3, uut3 = u * ut3, utt3 = ut3 * p; float x = x1 * uuu + cx1 * uut3 + cx2 * utt3 + x2 * ttt, y = y1 * uuu + cy1 * uut3 + cy2 * utt3 + y2 * ttt; out[o] = x; out[o + 1] = y; - if (tangents) - out[o + 2] = (float)Math.atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt)); + if (tangents) { + if (p < 0.001f) + out[o + 2] = (float)Math.atan2(cy1 - y1, cx1 - x1); + else + out[o + 2] = (float)Math.atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt)); + } } public int getOrder () {