Skip to content

Commit

Permalink
[libgdx] Physics scale fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Sweet committed Nov 6, 2023
1 parent b40b40f commit 251b368
Showing 1 changed file with 29 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ public void update (Physics physics) {
r = rotateOffset * mix + ca;
c = cos(r);
s = sin(r);
if (scaleX) scaleOffset += (dx * c + dy * s) * i / l;
if (scaleX) scaleOffset += (dx * c + dy * s) * i / l / bone.getWorldScaleX();
} else if (scaleX) {
float r = rotateOffset * mix + atan2(bone.c, bone.a);
float r = atan2(bone.c, bone.a);
c = cos(r);
s = sin(r);
scaleOffset += ((cx - bone.worldX) * c + (cy - bone.worldY) * s) * i / l;
scaleOffset += ((cx - bone.worldX) * c + (cy - bone.worldY) * s) * i / l / bone.getWorldScaleX();
}
}
cx = bone.worldX;
Expand Down Expand Up @@ -202,93 +202,40 @@ public void update (Physics physics) {
if (y) bone.worldY += yOffset * mix;
}

// Smoothing.
if (physics != Physics.none && false) {
float a = (Math.min(remaining / data.step, 1) - 1) * mix;
if (rotateOrShearX) {
float rotateOffset = rotateVelocityLast * a;
float r = rotateOffset * mix, ra = bone.a, sin, cos;
if (data.rotate) {
if (data.shearX) {
r *= 0.5f;
sin = sin(r);
cos = cos(r);
bone.a = cos * ra - sin * bone.c;
bone.c = sin * ra + cos * bone.c;
ra = bone.a;
} else {
sin = sin(r);
cos = cos(r);
}
float rb = bone.b;
bone.b = cos * rb - sin * bone.d;
bone.d = sin * rb + cos * bone.d;
} else {
if (rotateOrShearX) {
float r = rotateOffset * mix, ra = bone.a, sin, cos;
if (data.rotate) {
if (data.shearX) {
r *= 0.5f;
sin = sin(r);
cos = cos(r);
}
bone.a = cos * ra - sin * bone.c;
bone.c = sin * ra + cos * bone.c;
}
if (scaleX) {
}
}

if (false) {
// Local.
if (rotateOrShearX) {
float r = bone.worldToLocalRotation((atan2(bone.c, bone.a) + rotateOffset * mix) * radDeg) - bone.arotation;
if (data.rotate) {
if (data.shearX) {
r *= 0.5f;
bone.ashearX += r;
}
bone.arotation += r;
} else
bone.ashearX += r;
}
if (scaleX) bone.ascaleX *= 1 + scaleOffset * mix;
bone.update(null);
if (physics == Physics.update) {
tx = l * bone.a;
ty = l * bone.c;
}
} else {
if (rotateOrShearX) {
float r = rotateOffset * mix, ra = bone.a, sin, cos;
if (data.rotate) {
if (data.shearX) {
r *= 0.5f;
sin = sin(r);
cos = cos(r);
bone.a = cos * ra - sin * bone.c;
bone.c = sin * ra + cos * bone.c;
ra = bone.a;
} else {
sin = sin(r);
cos = cos(r);
}
float rb = bone.b;
bone.b = cos * rb - sin * bone.d;
bone.d = sin * rb + cos * bone.d;
bone.a = cos * ra - sin * bone.c;
bone.c = sin * ra + cos * bone.c;
ra = bone.a;
} else {
sin = sin(r);
cos = cos(r);
}
bone.a = cos * ra - sin * bone.c;
bone.c = sin * ra + cos * bone.c;
}
if (scaleX) {
float s = 1 + scaleOffset * mix;
bone.a *= s;
bone.c *= s;
float rb = bone.b;
bone.b = cos * rb - sin * bone.d;
bone.d = sin * rb + cos * bone.d;
} else {
sin = sin(r);
cos = cos(r);
}
if (physics == Physics.update) {
tx = l * bone.a;
ty = l * bone.c;
}
bone.updateAppliedTransform();
bone.a = cos * ra - sin * bone.c;
bone.c = sin * ra + cos * bone.c;
}
if (scaleX) {
float s = 1 + scaleOffset * mix;
bone.a *= s;
bone.c *= s;
}
if (physics == Physics.update) {
tx = l * bone.a;
ty = l * bone.c;
}
bone.updateAppliedTransform();
}

/** The bone constrained by this physics constraint. */
Expand Down

0 comments on commit 251b368

Please sign in to comment.