mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-19 00:06:42 +08:00
[c] Ported stretchy IK, fixed warnings.
This commit is contained in:
parent
b4d71f68c2
commit
a506047242
@ -432,7 +432,7 @@ typedef spDeformTimeline DeformTimeline;
|
||||
|
||||
/**/
|
||||
|
||||
static const int IKCONSTRAINT_ENTRIES = 3;
|
||||
static const int IKCONSTRAINT_ENTRIES = 4;
|
||||
|
||||
typedef struct spIkConstraintTimeline {
|
||||
spCurveTimeline super;
|
||||
@ -452,7 +452,7 @@ typedef struct spIkConstraintTimeline {
|
||||
|
||||
SP_API spIkConstraintTimeline* spIkConstraintTimeline_create (int framesCount);
|
||||
|
||||
SP_API void spIkConstraintTimeline_setFrame (spIkConstraintTimeline* self, int frameIndex, float time, float mix, int bendDirection);
|
||||
SP_API void spIkConstraintTimeline_setFrame (spIkConstraintTimeline* self, int frameIndex, float time, float mix, int bendDirection, int /**boolean**/ stretch);
|
||||
|
||||
#ifdef SPINE_SHORT_NAMES
|
||||
typedef spIkConstraintTimeline IkConstraintTimeline;
|
||||
|
||||
@ -49,6 +49,7 @@ typedef struct spIkConstraint {
|
||||
|
||||
spBone* target;
|
||||
int bendDirection;
|
||||
int /*boolean*/ stretch;
|
||||
float mix;
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -58,6 +59,7 @@ typedef struct spIkConstraint {
|
||||
bones(0),
|
||||
target(0),
|
||||
bendDirection(0),
|
||||
stretch(0),
|
||||
mix(0) {
|
||||
}
|
||||
#endif
|
||||
@ -68,8 +70,8 @@ SP_API void spIkConstraint_dispose (spIkConstraint* self);
|
||||
|
||||
SP_API void spIkConstraint_apply (spIkConstraint* self);
|
||||
|
||||
SP_API void spIkConstraint_apply1 (spBone* bone, float targetX, float targetY, float alpha);
|
||||
SP_API void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float targetY, int bendDirection, float alpha);
|
||||
SP_API void spIkConstraint_apply1 (spBone* bone, float targetX, float targetY, int /*boolean*/ stretch, float alpha);
|
||||
SP_API void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float targetY, int bendDirection, int /*boolean*/ stretch, float alpha);
|
||||
|
||||
#ifdef SPINE_SHORT_NAMES
|
||||
typedef spIkConstraint IkConstraint;
|
||||
|
||||
@ -46,6 +46,7 @@ typedef struct spIkConstraintData {
|
||||
|
||||
spBoneData* target;
|
||||
int bendDirection;
|
||||
int /*boolean*/ stretch;
|
||||
float mix;
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -55,6 +56,7 @@ typedef struct spIkConstraintData {
|
||||
bones(0),
|
||||
target(0),
|
||||
bendDirection(0),
|
||||
stretch(0),
|
||||
mix(0) {
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -63,7 +63,7 @@
|
||||
|
||||
#include <spine/dll.h>
|
||||
|
||||
// Required for sprintf and consorts on MSVC
|
||||
/* Required for sprintf and consorts on MSVC */
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4996)
|
||||
#endif
|
||||
|
||||
@ -243,7 +243,6 @@ void _spRotateTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton,
|
||||
spBone *bone;
|
||||
int frame;
|
||||
float prevRotation, frameTime, percent, r;
|
||||
|
||||
spRotateTimeline* self = SUB_CAST(spRotateTimeline, timeline);
|
||||
|
||||
bone = skeleton->bones[self->boneIndex];
|
||||
@ -301,6 +300,7 @@ void _spRotateTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton,
|
||||
UNUSED(lastTime);
|
||||
UNUSED(firedEvents);
|
||||
UNUSED(eventsCount);
|
||||
UNUSED(direction);
|
||||
}
|
||||
|
||||
int _spRotateTimeline_getPropertyId (const spTimeline* timeline) {
|
||||
@ -385,6 +385,7 @@ void _spTranslateTimeline_apply (const spTimeline* timeline, spSkeleton* skeleto
|
||||
UNUSED(lastTime);
|
||||
UNUSED(firedEvents);
|
||||
UNUSED(eventsCount);
|
||||
UNUSED(direction);
|
||||
}
|
||||
|
||||
int _spTranslateTimeline_getPropertyId (const spTimeline* self) {
|
||||
@ -584,6 +585,7 @@ void _spShearTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, f
|
||||
UNUSED(lastTime);
|
||||
UNUSED(firedEvents);
|
||||
UNUSED(eventsCount);
|
||||
UNUSED(direction);
|
||||
}
|
||||
|
||||
int _spShearTimeline_getPropertyId (const spTimeline* timeline) {
|
||||
@ -667,6 +669,7 @@ void _spColorTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, f
|
||||
UNUSED(lastTime);
|
||||
UNUSED(firedEvents);
|
||||
UNUSED(eventsCount);
|
||||
UNUSED(direction);
|
||||
}
|
||||
|
||||
int _spColorTimeline_getPropertyId (const spTimeline* timeline) {
|
||||
@ -776,6 +779,7 @@ void _spTwoColorTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton
|
||||
UNUSED(lastTime);
|
||||
UNUSED(firedEvents);
|
||||
UNUSED(eventsCount);
|
||||
UNUSED(direction);
|
||||
}
|
||||
|
||||
int _spTwoColorTimeline_getPropertyId (const spTimeline* timeline) {
|
||||
@ -1083,6 +1087,7 @@ void _spDeformTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton,
|
||||
UNUSED(lastTime);
|
||||
UNUSED(firedEvents);
|
||||
UNUSED(eventsCount);
|
||||
UNUSED(direction);
|
||||
}
|
||||
|
||||
int _spDeformTimeline_getPropertyId (const spTimeline* timeline) {
|
||||
@ -1156,10 +1161,12 @@ void _spEventTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, f
|
||||
firedEvents[*eventsCount] = self->events[frame];
|
||||
(*eventsCount)++;
|
||||
}
|
||||
UNUSED(direction);
|
||||
}
|
||||
|
||||
int _spEventTimeline_getPropertyId (const spTimeline* timeline) {
|
||||
return SP_TIMELINE_EVENT << 24;
|
||||
UNUSED(timeline);
|
||||
}
|
||||
|
||||
void _spEventTimeline_dispose (spTimeline* timeline) {
|
||||
@ -1233,6 +1240,7 @@ void _spDrawOrderTimeline_apply (const spTimeline* timeline, spSkeleton* skeleto
|
||||
|
||||
int _spDrawOrderTimeline_getPropertyId (const spTimeline* timeline) {
|
||||
return SP_TIMELINE_DRAWORDER << 24;
|
||||
UNUSED(timeline);
|
||||
}
|
||||
|
||||
void _spDrawOrderTimeline_dispose (spTimeline* timeline) {
|
||||
@ -1274,8 +1282,8 @@ void spDrawOrderTimeline_setFrame (spDrawOrderTimeline* self, int frameIndex, fl
|
||||
|
||||
/**/
|
||||
|
||||
static const int IKCONSTRAINT_PREV_TIME = -3, IKCONSTRAINT_PREV_MIX = -2, IKCONSTRAINT_PREV_BEND_DIRECTION = -1;
|
||||
static const int IKCONSTRAINT_MIX = 1, IKCONSTRAINT_BEND_DIRECTION = 2;
|
||||
static const int IKCONSTRAINT_PREV_TIME = -4, IKCONSTRAINT_PREV_MIX = -3, IKCONSTRAINT_PREV_BEND_DIRECTION = -2, IKCONSTRAINT_PREV_STRETCH = -1;
|
||||
static const int IKCONSTRAINT_MIX = 1, IKCONSTRAINT_BEND_DIRECTION = 2, IKCONSTRAINT_STRETCH = 3;
|
||||
|
||||
void _spIkConstraintTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time,
|
||||
spEvent** firedEvents, int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction) {
|
||||
@ -1293,10 +1301,12 @@ void _spIkConstraintTimeline_apply (const spTimeline* timeline, spSkeleton* skel
|
||||
case SP_MIX_BLEND_SETUP:
|
||||
constraint->mix = constraint->data->mix;
|
||||
constraint->bendDirection = constraint->data->bendDirection;
|
||||
constraint->stretch = constraint->data->stretch;
|
||||
return;
|
||||
case SP_MIX_BLEND_FIRST:
|
||||
constraint->mix += (constraint->data->mix - constraint->mix) * alpha;
|
||||
constraint->bendDirection = constraint->data->bendDirection;
|
||||
constraint->stretch = constraint->data->stretch;
|
||||
case SP_MIX_BLEND_REPLACE:
|
||||
case SP_MIX_BLEND_ADD:
|
||||
; /* to appease compiler */
|
||||
@ -1309,11 +1319,19 @@ void _spIkConstraintTimeline_apply (const spTimeline* timeline, spSkeleton* skel
|
||||
if (time >= frames[framesCount - IKCONSTRAINT_ENTRIES]) { /* Time is after last frame. */
|
||||
if (blend == SP_MIX_BLEND_SETUP) {
|
||||
constraint->mix = constraint->data->mix + (frames[framesCount + IKCONSTRAINT_PREV_MIX] - constraint->data->mix) * alpha;
|
||||
constraint->bendDirection = direction == SP_MIX_DIRECTION_OUT ? constraint->data->bendDirection
|
||||
: (int)frames[framesCount + IKCONSTRAINT_PREV_BEND_DIRECTION];
|
||||
if (direction == SP_MIX_DIRECTION_OUT) {
|
||||
constraint->bendDirection = constraint->data->bendDirection;
|
||||
constraint->stretch = constraint->data->stretch;
|
||||
} else {
|
||||
constraint->bendDirection = (int)frames[framesCount + IKCONSTRAINT_PREV_BEND_DIRECTION];
|
||||
constraint->stretch = frames[framesCount + IKCONSTRAINT_PREV_STRETCH] ? 1 : 0;
|
||||
}
|
||||
} else {
|
||||
constraint->mix += (frames[framesCount + IKCONSTRAINT_PREV_MIX] - constraint->mix) * alpha;
|
||||
if (direction == SP_MIX_DIRECTION_IN) constraint->bendDirection = (int)frames[framesCount + IKCONSTRAINT_PREV_BEND_DIRECTION];
|
||||
if (direction == SP_MIX_DIRECTION_IN) {
|
||||
constraint->bendDirection = (int)frames[framesCount + IKCONSTRAINT_PREV_BEND_DIRECTION];
|
||||
constraint->stretch = frames[framesCount + IKCONSTRAINT_PREV_STRETCH] ? 1 : 0;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -1326,10 +1344,19 @@ void _spIkConstraintTimeline_apply (const spTimeline* timeline, spSkeleton* skel
|
||||
|
||||
if (blend == SP_MIX_BLEND_SETUP) {
|
||||
constraint->mix = constraint->data->mix + (mix + (frames[frame + IKCONSTRAINT_MIX] - mix) * percent - constraint->data->mix) * alpha;
|
||||
constraint->bendDirection = direction == SP_MIX_DIRECTION_OUT ? constraint->data->bendDirection : (int)frames[frame + IKCONSTRAINT_PREV_BEND_DIRECTION];
|
||||
if (direction == SP_MIX_DIRECTION_OUT) {
|
||||
constraint->bendDirection = constraint->data->bendDirection;
|
||||
constraint->stretch = constraint->data->stretch;
|
||||
} else {
|
||||
constraint->bendDirection = (int)frames[frame + IKCONSTRAINT_PREV_BEND_DIRECTION];
|
||||
constraint->stretch = frames[frame + IKCONSTRAINT_PREV_STRETCH] ? 1 : 0;
|
||||
}
|
||||
} else {
|
||||
constraint->mix += (mix + (frames[frame + IKCONSTRAINT_MIX] - mix) * percent - constraint->mix) * alpha;
|
||||
if (direction == SP_MIX_DIRECTION_IN) constraint->bendDirection = (int)frames[frame + IKCONSTRAINT_PREV_BEND_DIRECTION];
|
||||
if (direction == SP_MIX_DIRECTION_IN) {
|
||||
constraint->bendDirection = (int)frames[frame + IKCONSTRAINT_PREV_BEND_DIRECTION];
|
||||
constraint->stretch = frames[frame + IKCONSTRAINT_PREV_STRETCH] ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
UNUSED(lastTime);
|
||||
@ -1345,11 +1372,12 @@ spIkConstraintTimeline* spIkConstraintTimeline_create (int framesCount) {
|
||||
return (spIkConstraintTimeline*)_spBaseTimeline_create(framesCount, SP_TIMELINE_IKCONSTRAINT, IKCONSTRAINT_ENTRIES, _spIkConstraintTimeline_apply, _spIkConstraintTimeline_getPropertyId);
|
||||
}
|
||||
|
||||
void spIkConstraintTimeline_setFrame (spIkConstraintTimeline* self, int frameIndex, float time, float mix, int bendDirection) {
|
||||
void spIkConstraintTimeline_setFrame (spIkConstraintTimeline* self, int frameIndex, float time, float mix, int bendDirection, int /*boolean*/ stretch) {
|
||||
frameIndex *= IKCONSTRAINT_ENTRIES;
|
||||
self->frames[frameIndex] = time;
|
||||
self->frames[frameIndex + IKCONSTRAINT_MIX] = mix;
|
||||
self->frames[frameIndex + IKCONSTRAINT_BEND_DIRECTION] = (float)bendDirection;
|
||||
self->frames[frameIndex + IKCONSTRAINT_STRETCH] = stretch ? 1 : 0;
|
||||
}
|
||||
|
||||
/**/
|
||||
@ -1435,6 +1463,7 @@ void _spTransformConstraintTimeline_apply (const spTimeline* timeline, spSkeleto
|
||||
UNUSED(lastTime);
|
||||
UNUSED(firedEvents);
|
||||
UNUSED(eventsCount);
|
||||
UNUSED(direction);
|
||||
}
|
||||
|
||||
int _spTransformConstraintTimeline_getPropertyId (const spTimeline* timeline) {
|
||||
@ -1506,6 +1535,7 @@ void _spPathConstraintPositionTimeline_apply(const spTimeline* timeline, spSkele
|
||||
UNUSED(lastTime);
|
||||
UNUSED(firedEvents);
|
||||
UNUSED(eventsCount);
|
||||
UNUSED(direction);
|
||||
}
|
||||
|
||||
int _spPathConstraintPositionTimeline_getPropertyId (const spTimeline* timeline) {
|
||||
@ -1574,6 +1604,7 @@ void _spPathConstraintSpacingTimeline_apply(const spTimeline* timeline, spSkelet
|
||||
UNUSED(lastTime);
|
||||
UNUSED(firedEvents);
|
||||
UNUSED(eventsCount);
|
||||
UNUSED(direction);
|
||||
}
|
||||
|
||||
int _spPathConstraintSpacingTimeline_getPropertyId (const spTimeline* timeline) {
|
||||
@ -1653,6 +1684,7 @@ void _spPathConstraintMixTimeline_apply(const spTimeline* timeline, spSkeleton*
|
||||
UNUSED(lastTime);
|
||||
UNUSED(firedEvents);
|
||||
UNUSED(eventsCount);
|
||||
UNUSED(direction);
|
||||
}
|
||||
|
||||
int _spPathConstraintMixTimeline_getPropertyId (const spTimeline* timeline) {
|
||||
|
||||
@ -516,6 +516,7 @@ void _spAnimationState_applyRotateTimeline (spAnimationState* self, spTimeline*
|
||||
float percent;
|
||||
float total, diff;
|
||||
int /*boolean*/ current, dir;
|
||||
UNUSED(self);
|
||||
|
||||
if (firstFrame) timelinesRotation[i] = 0;
|
||||
|
||||
|
||||
@ -39,6 +39,7 @@ spIkConstraint *spIkConstraint_create(spIkConstraintData *data, const spSkeleton
|
||||
spIkConstraint *self = NEW(spIkConstraint);
|
||||
CONST_CAST(spIkConstraintData*, self->data) = data;
|
||||
self->bendDirection = data->bendDirection;
|
||||
self->stretch = data->stretch;
|
||||
self->mix = data->mix;
|
||||
|
||||
self->bonesCount = self->data->bonesCount;
|
||||
@ -58,17 +59,17 @@ void spIkConstraint_dispose(spIkConstraint *self) {
|
||||
void spIkConstraint_apply(spIkConstraint *self) {
|
||||
switch (self->bonesCount) {
|
||||
case 1:
|
||||
spIkConstraint_apply1(self->bones[0], self->target->worldX, self->target->worldY, self->mix);
|
||||
spIkConstraint_apply1(self->bones[0], self->target->worldX, self->target->worldY, self->stretch, self->mix);
|
||||
break;
|
||||
case 2:
|
||||
spIkConstraint_apply2(self->bones[0], self->bones[1], self->target->worldX, self->target->worldY, self->bendDirection, self->mix);
|
||||
spIkConstraint_apply2(self->bones[0], self->bones[1], self->target->worldX, self->target->worldY, self->bendDirection, self->stretch, self->mix);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void spIkConstraint_apply1 (spBone* bone, float targetX, float targetY, float alpha) {
|
||||
void spIkConstraint_apply1 (spBone* bone, float targetX, float targetY, int /*boolean*/ stretch, float alpha) {
|
||||
spBone* p = bone->parent;
|
||||
float id, x, y, tx, ty, rotationIK;
|
||||
float id, x, y, tx, ty, rotationIK, sx;
|
||||
if (!bone->appliedValid) spBone_updateAppliedTransform(bone);
|
||||
id = 1 / (p->a * p->d - p->b * p->c);
|
||||
x = targetX - p->worldX, y = targetY - p->worldY;
|
||||
@ -77,16 +78,21 @@ void spIkConstraint_apply1 (spBone* bone, float targetX, float targetY, float al
|
||||
if (bone->ascaleX < 0) rotationIK += 180;
|
||||
if (rotationIK > 180) rotationIK -= 360;
|
||||
else if (rotationIK < -180) rotationIK += 360;
|
||||
spBone_updateWorldTransformWith(bone, bone->ax, bone->ay, bone->arotation + rotationIK * alpha, bone->ascaleX,
|
||||
sx = bone->ascaleX;
|
||||
if (stretch) {
|
||||
float b = bone->data->length * sx, dd = SQRT(tx * tx + ty * ty);
|
||||
if (dd > b && b > 0.0001f) sx *= (dd / b - 1) * alpha - 1;
|
||||
}
|
||||
spBone_updateWorldTransformWith(bone, bone->ax, bone->ay, bone->arotation + rotationIK * alpha, sx,
|
||||
bone->ascaleY, bone->ashearX, bone->ashearY);
|
||||
}
|
||||
|
||||
void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float targetY, int bendDir, float alpha) {
|
||||
float px, py, psx, psy;
|
||||
void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float targetY, int bendDir, int /*boolean*/ stretch, float alpha) {
|
||||
float px, py, psx, sx, psy;
|
||||
float cx, cy, csx, cwx, cwy;
|
||||
int o1, o2, s2, u;
|
||||
spBone* pp = parent->parent;
|
||||
float tx, ty, dx, dy, l1, l2, a1, a2, r;
|
||||
float tx, ty, dd, dx, dy, l1, l2, a1, a2, r;
|
||||
float id, x, y;
|
||||
if (alpha == 0) {
|
||||
spBone_updateWorldTransform(child);
|
||||
@ -94,7 +100,7 @@ void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float
|
||||
}
|
||||
if (!parent->appliedValid) spBone_updateAppliedTransform(parent);
|
||||
if (!child->appliedValid) spBone_updateAppliedTransform(child);
|
||||
px = parent->ax; py = parent->ay; psx = parent->ascaleX; psy = parent->ascaleY; csx = child->ascaleX;
|
||||
px = parent->ax; py = parent->ay; psx = parent->ascaleX; sx = psx; psy = parent->ascaleY; csx = child->ascaleX;
|
||||
if (psx < 0) {
|
||||
psx = -psx;
|
||||
o1 = 180;
|
||||
@ -129,6 +135,7 @@ void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float
|
||||
y = targetY - pp->worldY;
|
||||
tx = (x * pp->d - y * pp->b) * id - px;
|
||||
ty = (y * pp->a - x * pp->c) * id - py;
|
||||
dd = tx * tx + ty * ty;
|
||||
x = cwx - pp->worldX;
|
||||
y = cwy - pp->worldY;
|
||||
dx = (x * pp->d - y * pp->b) * id - px;
|
||||
@ -138,16 +145,19 @@ void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float
|
||||
if (u) {
|
||||
float cosine, a, b;
|
||||
l2 *= psx;
|
||||
cosine = (tx * tx + ty * ty - l1 * l1 - l2 * l2) / (2 * l1 * l2);
|
||||
cosine = (dd - l1 * l1 - l2 * l2) / (2 * l1 * l2);
|
||||
if (cosine < -1) cosine = -1;
|
||||
else if (cosine > 1) cosine = 1;
|
||||
else if (cosine > 1) {
|
||||
cosine = 1;
|
||||
if (stretch && l1 + l2 > 0.0001f) sx *= (SQRT(dd) / (l1 + l2) - 1) * alpha + 1;
|
||||
}
|
||||
a2 = ACOS(cosine) * bendDir;
|
||||
a = l1 + l2 * cosine;
|
||||
b = l2 * SIN(a2);
|
||||
a1 = ATAN2(ty * a - tx * b, tx * a + ty * b);
|
||||
} else {
|
||||
float a = psx * l2, b = psy * l2;
|
||||
float aa = a * a, bb = b * b, ll = l1 * l1, dd = tx * tx + ty * ty, ta = ATAN2(ty, tx);
|
||||
float aa = a * a, bb = b * b, ll = l1 * l1, ta = ATAN2(ty, tx);
|
||||
float c0 = bb * ll + aa * dd - aa * bb, c1 = -2 * bb * l1, c2 = bb - aa;
|
||||
float d = c1 * c1 - 4 * c2 * c0;
|
||||
if (d >= 0) {
|
||||
@ -199,7 +209,7 @@ void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float
|
||||
a1 = (a1 - os) * RAD_DEG + o1 - parent->arotation;
|
||||
if (a1 > 180) a1 -= 360;
|
||||
else if (a1 < -180) a1 += 360;
|
||||
spBone_updateWorldTransformWith(parent, px, py, parent->rotation + a1 * alpha, parent->ascaleX, parent->ascaleY, 0, 0);
|
||||
spBone_updateWorldTransformWith(parent, px, py, parent->rotation + a1 * alpha, sx, parent->ascaleY, 0, 0);
|
||||
a2 = ((a2 + os) * RAD_DEG - child->ashearX) * s2 + o2 - child->arotation;
|
||||
if (a2 > 180) a2 -= 360;
|
||||
else if (a2 < -180) a2 += 360;
|
||||
|
||||
@ -35,6 +35,7 @@ spIkConstraintData* spIkConstraintData_create (const char* name) {
|
||||
spIkConstraintData* self = NEW(spIkConstraintData);
|
||||
MALLOC_STR(self->name, name);
|
||||
self->bendDirection = 1;
|
||||
self->stretch = 0;
|
||||
self->mix = 1;
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -82,6 +82,7 @@ void spPathConstraint_apply (spPathConstraint* self) {
|
||||
int/*bool*/tip;
|
||||
float rotateMix = self->rotateMix, translateMix = self->translateMix;
|
||||
int/*bool*/ translate = translateMix > 0, rotate = rotateMix > 0;
|
||||
int lengthSpacing;
|
||||
spPathAttachment* attachment = (spPathAttachment*)self->target->attachment;
|
||||
spPathConstraintData* data = self->data;
|
||||
int percentSpacing = data->spacingMode == SP_SPACING_MODE_PERCENT;
|
||||
@ -112,7 +113,7 @@ void spPathConstraint_apply (spPathConstraint* self) {
|
||||
}
|
||||
lengths = self->lengths;
|
||||
}
|
||||
int lengthSpacing = data->spacingMode == SP_SPACING_MODE_LENGTH;
|
||||
lengthSpacing = data->spacingMode == SP_SPACING_MODE_LENGTH;
|
||||
for (i = 0, n = spacesCount - 1; i < n;) {
|
||||
spBone *bone = bones[i];
|
||||
setupLength = bone->data->length;
|
||||
|
||||
@ -436,6 +436,7 @@ void spSkeleton_setBonesToSetupPose (const spSkeleton* self) {
|
||||
for (i = 0; i < self->ikConstraintsCount; ++i) {
|
||||
spIkConstraint* ikConstraint = self->ikConstraints[i];
|
||||
ikConstraint->bendDirection = ikConstraint->data->bendDirection;
|
||||
ikConstraint->stretch = ikConstraint->data->stretch;
|
||||
ikConstraint->mix = ikConstraint->data->mix;
|
||||
}
|
||||
|
||||
|
||||
@ -392,7 +392,8 @@ static spAnimation* _spSkeletonBinary_readAnimation (spSkeletonBinary* self, con
|
||||
float time = readFloat(input);
|
||||
float mix = readFloat(input);
|
||||
signed char bendDirection = readSByte(input);
|
||||
spIkConstraintTimeline_setFrame(timeline, frameIndex, time, mix, bendDirection);
|
||||
int stretch = readBoolean(input);
|
||||
spIkConstraintTimeline_setFrame(timeline, frameIndex, time, mix, bendDirection, stretch);
|
||||
if (frameIndex < frameCount - 1) readCurve(input, SUPER(timeline), frameIndex);
|
||||
}
|
||||
spTimelineArray_add(timelines, (spTimeline*)timeline);
|
||||
@ -925,7 +926,7 @@ spSkeletonData* spSkeletonBinary_readSkeletonData (spSkeletonBinary* self, const
|
||||
/* TODO Avoid copying of slotName */
|
||||
spSlotData* slotData = spSlotData_create(i, slotName, boneData);
|
||||
FREE(slotName);
|
||||
readColor(input, &slotData->color.r, &slotData->color.g, &slotData->color.b, &slotData->color.a);
|
||||
readColor(input, &slotData->color.r, &slotData->color.g, &slotData->color.b, &slotData->color.a);
|
||||
a = readByte(input);
|
||||
r = readByte(input);
|
||||
g = readByte(input);
|
||||
@ -955,6 +956,7 @@ spSkeletonData* spSkeletonBinary_readSkeletonData (spSkeletonBinary* self, const
|
||||
data->target = skeletonData->bones[readVarint(input, 1)];
|
||||
data->mix = readFloat(input);
|
||||
data->bendDirection = readSByte(input);
|
||||
data->stretch = readBoolean(input);
|
||||
skeletonData->ikConstraints[i] = data;
|
||||
}
|
||||
|
||||
|
||||
@ -310,4 +310,5 @@ void spSkeletonClipping_clipTriangles(spSkeletonClipping* self, float* vertices,
|
||||
}
|
||||
}
|
||||
}
|
||||
UNUSED(verticesLength);
|
||||
}
|
||||
|
||||
@ -299,7 +299,7 @@ static spAnimation* _spSkeletonJson_readAnimation (spSkeletonJson* self, Json* r
|
||||
}
|
||||
for (valueMap = constraintMap->child, frameIndex = 0; valueMap; valueMap = valueMap->next, ++frameIndex) {
|
||||
spIkConstraintTimeline_setFrame(timeline, frameIndex, Json_getFloat(valueMap, "time", 0), Json_getFloat(valueMap, "mix", 1),
|
||||
Json_getInt(valueMap, "bendPositive", 1) ? 1 : -1);
|
||||
Json_getInt(valueMap, "bendPositive", 1) ? 1 : -1, Json_getInt(valueMap, "stretch", 0) ? 1 : 0);
|
||||
readCurve(valueMap, SUPER(timeline), frameIndex);
|
||||
}
|
||||
animation->timelines[animation->timelinesCount++] = SUPER_CAST(spTimeline, timeline);
|
||||
@ -737,6 +737,7 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
|
||||
}
|
||||
|
||||
data->bendDirection = Json_getInt(constraintMap, "bendPositive", 1) ? 1 : -1;
|
||||
data->stretch = Json_getInt(constraintMap, "stretch", 0) ? 1 : 0;
|
||||
data->mix = Json_getFloat(constraintMap, "mix", 1);
|
||||
|
||||
skeletonData->ikConstraints[i] = data;
|
||||
|
||||
@ -32,6 +32,8 @@
|
||||
#include <spine/extension.h>
|
||||
|
||||
void _spJitterVertexEffect_begin(spVertexEffect* self, spSkeleton* skeleton) {
|
||||
UNUSED(self);
|
||||
UNUSED(skeleton);
|
||||
}
|
||||
|
||||
void _spJitterVertexEffect_transform(spVertexEffect* self, float* x, float* y, float* u, float* v, spColor* light, spColor* dark) {
|
||||
@ -40,9 +42,14 @@ void _spJitterVertexEffect_transform(spVertexEffect* self, float* x, float* y, f
|
||||
float jitterY = internal->jitterY;
|
||||
(*x) += _spMath_randomTriangular(-jitterX, jitterY);
|
||||
(*y) += _spMath_randomTriangular(-jitterX, jitterY);
|
||||
UNUSED(u);
|
||||
UNUSED(v);
|
||||
UNUSED(light);
|
||||
UNUSED(dark);
|
||||
}
|
||||
|
||||
void _spJitterVertexEffect_end(spVertexEffect* self) {
|
||||
UNUSED(self);
|
||||
}
|
||||
|
||||
spJitterVertexEffect* spJitterVertexEffect_create(float jitterX, float jitterY) {
|
||||
@ -78,6 +85,11 @@ void _spSwirlVertexEffect_transform(spVertexEffect* self, float* positionX, floa
|
||||
(*positionX) = cosine * x - sine * y + internal->worldX;
|
||||
(*positionY) = sine * x + cosine * y + internal->worldY;
|
||||
}
|
||||
UNUSED(self);
|
||||
UNUSED(u);
|
||||
UNUSED(v);
|
||||
UNUSED(light);
|
||||
UNUSED(dark);
|
||||
}
|
||||
|
||||
void _spSwirlVertexEffect_end(spVertexEffect* self) {
|
||||
|
||||
@ -226,6 +226,7 @@ void Skeleton::setBonesToSetupPose() {
|
||||
IkConstraint &constraint = *constraintP;
|
||||
|
||||
constraint._bendDirection = constraint._data._bendDirection;
|
||||
constraint._stretch = constraint._data._stretch;
|
||||
constraint._mix = constraint._data._mix;
|
||||
}
|
||||
|
||||
|
||||
@ -442,6 +442,7 @@ void test (SkeletonData* skeletonData, Atlas* atlas) {
|
||||
|
||||
int main () {
|
||||
testcase(test, "data/tank-pro.json", "data/tank-pro.skel", "data/tank.atlas", 1.0f);
|
||||
testcase(stretchyman, "data/stretchyman-stretchy-ik.json", "data/stretchyman-stretchy-ik.skel", "data/stretchyman.atlas", 0.6f);
|
||||
testcase(owl, "data/owl-pro.json", "data/owl-pro.skel", "data/owl.atlas", 0.5f);
|
||||
testcase(coin, "data/coin-pro.json", "data/coin-pro.skel", "data/coin.atlas", 0.5f);
|
||||
testcase(vine, "data/vine-pro.json", "data/vine-pro.skel", "data/vine.atlas", 0.5f);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user