mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 17:26:01 +08:00
[c] Port: Scale physics constraint limits with skeleton scale. See #2576
This commit is contained in:
parent
a5e51afb57
commit
83ac01e76c
@ -121,22 +121,25 @@ void spPhysicsConstraint_update(spPhysicsConstraint *self, spPhysics physics) {
|
|||||||
self->ux = bx;
|
self->ux = bx;
|
||||||
self->uy = by;
|
self->uy = by;
|
||||||
} else {
|
} 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 || y) {
|
||||||
if (x) {
|
if (x) {
|
||||||
float u = (self->ux - bx) * i;
|
float u = (self->ux - bx) * i;
|
||||||
self->xOffset += u > q ? q : u < -q ? -q
|
self->xOffset += u > qx ? qx : u < -qx ? -qx
|
||||||
: u;
|
: u;
|
||||||
self->ux = bx;
|
self->ux = bx;
|
||||||
}
|
}
|
||||||
if (y) {
|
if (y) {
|
||||||
float u = (self->uy - by) * i;
|
float u = (self->uy - by) * i;
|
||||||
self->yOffset += u > q ? q : u < -q ? -q
|
self->yOffset += u > qy ? qy : u < -qy ? -qy
|
||||||
: u;
|
: u;
|
||||||
self->uy = by;
|
self->uy = by;
|
||||||
}
|
}
|
||||||
if (a >= t) {
|
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);
|
float m = self->massInverse * t, e = self->strength, w = self->wind * f, g = self->gravity * f * (spBone_isYDown() ? -1 : 1);
|
||||||
do {
|
do {
|
||||||
if (x) {
|
if (x) {
|
||||||
@ -159,14 +162,14 @@ void spPhysicsConstraint_update(spPhysicsConstraint *self, spPhysics physics) {
|
|||||||
if (rotateOrShearX || scaleX) {
|
if (rotateOrShearX || scaleX) {
|
||||||
float ca = ATAN2(bone->c, bone->a), c, s, mr = 0;
|
float ca = ATAN2(bone->c, bone->a), c, s, mr = 0;
|
||||||
float dx = self->cx - bone->worldX, dy = self->cy - bone->worldY;
|
float dx = self->cx - bone->worldX, dy = self->cy - bone->worldY;
|
||||||
if (dx > q)
|
if (dx > qx)
|
||||||
dx = q;
|
dx = qx;
|
||||||
else if (dx < -q)//
|
else if (dx < -qx)//
|
||||||
dx = -q;
|
dx = -qx;
|
||||||
if (dy > q)
|
if (dy > qy)
|
||||||
dy = q;
|
dy = qy;
|
||||||
else if (dy < -q)//
|
else if (dy < -qy)//
|
||||||
dy = -q;
|
dy = -qy;
|
||||||
if (rotateOrShearX) {
|
if (rotateOrShearX) {
|
||||||
mr = (self->data->rotate + self->data->shearX) * mix;
|
mr = (self->data->rotate + self->data->shearX) * mix;
|
||||||
float r = ATAN2(dy + self->ty, dx + self->tx) - ca - self->rotateOffset * mr;
|
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;
|
a = self->remaining;
|
||||||
if (a >= t) {
|
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 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) {
|
while (-1) {
|
||||||
a -= t;
|
a -= t;
|
||||||
if (scaleX) {
|
if (scaleX) {
|
||||||
|
|||||||
@ -760,6 +760,7 @@ void celestialCircus(spSkeletonData *skeletonData, spAtlas *atlas) {
|
|||||||
spSkeleton *skeleton = drawable->skeleton;
|
spSkeleton *skeleton = drawable->skeleton;
|
||||||
skeleton->x = 320;
|
skeleton->x = 320;
|
||||||
skeleton->y = 480;
|
skeleton->y = 480;
|
||||||
|
skeleton->scaleX = skeleton->scaleY = 0.2f;
|
||||||
spSkeleton_updateWorldTransform(skeleton, SP_PHYSICS_UPDATE);
|
spSkeleton_updateWorldTransform(skeleton, SP_PHYSICS_UPDATE);
|
||||||
spAnimationState_setAnimationByName(drawable->state, 0, "swing", true);
|
spAnimationState_setAnimationByName(drawable->state, 0, "swing", true);
|
||||||
|
|
||||||
@ -784,9 +785,9 @@ void celestialCircus(spSkeletonData *skeletonData, spAtlas *atlas) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
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(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(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(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(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);
|
testcase(dragon, "data/dragon-ess.json", "data/dragon-ess.skel", "data/dragon-pma.atlas", 0.6f);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user