From 355f5571537b490b338639e4ce70c2f494173f82 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Mon, 15 Sep 2025 14:55:28 +0200 Subject: [PATCH] [cpp] Port of commit 48355c2, abb4362: PhysicsConstraint fixes. --- spine-cpp/src/spine/PhysicsConstraint.cpp | 13 ++++++------- spine-glfw/example/physics.cpp | 1 + 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spine-cpp/src/spine/PhysicsConstraint.cpp b/spine-cpp/src/spine/PhysicsConstraint.cpp index a8fa26afa..18642f69c 100644 --- a/spine-cpp/src/spine/PhysicsConstraint.cpp +++ b/spine-cpp/src/spine/PhysicsConstraint.cpp @@ -112,7 +112,7 @@ void PhysicsConstraint::update(Skeleton &skeleton, Physics physics) { _ux = bx; _uy = by; } else { - float a = _remaining, i = p._inertia, f = skeleton._data.getReferenceScale(), d = -1, m = 0, e = 0, ax = 0, ay = 0, + float a = _remaining, i = p._inertia, f = skeleton._data.getReferenceScale(), d = -1, m = 0, e = 0, qx = _data._limit * delta, qy = qx * MathUtil::abs(skeleton.getScaleY()); qx *= MathUtil::abs(skeleton._scaleX); if (x || y) { @@ -132,8 +132,8 @@ void PhysicsConstraint::update(Skeleton &skeleton, Physics physics) { m = t * p._massInverse; e = p._strength; float w = f * p._wind, g = f * p._gravity; - ax = (w * skeleton._windX + g * skeleton._gravityX) * skeleton._scaleX; - ay = (w * skeleton._windY + g * skeleton._gravityY) * skeleton.getScaleY(); + float ax = (w * skeleton._windX + g * skeleton._gravityX) * skeleton._scaleX; + float ay = (w * skeleton._windY + g * skeleton._gravityY) * skeleton.getScaleY(); do { if (x) { _xVelocity += (ax - _xOffset * e) * m; @@ -188,10 +188,9 @@ void PhysicsConstraint::update(Skeleton &skeleton, Physics physics) { d = MathUtil::pow(p._damping, 60 * t); m = t * p._massInverse; e = p._strength; - float w = f * p._wind, g = f * p._gravity; - ax = (w * skeleton._windX + g * skeleton._gravityX) * skeleton._scaleX; - ay = (w * skeleton._windY + g * skeleton._gravityY) * skeleton.getScaleY(); } + float ax = p._wind * skeleton._windX + p._gravity * skeleton._gravityX; + float ay = p._wind * skeleton._windY + p._gravity * skeleton._gravityY; float rs = _rotateOffset, ss = _scaleOffset, h = l / f; while (true) { a -= t; @@ -290,4 +289,4 @@ BonePose &PhysicsConstraint::getBone() { void PhysicsConstraint::setBone(BonePose &bone) { _bone = &bone; -} \ No newline at end of file +} diff --git a/spine-glfw/example/physics.cpp b/spine-glfw/example/physics.cpp index 78c57fd81..dcaf0418f 100644 --- a/spine-glfw/example/physics.cpp +++ b/spine-glfw/example/physics.cpp @@ -125,6 +125,7 @@ int main() { // Set the "eyeblink-long" animation like in the web example animationState.setAnimation(0, "eyeblink-long", true); + animationState.setAnimation(1, "wind-idle", true); // Create the renderer and set the viewport size to match the window size. This sets up a // pixel perfect orthogonal projection for 2D rendering.