Skip to content

Commit

Permalink
[c] More 4.2 porting, SkeletonJson, SFML physics examples
Browse files Browse the repository at this point in the history
  • Loading branch information
badlogic committed Apr 16, 2024
1 parent f7f4d5c commit 2d940b4
Show file tree
Hide file tree
Showing 7 changed files with 367 additions and 37 deletions.
2 changes: 1 addition & 1 deletion spine-c/spine-c/include/spine/Animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ typedef struct spInheritTimeline {

SP_API spInheritTimeline *spInheritTimeline_create(int framesCount, int boneIndex);

SP_API void spInheritTimeline_setFrame(spDrawOrderTimeline *self, int frameIndex, float time, spInherit inherit);
SP_API void spInheritTimeline_setFrame(spInheritTimeline *self, int frameIndex, float time, spInherit inherit);


/**/
Expand Down
1 change: 1 addition & 0 deletions spine-c/spine-c/include/spine/SlotData.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef struct spSlotData {
spColor *darkColor;
spBlendMode blendMode;
int/*bool*/ visible;
char *path;
} spSlotData;

SP_API spSlotData *spSlotData_create(const int index, const char *name, spBoneData *boneData);
Expand Down
4 changes: 2 additions & 2 deletions spine-c/spine-c/include/spine/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#define SPINE_VERTEXEFFECT_H_

#define SPINE_MAJOR_VERSION 4
#define SPINE_MINOR_VERSION 1
#define SPINE_VERSION_STRING "4.1"
#define SPINE_MINOR_VERSION 2
#define SPINE_VERSION_STRING "4.2"

#endif
4 changes: 2 additions & 2 deletions spine-c/spine-c/src/spine/Animation.c
Original file line number Diff line number Diff line change
Expand Up @@ -2194,7 +2194,7 @@ spInheritTimeline *spInheritTimeline_create(int framesCount, int boneIndex) {
return self;
}

void spInheritTimeline_setFrame(spDrawOrderTimeline *self, int frame, float time, spInherit inherit) {
void spInheritTimeline_setFrame(spInheritTimeline *self, int frame, float time, spInherit inherit) {
frame *= 2;
self->super.frames->items[frame] = time;
self->super.frames->items[frame + 1] = inherit;
Expand Down Expand Up @@ -2857,6 +2857,6 @@ spPhysicsConstraintResetTimeline *spPhysicsConstraintResetTimeline_create(int fr
return self;
}

void spPhysicsResetTimeline_setFrame(spPhysicsConstraintResetTimeline *self, int frame, float time) {
void spPhysicsConstraintResetTimeline_setFrame(spPhysicsConstraintResetTimeline *self, int frame, float time) {
self->super.frames->items[frame] = time;
}
36 changes: 20 additions & 16 deletions spine-c/spine-c/src/spine/Bone.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ void spBone_updateWorldTransform(spBone *self) {
void spBone_updateWorldTransformWith(spBone *self, float x, float y, float rotation, float scaleX, float scaleY,
float shearX, float shearY) {
float pa, pb, pc, pd;
spBone *parent = self->parent;
float sx = self->skeleton->scaleX;
float sy = self->skeleton->scaleY * (spBone_isYDown() ? -1 : 1);
spBone *parent = self->parent;

self->ax = x;
self->ay = y;
Expand All @@ -82,14 +84,14 @@ void spBone_updateWorldTransformWith(spBone *self, float x, float y, float rotat
self->ashearY = shearY;

if (!parent) { /* Root bone. */
float sx = self->skeleton->scaleX;
float sy = self->skeleton->scaleY;
float rx = (rotation + shearX) * DEG_RAD;
float ry = (rotation + 90 + shearY) * DEG_RAD;
self->a = COS(rx) * scaleX * sx;
self->b = COS(ry) * scaleY * sx;
self->c = SIN(rx) * scaleX * sy;
self->d = SIN(ry) * scaleY * sy;
self->worldX = x * sx + self->skeleton->x;
self->worldY = y * sy + self->skeleton->y;
return;
}

Expand Down Expand Up @@ -129,8 +131,8 @@ void spBone_updateWorldTransformWith(spBone *self, float x, float y, float rotat
float prx;
if (s > 0.0001f) {
s = ABS(pa * pd - pb * pc) / s;
pa /= self->skeleton->scaleX;
pc /= self->skeleton->scaleY;
pa /= sx;
pc /= sy;
pb = pc * s;
pd = pa * s;
prx = ATAN2DEG(pc, pa);
Expand All @@ -156,10 +158,10 @@ void spBone_updateWorldTransformWith(spBone *self, float x, float y, float rotat
rotation *= DEG_RAD;
float cosine = COS(rotation);
float sine = SIN(rotation);
float za = (pa * cosine + pb * sine) / self->skeleton->scaleX;
float zc = (pc * cosine + pd * sine) / self->skeleton->scaleY;
float za = (pa * cosine + pb * sine) / sx;
float zc = (pc * cosine + pd * sine) / sy;
float s = SQRT(za * za + zc * zc);
if (self->data->inherit == SP_INHERIT_NOSCALE && (pa * pd - pb * pc < 0) != (self->skeleton->scaleX < 0 != self->skeleton->scaleY < 0))
if (self->data->inherit == SP_INHERIT_NOSCALE && (pa * pd - pb * pc < 0) != (sx < 0 != sy < 0))
s = -s;
rotation = PI / 2 + ATAN2(zc, za);
float zb = COS(rotation) * s;
Expand All @@ -177,10 +179,10 @@ void spBone_updateWorldTransformWith(spBone *self, float x, float y, float rotat
}
}

self->a *= self->skeleton->scaleX;
self->b *= self->skeleton->scaleX;
self->c *= self->skeleton->scaleY;
self->d *= self->skeleton->scaleY;
self->a *= sx;
self->b *= sx;
self->c *= sy;
self->d *= sy;
}

void spBone_setToSetupPose(spBone *self) {
Expand Down Expand Up @@ -223,6 +225,8 @@ void spBone_updateAppliedTransform(spBone *self) {
float s, sa, sc;
float cosine, sine;

float yDownScale = spBone_isYDown() ? -1 : 1;

spBone *parent = self->parent;
if (!parent) {
self->ax = self->worldX - self->skeleton->x;
Expand Down Expand Up @@ -252,9 +256,9 @@ void spBone_updateAppliedTransform(spBone *self) {
case SP_INHERIT_NOROTATIONORREFLECTION: {
s = ABS(pa * pd - pb * pc) / (pa * pa + pc * pc);
sa = pa / self->skeleton->scaleX;
sc = pc / self->skeleton->scaleY;
sc = pc / self->skeleton->scaleY * yDownScale;
pb = -sc * s * self->skeleton->scaleX;
pd = sa * s * self->skeleton->scaleY;
pd = sa * s * self->skeleton->scaleY * yDownScale;
pid = 1 / (pa * pd - pb * pc);
ia = pd * pid;
ib = pb * pid;
Expand All @@ -265,14 +269,14 @@ void spBone_updateAppliedTransform(spBone *self) {
float r = self->rotation * DEG_RAD;
cosine = COS(r), sine = SIN(r);
pa = (pa * cosine + pb * sine) / self->skeleton->scaleX;
pc = (pc * cosine + pd * sine) / self->skeleton->scaleY;
pc = (pc * cosine + pd * sine) / self->skeleton->scaleY * yDownScale;
s = SQRT(pa * pa + pc * pc);
if (s > 0.00001) s = 1 / s;
pa *= s;
pc *= s;
s = SQRT(pa * pa + pc * pc);
if (self->inherit == SP_INHERIT_NOSCALE &&
pid < 0 != (self->skeleton->scaleX < 0 != self->skeleton->scaleY < 0))
pid < 0 != (self->skeleton->scaleX < 0 != (self->skeleton->scaleY * yDownScale) < 0))
s = -s;
r = PI / 2 + ATAN2(pc, pa);
pb = COS(r) * s;
Expand Down
Loading

0 comments on commit 2d940b4

Please sign in to comment.