mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 17:26:01 +08:00
Fixed single bone IK with flipping and y-up coordinate systems.
This commit is contained in:
parent
ee849c62eb
commit
028769f54f
@ -77,7 +77,9 @@ public class IkConstraint {
|
||||
static public function apply1 (bone:Bone, targetX:Number, targetY:Number, alpha:Number) : void {
|
||||
var parentRotation:Number = (!bone._data.inheritRotation || bone._parent == null) ? 0 : bone._parent._worldRotation;
|
||||
var rotation:Number = bone.rotation;
|
||||
var rotationIK:Number = Math.atan2(targetY - bone._worldY, targetX - bone._worldX) * radDeg - parentRotation;
|
||||
var rotationIK:Number = Math.atan2(targetY - bone._worldY, targetX - bone._worldX) * radDeg;
|
||||
if (bone._worldFlipX != (bone._worldFlipY != Bone.yDown)) rotationIK = -rotationIK;
|
||||
rotationIK -= parentRotation;
|
||||
bone.rotationIK = rotation + (rotationIK - rotation) * alpha;
|
||||
}
|
||||
|
||||
|
||||
@ -69,7 +69,9 @@ void spIkConstraint_apply (spIkConstraint* self) {
|
||||
void spIkConstraint_apply1 (spBone* bone, float targetX, float targetY, float alpha) {
|
||||
float parentRotation = (!bone->data->inheritRotation || !bone->parent) ? 0 : bone->parent->worldRotation;
|
||||
float rotation = bone->rotation;
|
||||
float rotationIK = ATAN2(targetY - bone->worldY, targetX - bone->worldX) * RAD_DEG - parentRotation;
|
||||
float rotationIK = ATAN2(targetY - bone->worldY, targetX - bone->worldX) * RAD_DEG;
|
||||
if (bone->worldFlipX != (bone->worldFlipY != yDown)) rotationIK = -rotationIK;
|
||||
rotationIK -= parentRotation;
|
||||
bone->rotationIK = rotation + (rotationIK - rotation) * alpha;
|
||||
}
|
||||
|
||||
|
||||
@ -82,7 +82,9 @@ namespace Spine {
|
||||
static public void apply (Bone bone, float targetX, float targetY, float alpha) {
|
||||
float parentRotation = (!bone.data.inheritRotation || bone.parent == null) ? 0 : bone.parent.worldRotation;
|
||||
float rotation = bone.rotation;
|
||||
float rotationIK = (float)Math.Atan2(targetY - bone.worldY, targetX - bone.worldX) * radDeg - parentRotation;
|
||||
float rotationIK = (float)Math.Atan2(targetY - bone.worldY, targetX - bone.worldX) * radDeg;
|
||||
if (bone.worldFlipX != (bone.worldFlipY != Bone.yDown)) rotationIK = -rotationIK;
|
||||
rotationIK -= parentRotation;
|
||||
bone.rotationIK = rotation + (rotationIK - rotation) * alpha;
|
||||
}
|
||||
|
||||
|
||||
@ -226,7 +226,9 @@ spine.IkConstraint.prototype = {
|
||||
spine.IkConstraint.apply1 = function (bone, targetX, targetY, alpha) {
|
||||
var parentRotation = (!bone.data.inheritRotation || !bone.parent) ? 0 : bone.parent.worldRotation;
|
||||
var rotation = bone.rotation;
|
||||
var rotationIK = Math.atan2(targetY - bone.worldY, targetX - bone.worldX) * spine.radDeg - parentRotation;
|
||||
var rotationIK = Math.atan2(targetY - bone.worldY, targetX - bone.worldX) * spine.radDeg;
|
||||
if (bone.worldFlipX != (bone.worldFlipY != spine.Bone.yDown)) rotationIK = -rotationIK;
|
||||
rotationIK -= parentRotation;
|
||||
bone.rotationIK = rotation + (rotationIK - rotation) * alpha;
|
||||
};
|
||||
/** Adjusts the parent and child bone rotations so the tip of the child is as close to the target position as possible. The
|
||||
|
||||
@ -72,7 +72,11 @@ function IkConstraint.apply1 (bone, targetX, targetY, alpha)
|
||||
parentRotation = bone.parent.worldRotation
|
||||
end
|
||||
local rotation = bone.rotation
|
||||
local rotationIK = math.atan2(targetY - bone.worldY, targetX - bone.worldX) * radDeg - parentRotation
|
||||
local rotationIK = math.atan2(targetY - bone.worldY, targetX - bone.worldX) * radDeg
|
||||
if bone.worldFlipX ~= bone.worldFlipY then
|
||||
rotationIK = -rotationIK
|
||||
end
|
||||
rotationIK = rotationIK - parentRotation
|
||||
bone.rotationIK = rotation + (rotationIK - rotation) * alpha
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user