mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[c][cpp] Ported flipX/flipY -> scaleX/scaleY change. See #1142.
This commit is contained in:
parent
172bf22d84
commit
5aab588928
@ -66,7 +66,7 @@ typedef struct spSkeleton {
|
|||||||
spSkin* const skin;
|
spSkin* const skin;
|
||||||
spColor color;
|
spColor color;
|
||||||
float time;
|
float time;
|
||||||
int/*bool*/flipX, flipY;
|
float scaleX, scaleY;
|
||||||
float x, y;
|
float x, y;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -88,8 +88,8 @@ typedef struct spSkeleton {
|
|||||||
skin(0),
|
skin(0),
|
||||||
color(),
|
color(),
|
||||||
time(0),
|
time(0),
|
||||||
flipX(0),
|
scaleX(1),
|
||||||
flipY(0),
|
scaleY(1),
|
||||||
x(0), y(0) {
|
x(0), y(0) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -65,6 +65,8 @@ void spBone_updateWorldTransformWith (spBone* self, float x, float y, float rota
|
|||||||
float cosine, sine;
|
float cosine, sine;
|
||||||
float pa, pb, pc, pd;
|
float pa, pb, pc, pd;
|
||||||
spBone* parent = self->parent;
|
spBone* parent = self->parent;
|
||||||
|
float sx = self->skeleton->scaleX;
|
||||||
|
float sy = self->skeleton->scaleY * (spBone_isYDown() ? -1 : 1);
|
||||||
|
|
||||||
self->ax = x;
|
self->ax = x;
|
||||||
self->ay = y;
|
self->ay = y;
|
||||||
@ -77,26 +79,12 @@ void spBone_updateWorldTransformWith (spBone* self, float x, float y, float rota
|
|||||||
|
|
||||||
if (!parent) { /* Root bone. */
|
if (!parent) { /* Root bone. */
|
||||||
float rotationY = rotation + 90 + shearY;
|
float rotationY = rotation + 90 + shearY;
|
||||||
float la = COS_DEG(rotation + shearX) * scaleX;
|
CONST_CAST(float, self->a) = COS_DEG(rotation + shearX) * scaleX * sx;
|
||||||
float lb = COS_DEG(rotationY) * scaleY;
|
CONST_CAST(float, self->b) = COS_DEG(rotationY) * scaleY * sy;
|
||||||
float lc = SIN_DEG(rotation + shearX) * scaleX;
|
CONST_CAST(float, self->c) = SIN_DEG(rotation + shearX) * scaleX * sx;
|
||||||
float ld = SIN_DEG(rotationY) * scaleY;
|
CONST_CAST(float, self->d) = SIN_DEG(rotationY) * scaleY * sy;
|
||||||
if (self->skeleton->flipX) {
|
CONST_CAST(float, self->worldX) = x * sx + self->skeleton->x;
|
||||||
x = -x;
|
CONST_CAST(float, self->worldY) = y * sy + self->skeleton->y;
|
||||||
la = -la;
|
|
||||||
lb = -lb;
|
|
||||||
}
|
|
||||||
if (self->skeleton->flipY != yDown) {
|
|
||||||
y = -y;
|
|
||||||
lc = -lc;
|
|
||||||
ld = -ld;
|
|
||||||
}
|
|
||||||
CONST_CAST(float, self->a) = la;
|
|
||||||
CONST_CAST(float, self->b) = lb;
|
|
||||||
CONST_CAST(float, self->c) = lc;
|
|
||||||
CONST_CAST(float, self->d) = ld;
|
|
||||||
CONST_CAST(float, self->worldX) = x + self->skeleton->x;
|
|
||||||
CONST_CAST(float, self->worldY) = y + self->skeleton->y;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,8 +147,8 @@ void spBone_updateWorldTransformWith (spBone* self, float x, float y, float rota
|
|||||||
float za, zc, s;
|
float za, zc, s;
|
||||||
float r, zb, zd, la, lb, lc, ld;
|
float r, zb, zd, la, lb, lc, ld;
|
||||||
cosine = COS_DEG(rotation); sine = SIN_DEG(rotation);
|
cosine = COS_DEG(rotation); sine = SIN_DEG(rotation);
|
||||||
za = pa * cosine + pb * sine;
|
za = (pa * cosine + pb * sine) / sx;
|
||||||
zc = pc * cosine + pd * sine;
|
zc = (pc * cosine + pd * sine) / sy;
|
||||||
s = SQRT(za * za + zc * zc);
|
s = SQRT(za * za + zc * zc);
|
||||||
if (s > 0.00001f) s = 1 / s;
|
if (s > 0.00001f) s = 1 / s;
|
||||||
za *= s;
|
za *= s;
|
||||||
@ -173,25 +161,18 @@ void spBone_updateWorldTransformWith (spBone* self, float x, float y, float rota
|
|||||||
lb = COS_DEG(90 + shearY) * scaleY;
|
lb = COS_DEG(90 + shearY) * scaleY;
|
||||||
lc = SIN_DEG(shearX) * scaleX;
|
lc = SIN_DEG(shearX) * scaleX;
|
||||||
ld = SIN_DEG(90 + shearY) * scaleY;
|
ld = SIN_DEG(90 + shearY) * scaleY;
|
||||||
if (self->data->transformMode != SP_TRANSFORMMODE_NOSCALEORREFLECTION ? pa * pd - pb * pc < 0 : self->skeleton->flipX != self->skeleton->flipY) {
|
|
||||||
zb = -zb;
|
|
||||||
zd = -zd;
|
|
||||||
}
|
|
||||||
CONST_CAST(float, self->a) = za * la + zb * lc;
|
CONST_CAST(float, self->a) = za * la + zb * lc;
|
||||||
CONST_CAST(float, self->b) = za * lb + zb * ld;
|
CONST_CAST(float, self->b) = za * lb + zb * ld;
|
||||||
CONST_CAST(float, self->c) = zc * la + zd * lc;
|
CONST_CAST(float, self->c) = zc * la + zd * lc;
|
||||||
CONST_CAST(float, self->d) = zc * lb + zd * ld;
|
CONST_CAST(float, self->d) = zc * lb + zd * ld;
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (self->skeleton->flipX) {
|
|
||||||
CONST_CAST(float, self->a) = -self->a;
|
CONST_CAST(float, self->a) *= sx;
|
||||||
CONST_CAST(float, self->b) = -self->b;
|
CONST_CAST(float, self->b) *= sx;
|
||||||
}
|
CONST_CAST(float, self->c) *= sy;
|
||||||
if (self->skeleton->flipY != yDown) {
|
CONST_CAST(float, self->d) *= sy;
|
||||||
CONST_CAST(float, self->c) = -self->c;
|
|
||||||
CONST_CAST(float, self->d) = -self->d;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void spBone_setToSetupPose (spBone* self) {
|
void spBone_setToSetupPose (spBone* self) {
|
||||||
|
|||||||
@ -119,6 +119,9 @@ spSkeleton* spSkeleton_create (spSkeletonData* data) {
|
|||||||
|
|
||||||
spColor_setFromFloats(&self->color, 1, 1, 1, 1);
|
spColor_setFromFloats(&self->color, 1, 1, 1, 1);
|
||||||
|
|
||||||
|
self->scaleX = 1;
|
||||||
|
self->scaleY = 1;
|
||||||
|
|
||||||
spSkeleton_updateCache(self);
|
spSkeleton_updateCache(self);
|
||||||
|
|
||||||
FREE(childrenCounts);
|
FREE(childrenCounts);
|
||||||
|
|||||||
@ -204,13 +204,13 @@ public:
|
|||||||
|
|
||||||
void setY(float inValue);
|
void setY(float inValue);
|
||||||
|
|
||||||
bool getFlipX();
|
float getScaleX();
|
||||||
|
|
||||||
void setFlipX(bool inValue);
|
void setScaleX(float inValue);
|
||||||
|
|
||||||
bool getFlipY();
|
float getScaleY();
|
||||||
|
|
||||||
void setFlipY(bool inValue);
|
void setScaleY(float inValue);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SkeletonData *_data;
|
SkeletonData *_data;
|
||||||
@ -225,7 +225,7 @@ private:
|
|||||||
Skin *_skin;
|
Skin *_skin;
|
||||||
Color _color;
|
Color _color;
|
||||||
float _time;
|
float _time;
|
||||||
bool _flipX, _flipY;
|
float _scaleX, _scaleY;
|
||||||
float _x, _y;
|
float _x, _y;
|
||||||
|
|
||||||
void sortIkConstraint(IkConstraint *constraint);
|
void sortIkConstraint(IkConstraint *constraint);
|
||||||
|
|||||||
@ -101,26 +101,14 @@ Bone::updateWorldTransform(float x, float y, float rotation, float scaleX, float
|
|||||||
|
|
||||||
if (!parent) { /* Root bone. */
|
if (!parent) { /* Root bone. */
|
||||||
float rotationY = rotation + 90 + shearY;
|
float rotationY = rotation + 90 + shearY;
|
||||||
float la = MathUtil::cosDeg(rotation + shearX) * scaleX;
|
float sx = _skeleton.getScaleX();
|
||||||
float lb = MathUtil::cosDeg(rotationY) * scaleY;
|
float sy = _skeleton.getScaleY();
|
||||||
float lc = MathUtil::sinDeg(rotation + shearX) * scaleX;
|
_a = MathUtil::cosDeg(rotation + shearX) * scaleX * sx;
|
||||||
float ld = MathUtil::sinDeg(rotationY) * scaleY;
|
_b = MathUtil::cosDeg(rotationY) * scaleY * sy;
|
||||||
if (_skeleton.getFlipX()) {
|
_c = MathUtil::sinDeg(rotation + shearX) * scaleX * sx;
|
||||||
x = -x;
|
_d = MathUtil::sinDeg(rotationY) * scaleY * sy;
|
||||||
la = -la;
|
_worldX = x * sx + _skeleton.getX();
|
||||||
lb = -lb;
|
_worldY = y * sy + _skeleton.getY();
|
||||||
}
|
|
||||||
if (_skeleton.getFlipY() != yDown) {
|
|
||||||
y = -y;
|
|
||||||
lc = -lc;
|
|
||||||
ld = -ld;
|
|
||||||
}
|
|
||||||
_a = la;
|
|
||||||
_b = lb;
|
|
||||||
_c = lc;
|
|
||||||
_d = ld;
|
|
||||||
_worldX = x + _skeleton.getX();
|
|
||||||
_worldY = y + _skeleton.getY();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,8 +172,8 @@ Bone::updateWorldTransform(float x, float y, float rotation, float scaleX, float
|
|||||||
float r, zb, zd, la, lb, lc, ld;
|
float r, zb, zd, la, lb, lc, ld;
|
||||||
cosine = MathUtil::cosDeg(rotation);
|
cosine = MathUtil::cosDeg(rotation);
|
||||||
sine = MathUtil::sinDeg(rotation);
|
sine = MathUtil::sinDeg(rotation);
|
||||||
za = pa * cosine + pb * sine;
|
za = (pa * cosine + pb * sine) / _skeleton.getScaleX();
|
||||||
zc = pc * cosine + pd * sine;
|
zc = (pc * cosine + pd * sine) / _skeleton.getScaleY();
|
||||||
s = MathUtil::sqrt(za * za + zc * zc);
|
s = MathUtil::sqrt(za * za + zc * zc);
|
||||||
if (s > 0.00001f) s = 1 / s;
|
if (s > 0.00001f) s = 1 / s;
|
||||||
za *= s;
|
za *= s;
|
||||||
@ -198,26 +186,17 @@ Bone::updateWorldTransform(float x, float y, float rotation, float scaleX, float
|
|||||||
lb = MathUtil::cosDeg(90 + shearY) * scaleY;
|
lb = MathUtil::cosDeg(90 + shearY) * scaleY;
|
||||||
lc = MathUtil::sinDeg(shearX) * scaleX;
|
lc = MathUtil::sinDeg(shearX) * scaleX;
|
||||||
ld = MathUtil::sinDeg(90 + shearY) * scaleY;
|
ld = MathUtil::sinDeg(90 + shearY) * scaleY;
|
||||||
if (getData().getTransformMode() != TransformMode_NoScaleOrReflection ? pa * pd - pb * pc < 0 :
|
|
||||||
_skeleton.getFlipX() != _skeleton.getFlipY()) {
|
|
||||||
zb = -zb;
|
|
||||||
zd = -zd;
|
|
||||||
}
|
|
||||||
_a = za * la + zb * lc;
|
_a = za * la + zb * lc;
|
||||||
_b = za * lb + zb * ld;
|
_b = za * lb + zb * ld;
|
||||||
_c = zc * la + zd * lc;
|
_c = zc * la + zd * lc;
|
||||||
_d = zc * lb + zd * ld;
|
_d = zc * lb + zd * ld;
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_skeleton.getFlipX()) {
|
_a *= _skeleton.getScaleX();
|
||||||
_a = -_a;
|
_b *= _skeleton.getScaleX();
|
||||||
_b = -_b;
|
_c *= _skeleton.getScaleY();
|
||||||
}
|
_d *= _skeleton.getScaleY();
|
||||||
if (_skeleton.getFlipY() != yDown) {
|
|
||||||
_c = -_c;
|
|
||||||
_d = -_d;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bone::setToSetupPose() {
|
void Bone::setToSetupPose() {
|
||||||
|
|||||||
@ -57,8 +57,8 @@ Skeleton::Skeleton(SkeletonData *skeletonData) :
|
|||||||
_skin(NULL),
|
_skin(NULL),
|
||||||
_color(1, 1, 1, 1),
|
_color(1, 1, 1, 1),
|
||||||
_time(0),
|
_time(0),
|
||||||
_flipX(false),
|
_scaleX(1),
|
||||||
_flipY(false),
|
_scaleY(1),
|
||||||
_x(0),
|
_x(0),
|
||||||
_y(0) {
|
_y(0) {
|
||||||
_bones.ensureCapacity(_data->getBones().size());
|
_bones.ensureCapacity(_data->getBones().size());
|
||||||
@ -513,20 +513,20 @@ void Skeleton::setY(float inValue) {
|
|||||||
_y = inValue;
|
_y = inValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Skeleton::getFlipX() {
|
float Skeleton::getScaleX() {
|
||||||
return _flipX;
|
return _scaleX;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Skeleton::setFlipX(bool inValue) {
|
void Skeleton::setScaleX(float inValue) {
|
||||||
_flipX = inValue;
|
_scaleX = inValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Skeleton::getFlipY() {
|
float Skeleton::getScaleY() {
|
||||||
return _flipY;
|
return _scaleY * (Bone::isYDown() ? -1 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Skeleton::setFlipY(bool inValue) {
|
void Skeleton::setScaleY(float inValue) {
|
||||||
_flipY = inValue;
|
_scaleY = inValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Skeleton::sortIkConstraint(IkConstraint *constraint) {
|
void Skeleton::sortIkConstraint(IkConstraint *constraint) {
|
||||||
|
|||||||
@ -119,8 +119,6 @@ void spineboy (SkeletonData* skeletonData, Atlas* atlas) {
|
|||||||
drawable->timeScale = 1;
|
drawable->timeScale = 1;
|
||||||
|
|
||||||
Skeleton* skeleton = drawable->skeleton;
|
Skeleton* skeleton = drawable->skeleton;
|
||||||
skeleton->flipX = false;
|
|
||||||
skeleton->flipY = false;
|
|
||||||
Skeleton_setToSetupPose(skeleton);
|
Skeleton_setToSetupPose(skeleton);
|
||||||
|
|
||||||
skeleton->x = 320;
|
skeleton->x = 320;
|
||||||
@ -170,8 +168,6 @@ void goblins (SkeletonData* skeletonData, Atlas* atlas) {
|
|||||||
drawable->timeScale = 1;
|
drawable->timeScale = 1;
|
||||||
|
|
||||||
Skeleton* skeleton = drawable->skeleton;
|
Skeleton* skeleton = drawable->skeleton;
|
||||||
skeleton->flipX = false;
|
|
||||||
skeleton->flipY = false;
|
|
||||||
Skeleton_setSkinByName(skeleton, "goblin");
|
Skeleton_setSkinByName(skeleton, "goblin");
|
||||||
Skeleton_setSlotsToSetupPose(skeleton);
|
Skeleton_setSlotsToSetupPose(skeleton);
|
||||||
//Skeleton_setAttachment(skeleton, "left hand item", "dagger");
|
//Skeleton_setAttachment(skeleton, "left hand item", "dagger");
|
||||||
@ -307,9 +303,6 @@ void stretchyman (SkeletonData* skeletonData, Atlas* atlas) {
|
|||||||
drawable->timeScale = 1;
|
drawable->timeScale = 1;
|
||||||
|
|
||||||
Skeleton* skeleton = drawable->skeleton;
|
Skeleton* skeleton = drawable->skeleton;
|
||||||
skeleton->flipX = false;
|
|
||||||
skeleton->flipY = false;
|
|
||||||
|
|
||||||
skeleton->x = 100;
|
skeleton->x = 100;
|
||||||
skeleton->y = 590;
|
skeleton->y = 590;
|
||||||
Skeleton_updateWorldTransform(skeleton);
|
Skeleton_updateWorldTransform(skeleton);
|
||||||
|
|||||||
@ -118,8 +118,6 @@ void spineboy (SkeletonData* skeletonData, Atlas* atlas) {
|
|||||||
drawable->timeScale = 1;
|
drawable->timeScale = 1;
|
||||||
|
|
||||||
Skeleton* skeleton = drawable->skeleton;
|
Skeleton* skeleton = drawable->skeleton;
|
||||||
skeleton->setFlipX(false);
|
|
||||||
skeleton->setFlipY(false);
|
|
||||||
skeleton->setToSetupPose();
|
skeleton->setToSetupPose();
|
||||||
|
|
||||||
skeleton->setPosition(320, 590);
|
skeleton->setPosition(320, 590);
|
||||||
@ -168,8 +166,6 @@ void goblins (SkeletonData* skeletonData, Atlas* atlas) {
|
|||||||
drawable->timeScale = 1;
|
drawable->timeScale = 1;
|
||||||
|
|
||||||
Skeleton* skeleton = drawable->skeleton;
|
Skeleton* skeleton = drawable->skeleton;
|
||||||
skeleton->setFlipX(false);
|
|
||||||
skeleton->setFlipY(false);
|
|
||||||
skeleton->setSkin("goblin");
|
skeleton->setSkin("goblin");
|
||||||
skeleton->setSlotsToSetupPose();
|
skeleton->setSlotsToSetupPose();
|
||||||
|
|
||||||
@ -309,8 +305,6 @@ void stretchyman (SkeletonData* skeletonData, Atlas* atlas) {
|
|||||||
drawable->timeScale = 1;
|
drawable->timeScale = 1;
|
||||||
|
|
||||||
Skeleton* skeleton = drawable->skeleton;
|
Skeleton* skeleton = drawable->skeleton;
|
||||||
skeleton->setFlipX(false);
|
|
||||||
skeleton->setFlipY(false);
|
|
||||||
|
|
||||||
skeleton->setPosition(100, 590);
|
skeleton->setPosition(100, 590);
|
||||||
skeleton->updateWorldTransform();
|
skeleton->updateWorldTransform();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user