mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[libgdx] Fixed one bone IK with disable inherit rotation/scale/reflection.
This commit is contained in:
parent
8c8b08f80b
commit
203a648ae9
@ -177,10 +177,28 @@ public class IkConstraint implements Updatable {
|
|||||||
if (bone == null) throw new IllegalArgumentException("bone cannot be null.");
|
if (bone == null) throw new IllegalArgumentException("bone cannot be null.");
|
||||||
if (!bone.appliedValid) bone.updateAppliedTransform();
|
if (!bone.appliedValid) bone.updateAppliedTransform();
|
||||||
Bone p = bone.parent;
|
Bone p = bone.parent;
|
||||||
float id = 1 / (p.a * p.d - p.b * p.c);
|
float pa = p.a, pb = p.b, pc = p.c, pd = p.d;
|
||||||
float x = targetX - p.worldX, y = targetY - p.worldY;
|
float rotationIK = -bone.ashearX - bone.arotation, tx, ty;
|
||||||
float tx = (x * p.d - y * p.b) * id - bone.ax, ty = (y * p.a - x * p.c) * id - bone.ay;
|
switch (bone.data.transformMode) {
|
||||||
float rotationIK = atan2(ty, tx) * radDeg - bone.ashearX - bone.arotation;
|
case onlyTranslation:
|
||||||
|
tx = targetX - bone.worldX;
|
||||||
|
ty = targetY - bone.worldY;
|
||||||
|
break;
|
||||||
|
case noRotationOrReflection:
|
||||||
|
rotationIK += atan2(pc, pa) * radDeg;
|
||||||
|
float ps = pa * pa + pc * pc;
|
||||||
|
if (ps > 0.0001f) {
|
||||||
|
ps = Math.abs(pa * pd - pb * pc) / ps;
|
||||||
|
pb = -pc * ps;
|
||||||
|
pd = pa * ps;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
float x = targetX - p.worldX, y = targetY - p.worldY;
|
||||||
|
float d = pa * pd - pb * pc;
|
||||||
|
tx = (x * pd - y * pb) / d - bone.ax;
|
||||||
|
ty = (y * pa - x * pc) / d - bone.ay;
|
||||||
|
}
|
||||||
|
rotationIK += atan2(ty, tx) * radDeg;
|
||||||
if (bone.ascaleX < 0) rotationIK += 180;
|
if (bone.ascaleX < 0) rotationIK += 180;
|
||||||
if (rotationIK > 180)
|
if (rotationIK > 180)
|
||||||
rotationIK -= 360;
|
rotationIK -= 360;
|
||||||
@ -188,6 +206,12 @@ public class IkConstraint implements Updatable {
|
|||||||
rotationIK += 360;
|
rotationIK += 360;
|
||||||
float sx = bone.ascaleX, sy = bone.ascaleY;
|
float sx = bone.ascaleX, sy = bone.ascaleY;
|
||||||
if (compress || stretch) {
|
if (compress || stretch) {
|
||||||
|
switch (bone.data.transformMode) {
|
||||||
|
case noScale:
|
||||||
|
case noScaleOrReflection:
|
||||||
|
tx = targetX - bone.worldX;
|
||||||
|
ty = targetY - bone.worldY;
|
||||||
|
}
|
||||||
float b = bone.data.length * sx, dd = (float)Math.sqrt(tx * tx + ty * ty);
|
float b = bone.data.length * sx, dd = (float)Math.sqrt(tx * tx + ty * ty);
|
||||||
if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001f) {
|
if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001f) {
|
||||||
float s = (dd / b - 1) * alpha + 1;
|
float s = (dd / b - 1) * alpha + 1;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user