[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
This commit is contained in:
NathanSweet 2018-10-17 14:52:15 +02:00
parent d0d22bb344
commit 9be30c44cd

View File

@ -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, 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) { 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 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 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; float x = x1 * uuu + cx1 * uut3 + cx2 * utt3 + x2 * ttt, y = y1 * uuu + cy1 * uut3 + cy2 * utt3 + y2 * ttt;
out[o] = x; out[o] = x;
out[o + 1] = y; out[o + 1] = y;
if (tangents) 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 (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 () { public int getOrder () {