[c] Port: Scale physics constraint limits with skeleton scale. See #2576

This commit is contained in:
Mario Zechner 2024-07-24 14:36:41 +02:00
parent a5e51afb57
commit 83ac01e76c
2 changed files with 18 additions and 14 deletions

View File

@ -121,22 +121,25 @@ void spPhysicsConstraint_update(spPhysicsConstraint *self, spPhysics physics) {
self->ux = bx;
self->uy = by;
} else {
float a = self->remaining, i = self->inertia, q = self->data->limit * delta, t = self->data->step, f = self->skeleton->data->referenceScale, d = -1;
// float a = self->remaining, i = self->inertia, q = self->data->limit * delta, t = self->data->step, f = self->skeleton->data->referenceScale, d = -1;
float a = self->remaining, i = self->inertia, t = self->data->step, f = self->skeleton->data->referenceScale;
float qx = self->data->limit * delta, qy = qx * ABS(self->skeleton->scaleX);
qx *= ABS(self->skeleton->scaleY);
if (x || y) {
if (x) {
float u = (self->ux - bx) * i;
self->xOffset += u > q ? q : u < -q ? -q
self->xOffset += u > qx ? qx : u < -qx ? -qx
: u;
self->ux = bx;
}
if (y) {
float u = (self->uy - by) * i;
self->yOffset += u > q ? q : u < -q ? -q
self->yOffset += u > qy ? qy : u < -qy ? -qy
: u;
self->uy = by;
}
if (a >= t) {
d = POW(self->damping, 60 * t);
float d = POW(self->damping, 60 * t);
float m = self->massInverse * t, e = self->strength, w = self->wind * f, g = self->gravity * f * (spBone_isYDown() ? -1 : 1);
do {
if (x) {
@ -159,14 +162,14 @@ void spPhysicsConstraint_update(spPhysicsConstraint *self, spPhysics physics) {
if (rotateOrShearX || scaleX) {
float ca = ATAN2(bone->c, bone->a), c, s, mr = 0;
float dx = self->cx - bone->worldX, dy = self->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 = (self->data->rotate + self->data->shearX) * mix;
float r = ATAN2(dy + self->ty, dx + self->tx) - ca - self->rotateOffset * mr;
@ -186,8 +189,8 @@ void spPhysicsConstraint_update(spPhysicsConstraint *self, spPhysics physics) {
}
a = self->remaining;
if (a >= t) {
if (d == -1) d = POW(self->damping, 60 * t);
float m = self->massInverse * t, e = self->strength, w = self->wind, g = self->gravity, h = l / f;
float d = POW(self->damping, 60 * t);
while (-1) {
a -= t;
if (scaleX) {

View File

@ -760,6 +760,7 @@ void celestialCircus(spSkeletonData *skeletonData, spAtlas *atlas) {
spSkeleton *skeleton = drawable->skeleton;
skeleton->x = 320;
skeleton->y = 480;
skeleton->scaleX = skeleton->scaleY = 0.2f;
spSkeleton_updateWorldTransform(skeleton, SP_PHYSICS_UPDATE);
spAnimationState_setAnimationByName(drawable->state, 0, "swing", true);
@ -784,9 +785,9 @@ void celestialCircus(spSkeletonData *skeletonData, spAtlas *atlas) {
}
int main() {
testcase(celestialCircus, "data/celestial-circus-pro.json", "data/celestial-circus-pro.skel", "data/celestial-circus-pma.atlas", 1);
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(raptor, "data/raptor-pro.json", "data/raptor-pro.skel", "data/raptor-pma.atlas", 0.5f);
testcase(dragon, "data/dragon-ess.json", "data/dragon-ess.skel", "data/dragon-pma.atlas", 0.6f);