Skip to content

Commit

Permalink
[haxe] Port: Scale physics constraint limits with skeleton scale. See #…
Browse files Browse the repository at this point in the history
  • Loading branch information
davidetan committed Jul 12, 2024
1 parent cbed5fb commit d08f346
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions spine-haxe/spine-haxe/spine/PhysicsConstraint.hx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ package spine;
class PhysicsConstraint implements Updatable {
private var _data:PhysicsConstraintData;
private var _bone:Bone = null;

public var inertia:Float = 0;
public var strength:Float = 0;
public var damping:Float = 0;
Expand Down Expand Up @@ -63,7 +63,7 @@ class PhysicsConstraint implements Updatable {
private var _skeleton:Skeleton;
public var remaining:Float = 0;
public var lastTime:Float = 0;

public function new(data: PhysicsConstraintData, skeleton: Skeleton) {
_data = data;
_skeleton = skeleton;
Expand Down Expand Up @@ -123,7 +123,7 @@ class PhysicsConstraint implements Updatable {
return;
case Physics.reset, Physics.update:
if (physics == Physics.reset) reset();

var delta:Float = Math.max(skeleton.time - lastTime, 0);
remaining += delta;
lastTime = _skeleton.time;
Expand All @@ -136,19 +136,22 @@ class PhysicsConstraint implements Updatable {
} else {
var a:Float = remaining,
i:Float = inertia,
q:Float = _data.limit * delta,
t:Float = _data.step,
f:Float = skeleton.data.referenceScale,
d:Float = -1;

var qx:Float = _data.limit * delta,
qy:Float = qx * skeleton.scaleY;
qx *= skeleton.scaleX;
if (x || y) {
if (x) {
var u:Float = (ux - bx) * i;
xOffset += u > q ? q : u < -q ? -q : u;
xOffset += u > qx ? qx : u < -qx ? -qx : u;
ux = bx;
}
if (y) {
var u:Float = (uy - by) * i;
yOffset += u > q ? q : u < -q ? -q : u;
yOffset += u > qy ? qy : u < -qy ? -qy : u;
uy = by;
}
if (a >= t) {
Expand Down Expand Up @@ -181,14 +184,14 @@ class PhysicsConstraint implements Updatable {
mr:Float = 0;
var dx:Float = cx - bone.worldX,
dy:Float = cy - bone.worldY;
if (dx > q)
dx = q;
else if (dx < -q) //
dx = -q;
if (dy > q)
dy = q;
else if (dy < -q) //
dy = -q;
if (dx > qx)
dx = qx;
else if (dx < -qx) //
dx = -qx;
if (dy > qy)
dy = qy;
else if (dy < -qy) //
dy = -qy;
if (rotateOrShearX) {
mr = (_data.rotate + _data.shearX) * mix;
var r:Float = Math.atan2(dy + ty, dx + tx) - ca - rotateOffset * mr;
Expand Down

0 comments on commit d08f346

Please sign in to comment.