mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[cpp] Port: Scale physics constraint limits with skeleton scale. See #2576
This commit is contained in:
parent
92b5b8a1ee
commit
a5e51afb57
@ -334,22 +334,24 @@ void PhysicsConstraint::update(Physics physics) {
|
||||
_ux = bx;
|
||||
_uy = by;
|
||||
} else {
|
||||
float a = _remaining, i = _inertia, q = _data._limit * delta, t = _data._step, f = _skeleton.getData()->getReferenceScale(), d = -1;
|
||||
float a = _remaining, i = _inertia, t = _data._step, f = _skeleton.getData()->getReferenceScale();
|
||||
float qx = _data._limit * delta, qy = qx * MathUtil::abs(_skeleton.getScaleX());
|
||||
qx *= MathUtil::abs(_skeleton.getScaleY());
|
||||
if (x || y) {
|
||||
if (x) {
|
||||
float u = (_ux - bx) * i;
|
||||
_xOffset += u > q ? q : u < -q ? -q
|
||||
_xOffset += u > qx ? qx : u < -qx ? -qx
|
||||
: u;
|
||||
_ux = bx;
|
||||
}
|
||||
if (y) {
|
||||
float u = (_uy - by) * i;
|
||||
_yOffset += u > q ? q : u < -q ? -q
|
||||
_yOffset += u > qy ? qy : u < -qy ? -qy
|
||||
: u;
|
||||
_uy = by;
|
||||
}
|
||||
if (a >= t) {
|
||||
d = MathUtil::pow(_damping, 60 * t);
|
||||
float d = MathUtil::pow(_damping, 60 * t);
|
||||
float m = _massInverse * t, e = _strength, w = _wind * f, g = _gravity * f * (Bone::yDown ? -1 : 1);
|
||||
do {
|
||||
if (x) {
|
||||
@ -372,14 +374,14 @@ void PhysicsConstraint::update(Physics physics) {
|
||||
if (rotateOrShearX || scaleX) {
|
||||
float ca = MathUtil::atan2(bone->_c, bone->_a), c, s, mr = 0;
|
||||
float dx = _cx - bone->_worldX, dy = _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;
|
||||
float r = MathUtil::atan2(dy + _ty, dx + _tx) - ca - _rotateOffset * mr;
|
||||
@ -399,8 +401,8 @@ void PhysicsConstraint::update(Physics physics) {
|
||||
}
|
||||
a = _remaining;
|
||||
if (a >= t) {
|
||||
if (d == -1) d = MathUtil::pow(_damping, 60 * t);
|
||||
float m = _massInverse * t, e = _strength, w = _wind, g = _gravity * (Bone::yDown ? -1 : 1), h = l / f;
|
||||
float d = MathUtil::pow(_damping, 60 * t);
|
||||
while (true) {
|
||||
a -= t;
|
||||
if (scaleX) {
|
||||
|
||||
@ -626,6 +626,8 @@ void celestialCircus(SkeletonData *skeletonData, Atlas *atlas) {
|
||||
|
||||
Skeleton *skeleton = drawable.skeleton;
|
||||
skeleton->setPosition(320, 480);
|
||||
skeleton->setScaleX(0.2);
|
||||
skeleton->setScaleY(0.2);
|
||||
skeleton->updateWorldTransform(Physics_Update);
|
||||
|
||||
drawable.state->setAnimation(0, "swing", true);
|
||||
@ -778,10 +780,10 @@ extern spine::SkeletonRenderer *skeletonRenderer;
|
||||
int main() {
|
||||
SpineExtension::setInstance(&dbgExtension);
|
||||
|
||||
testcase(celestialCircus, "data/celestial-circus-pro.json", "data/celestial-circus-pro.skel", "data/celestial-circus-pma.atlas", 1);
|
||||
testcase(mixAndMatch, "data/mix-and-match-pro.json", "data/mix-and-match-pro.skel", "data/mix-and-match-pma.atlas", 0.5f);
|
||||
testcase(cloudpot, "data/cloud-pot.json", "data/cloud-pot.skel", "data/cloud-pot-pma.atlas", 0.2);
|
||||
testcase(sack, "data/sack-pro.json", "data/sack-pro.skel", "data/sack-pma.atlas", 0.2f);
|
||||
testcase(celestialCircus, "data/celestial-circus-pro.json", "data/celestial-circus-pro.skel", "data/celestial-circus-pma.atlas", 0.2f);
|
||||
testcase(snowglobe, "data/snowglobe-pro.json", "data/snowglobe-pro.skel", "data/snowglobe-pma.atlas", 0.2f);
|
||||
testcase(dragon, "data/dragon-ess.json", "data/dragon-ess.skel", "data/dragon-pma.atlas", 0.6f);
|
||||
testcase(spineboy, "data/spineboy-pro.json", "data/spineboy-pro.skel", "data/spineboy-pma.atlas", 0.62f);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user