[cpp] Formatting

This commit is contained in:
Mario Zechner 2024-01-16 12:42:22 +01:00
parent 62080c6c8b
commit d03f535ed8
24 changed files with 682 additions and 687 deletions

View File

@ -96,6 +96,6 @@ void _spAttachmentLoader_setError(spAttachmentLoader *self, const char *error1,
void _spAttachmentLoader_setUnknownTypeError(spAttachmentLoader *self, spAttachmentType type) { void _spAttachmentLoader_setUnknownTypeError(spAttachmentLoader *self, spAttachmentType type) {
char buffer[16]; char buffer[16];
snprintf(buffer, 16,"%d", type); snprintf(buffer, 16, "%d", type);
_spAttachmentLoader_setError(self, "Unknown attachment type: ", buffer); _spAttachmentLoader_setError(self, "Unknown attachment type: ", buffer);
} }

View File

@ -262,30 +262,30 @@ void spBone_updateAppliedTransform(spBone *self) {
} }
case SP_TRANSFORMMODE_NOSCALE: case SP_TRANSFORMMODE_NOSCALE:
case SP_TRANSFORMMODE_NOSCALEORREFLECTION: { case SP_TRANSFORMMODE_NOSCALEORREFLECTION: {
cosine = COS_DEG(self->rotation), sine = SIN_DEG(self->rotation); cosine = COS_DEG(self->rotation), sine = SIN_DEG(self->rotation);
pa = (pa * cosine + pb * sine) / self->skeleton->scaleX; pa = (pa * cosine + pb * sine) / self->skeleton->scaleX;
pc = (pc * cosine + pd * sine) / self->skeleton->scaleY; pc = (pc * cosine + pd * sine) / self->skeleton->scaleY;
s = SQRT(pa * pa + pc * pc); s = SQRT(pa * pa + pc * pc);
if (s > 0.00001f) s = 1 / s; if (s > 0.00001f) s = 1 / s;
pa *= s; pa *= s;
pc *= s; pc *= s;
s = SQRT(pa * pa + pc * pc); s = SQRT(pa * pa + pc * pc);
if (self->data->transformMode == SP_TRANSFORMMODE_NOSCALE && if (self->data->transformMode == SP_TRANSFORMMODE_NOSCALE &&
pid < 0 != (self->skeleton->scaleX < 0 != self->skeleton->scaleY < 0)) pid < 0 != (self->skeleton->scaleX < 0 != self->skeleton->scaleY < 0))
s = -s; s = -s;
r = PI / 2 + ATAN2(pc, pa); r = PI / 2 + ATAN2(pc, pa);
pb = COS(r) * s; pb = COS(r) * s;
pd = SIN(r) * s; pd = SIN(r) * s;
pid = 1 / (pa * pd - pb * pc); pid = 1 / (pa * pd - pb * pc);
ia = pd * pid; ia = pd * pid;
ib = pb * pid; ib = pb * pid;
ic = pc * pid; ic = pc * pid;
id = pa * pid; id = pa * pid;
break; break;
} }
case SP_TRANSFORMMODE_ONLYTRANSLATION: case SP_TRANSFORMMODE_ONLYTRANSLATION:
case SP_TRANSFORMMODE_NORMAL: case SP_TRANSFORMMODE_NORMAL:
break; break;
} }
ra = ia * self->a - ib * self->c; ra = ia * self->a - ib * self->c;
rb = ia * self->b - ib * self->d; rb = ia * self->b - ib * self->d;

View File

@ -211,7 +211,7 @@ float TrackEntry::getTrackComplete() {
} }
bool TrackEntry::wasApplied() { bool TrackEntry::wasApplied() {
return _nextTrackLast != -1; return _nextTrackLast != -1;
} }
EventQueueEntry::EventQueueEntry(EventType eventType, TrackEntry *trackEntry, Event *event) : _type(eventType), EventQueueEntry::EventQueueEntry(EventType eventType, TrackEntry *trackEntry, Event *event) : _type(eventType),
@ -438,14 +438,14 @@ bool AnimationState::apply(Skeleton &skeleton) {
// apply mixing from entries first. // apply mixing from entries first.
float alpha = current._alpha; float alpha = current._alpha;
if (current._mixingFrom != NULL) { if (current._mixingFrom != NULL) {
alpha *= applyMixingFrom(currentP, skeleton, blend); alpha *= applyMixingFrom(currentP, skeleton, blend);
} else if (current._trackTime >= current._trackEnd && current._next == NULL) { } else if (current._trackTime >= current._trackEnd && current._next == NULL) {
alpha = 0;// Set to setup pose the last time the entry will be applied. alpha = 0;// Set to setup pose the last time the entry will be applied.
} }
bool attachments = alpha >= current._alphaAttachmentThreshold; bool attachments = alpha >= current._alphaAttachmentThreshold;
// apply current entry. // apply current entry.
float animationLast = current._animationLast, animationTime = current.getAnimationTime(); float animationLast = current._animationLast, animationTime = current.getAnimationTime();
float applyTime = animationTime; float applyTime = animationTime;
Vector<Event *> *applyEvents = &_events; Vector<Event *> *applyEvents = &_events;
@ -456,8 +456,8 @@ bool AnimationState::apply(Skeleton &skeleton) {
size_t timelineCount = current._animation->_timelines.size(); size_t timelineCount = current._animation->_timelines.size();
Vector<Timeline *> &timelines = current._animation->_timelines; Vector<Timeline *> &timelines = current._animation->_timelines;
if ((i == 0 && alpha == 1) || blend == MixBlend_Add) { if ((i == 0 && alpha == 1) || blend == MixBlend_Add) {
if (i == 0) attachments = true; if (i == 0) attachments = true;
for (size_t ii = 0; ii < timelineCount; ++ii) { for (size_t ii = 0; ii < timelineCount; ++ii) {
Timeline *timeline = timelines[ii]; Timeline *timeline = timelines[ii];
if (timeline->getRTTI().isExactly(AttachmentTimeline::rtti)) if (timeline->getRTTI().isExactly(AttachmentTimeline::rtti))
applyAttachmentTimeline(static_cast<AttachmentTimeline *>(timeline), skeleton, applyTime, blend, applyAttachmentTimeline(static_cast<AttachmentTimeline *>(timeline), skeleton, applyTime, blend,
@ -481,13 +481,13 @@ bool AnimationState::apply(Skeleton &skeleton) {
if (!shortestRotation && timeline->getRTTI().isExactly(RotateTimeline::rtti)) if (!shortestRotation && timeline->getRTTI().isExactly(RotateTimeline::rtti))
applyRotateTimeline(static_cast<RotateTimeline *>(timeline), skeleton, applyTime, alpha, applyRotateTimeline(static_cast<RotateTimeline *>(timeline), skeleton, applyTime, alpha,
timelineBlend, timelinesRotation, ii << 1, firstFrame); timelineBlend, timelinesRotation, ii << 1, firstFrame);
else if (timeline->getRTTI().isExactly(AttachmentTimeline::rtti)) else if (timeline->getRTTI().isExactly(AttachmentTimeline::rtti))
applyAttachmentTimeline(static_cast<AttachmentTimeline *>(timeline), skeleton, applyTime, applyAttachmentTimeline(static_cast<AttachmentTimeline *>(timeline), skeleton, applyTime,
timelineBlend, true); timelineBlend, true);
else else
timeline->apply(skeleton, animationLast, applyTime, applyEvents, alpha, timelineBlend, timeline->apply(skeleton, animationLast, applyTime, applyEvents, alpha, timelineBlend,
MixDirection_In); MixDirection_In);
} }
} }
@ -744,8 +744,8 @@ void AnimationState::applyRotateTimeline(RotateTimeline *rotateTimeline, Skeleto
// Mix between rotations using the direction of the shortest route on the first frame while detecting crosses. // Mix between rotations using the direction of the shortest route on the first frame while detecting crosses.
float total, diff = r2 - r1; float total, diff = r2 - r1;
diff -= MathUtil::ceil(diff / 360 - 0.5) * 360; diff -= MathUtil::ceil(diff / 360 - 0.5) * 360;
if (diff == 0) { if (diff == 0) {
total = timelinesRotation[i]; total = timelinesRotation[i];
} else { } else {
float lastTotal, lastDiff; float lastTotal, lastDiff;
@ -885,7 +885,7 @@ float AnimationState::applyMixingFrom(TrackEntry *to, Skeleton &skeleton, MixBle
timelinesRotation, i << 1, firstFrame); timelinesRotation, i << 1, firstFrame);
} else if (timeline->getRTTI().isExactly(AttachmentTimeline::rtti)) { } else if (timeline->getRTTI().isExactly(AttachmentTimeline::rtti)) {
applyAttachmentTimeline(static_cast<AttachmentTimeline *>(timeline), skeleton, applyTime, timelineBlend, applyAttachmentTimeline(static_cast<AttachmentTimeline *>(timeline), skeleton, applyTime, timelineBlend,
attachments && alpha >= from->_alphaAttachmentThreshold); attachments && alpha >= from->_alphaAttachmentThreshold);
} else { } else {
if (drawOrder && timeline->getRTTI().isExactly(DrawOrderTimeline::rtti) && if (drawOrder && timeline->getRTTI().isExactly(DrawOrderTimeline::rtti) &&
timelineBlend == MixBlend_Setup) timelineBlend == MixBlend_Setup)
@ -986,7 +986,7 @@ TrackEntry *AnimationState::newTrackEntry(size_t trackIndex, Animation *animatio
entry._eventThreshold = 0; entry._eventThreshold = 0;
entry._mixAttachmentThreshold = 0; entry._mixAttachmentThreshold = 0;
entry._alphaAttachmentThreshold = 0; entry._alphaAttachmentThreshold = 0;
entry._mixDrawOrderThreshold = 0; entry._mixDrawOrderThreshold = 0;
entry._animationStart = 0; entry._animationStart = 0;

View File

@ -96,15 +96,15 @@ void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX,
_ashearY = shearY; _ashearY = shearY;
if (!parent) { /* Root bone. */ if (!parent) { /* Root bone. */
Skeleton &skeleton = this->_skeleton; Skeleton &skeleton = this->_skeleton;
float sx = skeleton.getScaleX(); float sx = skeleton.getScaleX();
float sy = skeleton.getScaleY(); float sy = skeleton.getScaleY();
float rx = (rotation + shearX) * MathUtil::Deg_Rad; float rx = (rotation + shearX) * MathUtil::Deg_Rad;
float ry = (rotation + 90 + shearY) * MathUtil::Deg_Rad; float ry = (rotation + 90 + shearY) * MathUtil::Deg_Rad;
_a = MathUtil::cos(rx) * scaleX * sx; _a = MathUtil::cos(rx) * scaleX * sx;
_b = MathUtil::cos(ry) * scaleY * sx; _b = MathUtil::cos(ry) * scaleY * sx;
_c = MathUtil::sin(rx) * scaleX * sy; _c = MathUtil::sin(rx) * scaleX * sy;
_d = MathUtil::sin(ry) * scaleY * sy; _d = MathUtil::sin(ry) * scaleY * sy;
_worldX = x * sx + _skeleton.getX(); _worldX = x * sx + _skeleton.getX();
_worldY = y * sy + _skeleton.getY(); _worldY = y * sy + _skeleton.getY();
return; return;
@ -120,12 +120,12 @@ void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX,
switch (_data.getTransformMode()) { switch (_data.getTransformMode()) {
case TransformMode_Normal: { case TransformMode_Normal: {
float rx = (rotation + shearX) * MathUtil::Deg_Rad; float rx = (rotation + shearX) * MathUtil::Deg_Rad;
float ry = (rotation + 90 + shearY) * MathUtil::Deg_Rad; float ry = (rotation + 90 + shearY) * MathUtil::Deg_Rad;
float la = MathUtil::cos(rx) * scaleX; float la = MathUtil::cos(rx) * scaleX;
float lb = MathUtil::cos(ry) * scaleY; float lb = MathUtil::cos(ry) * scaleY;
float lc = MathUtil::sin(rx) * scaleX; float lc = MathUtil::sin(rx) * scaleX;
float ld = MathUtil::sin(ry) * scaleY; float ld = MathUtil::sin(ry) * scaleY;
_a = pa * la + pb * lc; _a = pa * la + pb * lc;
_b = pa * lb + pb * ld; _b = pa * lb + pb * ld;
_c = pc * la + pd * lc; _c = pc * la + pd * lc;
@ -133,12 +133,12 @@ void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX,
return; return;
} }
case TransformMode_OnlyTranslation: { case TransformMode_OnlyTranslation: {
float rx = (rotation + shearX) * MathUtil::Deg_Rad; float rx = (rotation + shearX) * MathUtil::Deg_Rad;
float ry = (rotation + 90 + shearY) * MathUtil::Deg_Rad; float ry = (rotation + 90 + shearY) * MathUtil::Deg_Rad;
_a = MathUtil::cos(rx) * scaleX; _a = MathUtil::cos(rx) * scaleX;
_b = MathUtil::cos(ry) * scaleY; _b = MathUtil::cos(ry) * scaleY;
_c = MathUtil::sin(rx) * scaleX; _c = MathUtil::sin(rx) * scaleX;
_d = MathUtil::sin(ry) * scaleY; _d = MathUtil::sin(ry) * scaleY;
break; break;
} }
case TransformMode_NoRotationOrReflection: { case TransformMode_NoRotationOrReflection: {
@ -156,12 +156,12 @@ void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX,
pc = 0; pc = 0;
prx = 90 - MathUtil::atan2(pd, pb) * MathUtil::Rad_Deg; prx = 90 - MathUtil::atan2(pd, pb) * MathUtil::Rad_Deg;
} }
float rx = (rotation + shearX - prx) * MathUtil::Deg_Rad; float rx = (rotation + shearX - prx) * MathUtil::Deg_Rad;
float ry = (rotation + shearY - prx + 90) * MathUtil::Deg_Rad; float ry = (rotation + shearY - prx + 90) * MathUtil::Deg_Rad;
float la = MathUtil::cos(rx) * scaleX; float la = MathUtil::cos(rx) * scaleX;
float lb = MathUtil::cos(ry) * scaleY; float lb = MathUtil::cos(ry) * scaleY;
float lc = MathUtil::sin(rx) * scaleX; float lc = MathUtil::sin(rx) * scaleX;
float ld = MathUtil::sin(ry) * scaleY; float ld = MathUtil::sin(ry) * scaleY;
_a = pa * la - pb * lc; _a = pa * la - pb * lc;
_b = pa * lb - pb * ld; _b = pa * lb - pb * ld;
_c = pc * la + pd * lc; _c = pc * la + pd * lc;
@ -170,9 +170,9 @@ void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX,
} }
case TransformMode_NoScale: case TransformMode_NoScale:
case TransformMode_NoScaleOrReflection: { case TransformMode_NoScaleOrReflection: {
rotation *= MathUtil::Deg_Rad; rotation *= MathUtil::Deg_Rad;
float cosine = MathUtil::cos(rotation); float cosine = MathUtil::cos(rotation);
float sine = MathUtil::sin(rotation); float sine = MathUtil::sin(rotation);
float za = (pa * cosine + pb * sine) / _skeleton.getScaleX(); float za = (pa * cosine + pb * sine) / _skeleton.getScaleX();
float zc = (pc * cosine + pd * sine) / _skeleton.getScaleY(); float zc = (pc * cosine + pd * sine) / _skeleton.getScaleY();
float s = MathUtil::sqrt(za * za + zc * zc); float s = MathUtil::sqrt(za * za + zc * zc);
@ -183,15 +183,15 @@ void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX,
if (_data.getTransformMode() == TransformMode_NoScale && if (_data.getTransformMode() == TransformMode_NoScale &&
(pa * pd - pb * pc < 0) != (_skeleton.getScaleX() < 0 != _skeleton.getScaleY() < 0)) (pa * pd - pb * pc < 0) != (_skeleton.getScaleX() < 0 != _skeleton.getScaleY() < 0))
s = -s; s = -s;
rotation = MathUtil::Pi / 2 + MathUtil::atan2(zc, za); rotation = MathUtil::Pi / 2 + MathUtil::atan2(zc, za);
float zb = MathUtil::cos(rotation) * s; float zb = MathUtil::cos(rotation) * s;
float zd = MathUtil::sin(rotation) * s; float zd = MathUtil::sin(rotation) * s;
shearX *= MathUtil::Deg_Rad; shearX *= MathUtil::Deg_Rad;
shearY = (90 + shearY) * MathUtil::Deg_Rad; shearY = (90 + shearY) * MathUtil::Deg_Rad;
float la = MathUtil::cos(shearX) * scaleX; float la = MathUtil::cos(shearX) * scaleX;
float lb = MathUtil::cos(shearY) * scaleY; float lb = MathUtil::cos(shearY) * scaleY;
float lc = MathUtil::sin(shearX) * scaleX; float lc = MathUtil::sin(shearX) * scaleX;
float ld = MathUtil::sin(shearY) * scaleY; float ld = MathUtil::sin(shearY) * scaleY;
_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;
@ -251,13 +251,13 @@ float Bone::localToWorldRotation(float localRotation) {
} }
void Bone::rotateWorld(float degrees) { void Bone::rotateWorld(float degrees) {
degrees *= MathUtil::Deg_Rad; degrees *= MathUtil::Deg_Rad;
float sine = MathUtil::sin(degrees), cosine = MathUtil::cos(degrees); float sine = MathUtil::sin(degrees), cosine = MathUtil::cos(degrees);
float ra = _a, rb = _b; float ra = _a, rb = _b;
_a = cosine * ra - sine * _c; _a = cosine * ra - sine * _c;
_b = cosine * rb - sine * _d; _b = cosine * rb - sine * _d;
_c = sine * ra + cosine * _c; _c = sine * ra + cosine * _c;
_d = sine * rb + cosine * _d; _d = sine * rb + cosine * _d;
} }
float Bone::getWorldToLocalRotationX() { float Bone::getWorldToLocalRotationX() {
@ -497,70 +497,70 @@ void Bone::updateAppliedTransform() {
} }
float pa = parent->_a, pb = parent->_b, pc = parent->_c, pd = parent->_d; float pa = parent->_a, pb = parent->_b, pc = parent->_c, pd = parent->_d;
float pid = 1 / (pa * pd - pb * pc); float pid = 1 / (pa * pd - pb * pc);
float ia = pd * pid, ib = pb * pid, ic = pc * pid, id = pa * pid; float ia = pd * pid, ib = pb * pid, ic = pc * pid, id = pa * pid;
float dx = _worldX - parent->_worldX, dy = _worldY - parent->_worldY; float dx = _worldX - parent->_worldX, dy = _worldY - parent->_worldY;
_ax = (dx * ia - dy * ib); _ax = (dx * ia - dy * ib);
_ay = (dy * id - dx * ic); _ay = (dy * id - dx * ic);
float ra, rb, rc, rd; float ra, rb, rc, rd;
if (_data.getTransformMode() == TransformMode_OnlyTranslation) { if (_data.getTransformMode() == TransformMode_OnlyTranslation) {
ra = _a; ra = _a;
rb = _b; rb = _b;
rc = _c; rc = _c;
rd = _d; rd = _d;
} else { } else {
switch (_data.getTransformMode()) { switch (_data.getTransformMode()) {
case TransformMode_NoRotationOrReflection: { case TransformMode_NoRotationOrReflection: {
float s = MathUtil::abs(pa * pd - pb * pc) / (pa * pa + pc * pc); float s = MathUtil::abs(pa * pd - pb * pc) / (pa * pa + pc * pc);
float sa = pa / _skeleton.getScaleX(); float sa = pa / _skeleton.getScaleX();
float sc = pc / _skeleton.getScaleY(); float sc = pc / _skeleton.getScaleY();
pb = -sc * s * _skeleton.getScaleX(); pb = -sc * s * _skeleton.getScaleX();
pd = sa * s * _skeleton.getScaleY(); pd = sa * s * _skeleton.getScaleY();
pid = 1 / (pa * pd - pb * pc); pid = 1 / (pa * pd - pb * pc);
ia = pd * pid; ia = pd * pid;
ib = pb * pid; ib = pb * pid;
break; break;
} }
case TransformMode_NoScale: case TransformMode_NoScale:
case TransformMode_NoScaleOrReflection: { case TransformMode_NoScaleOrReflection: {
float cos = MathUtil::cosDeg(_rotation), sin = MathUtil::sinDeg(_rotation); float cos = MathUtil::cosDeg(_rotation), sin = MathUtil::sinDeg(_rotation);
pa = (pa * cos + pb * sin) / _skeleton.getScaleX(); pa = (pa * cos + pb * sin) / _skeleton.getScaleX();
pc = (pc * cos + pd * sin) / _skeleton.getScaleY(); pc = (pc * cos + pd * sin) / _skeleton.getScaleY();
float s = MathUtil::sqrt(pa * pa + pc * pc); float s = MathUtil::sqrt(pa * pa + pc * pc);
if (s > 0.00001) s = 1 / s; if (s > 0.00001) s = 1 / s;
pa *= s; pa *= s;
pc *= s; pc *= s;
s = MathUtil::sqrt(pa * pa + pc * pc); s = MathUtil::sqrt(pa * pa + pc * pc);
if (_data.getTransformMode() == TransformMode_NoScale && if (_data.getTransformMode() == TransformMode_NoScale &&
pid < 0 != (_skeleton.getScaleX() < 0 != _skeleton.getScaleY() < 0)) pid < 0 != (_skeleton.getScaleX() < 0 != _skeleton.getScaleY() < 0))
s = -s; s = -s;
float r = MathUtil::Pi / 2 + MathUtil::atan2(pc, pa); float r = MathUtil::Pi / 2 + MathUtil::atan2(pc, pa);
pb = MathUtil::cos(r) * s; pb = MathUtil::cos(r) * s;
pd = MathUtil::sin(r) * s; pd = MathUtil::sin(r) * s;
pid = 1 / (pa * pd - pb * pc); pid = 1 / (pa * pd - pb * pc);
ia = pd * pid; ia = pd * pid;
ib = pb * pid; ib = pb * pid;
ic = pc * pid; ic = pc * pid;
id = pa * pid; id = pa * pid;
break; break;
} }
case TransformMode_Normal: case TransformMode_Normal:
case TransformMode_OnlyTranslation: case TransformMode_OnlyTranslation:
break; break;
} }
ra = ia * _a - ib * _c; ra = ia * _a - ib * _c;
rb = ia * _b - ib * _d; rb = ia * _b - ib * _d;
rc = id * _c - ic * _a; rc = id * _c - ic * _a;
rd = id * _d - ic * _b; rd = id * _d - ic * _b;
} }
_ashearX = 0; _ashearX = 0;
_ascaleX = MathUtil::sqrt(ra * ra + rc * rc); _ascaleX = MathUtil::sqrt(ra * ra + rc * rc);
if (_ascaleX > 0.0001f) { if (_ascaleX > 0.0001f) {
float det = ra * rd - rb * rc; float det = ra * rd - rb * rc;
_ascaleY = det / _ascaleX; _ascaleY = det / _ascaleX;
_ashearY = -MathUtil::atan2(ra * rb + rc * rd, det) * MathUtil::Rad_Deg; _ashearY = -MathUtil::atan2(ra * rb + rc * rd, det) * MathUtil::Rad_Deg;
_arotation = MathUtil::atan2(rc, ra) * MathUtil::Rad_Deg; _arotation = MathUtil::atan2(rc, ra) * MathUtil::Rad_Deg;
} else { } else {
_ascaleX = 0; _ascaleX = 0;
_ascaleY = MathUtil::sqrt(rb * rb + rd * rd); _ascaleY = MathUtil::sqrt(rb * rb + rd * rd);

View File

@ -47,8 +47,8 @@ BoneData::BoneData(int index, const String &name, BoneData *parent) : _index(ind
_transformMode(TransformMode_Normal), _transformMode(TransformMode_Normal),
_skinRequired(false), _skinRequired(false),
_color(), _color(),
_icon(), _icon(),
_visible(true){ _visible(true) {
assert(index >= 0); assert(index >= 0);
assert(_name.length() > 0); assert(_name.length() > 0);
} }
@ -150,18 +150,17 @@ Color &BoneData::getColor() {
} }
const String &BoneData::getIcon() { const String &BoneData::getIcon() {
return _icon; return _icon;
} }
void BoneData::setIcon(const String &icon) { void BoneData::setIcon(const String &icon) {
this->_icon = icon; this->_icon = icon;
} }
bool BoneData::isVisible() { bool BoneData::isVisible() {
return _visible; return _visible;
} }
void BoneData::setVisible(bool inValue) { void BoneData::setVisible(bool inValue) {
this->_visible = inValue; this->_visible = inValue;
} }

View File

@ -133,105 +133,104 @@ float CurveTimeline1::getCurveValue(float time) {
} }
float CurveTimeline1::getRelativeValue(float time, float alpha, MixBlend blend, float current, float setup) { float CurveTimeline1::getRelativeValue(float time, float alpha, MixBlend blend, float current, float setup) {
if (time < _frames[0]) { if (time < _frames[0]) {
switch (blend) { switch (blend) {
case MixBlend_Setup: case MixBlend_Setup:
return setup; return setup;
case MixBlend_First: case MixBlend_First:
return current + (setup - current) * alpha; return current + (setup - current) * alpha;
default: default:
return current; return current;
} }
} }
float value = getCurveValue(time); float value = getCurveValue(time);
switch (blend) { switch (blend) {
case MixBlend_Setup: case MixBlend_Setup:
return setup + value * alpha; return setup + value * alpha;
case MixBlend_First: case MixBlend_First:
case MixBlend_Replace: case MixBlend_Replace:
value += setup - current; value += setup - current;
break; break;
case MixBlend_Add: case MixBlend_Add:
break; break;
} }
return current + value * alpha; return current + value * alpha;
} }
float CurveTimeline1::getAbsoluteValue(float time, float alpha, MixBlend blend, float current, float setup) { float CurveTimeline1::getAbsoluteValue(float time, float alpha, MixBlend blend, float current, float setup) {
if (time < _frames[0]) { if (time < _frames[0]) {
switch (blend) { switch (blend) {
case MixBlend_Setup: case MixBlend_Setup:
return setup; return setup;
case MixBlend_First: case MixBlend_First:
return current + (setup - current) * alpha; return current + (setup - current) * alpha;
default: default:
return current; return current;
} }
} }
float value = getCurveValue(time); float value = getCurveValue(time);
if (blend == MixBlend_Setup) return setup + (value - setup) * alpha; if (blend == MixBlend_Setup) return setup + (value - setup) * alpha;
return current + (value - current) * alpha; return current + (value - current) * alpha;
} }
float CurveTimeline1::getAbsoluteValue(float time, float alpha, MixBlend blend, float current, float setup, float value) { float CurveTimeline1::getAbsoluteValue(float time, float alpha, MixBlend blend, float current, float setup, float value) {
if (time < _frames[0]) { if (time < _frames[0]) {
switch (blend) { switch (blend) {
case MixBlend_Setup: case MixBlend_Setup:
return setup; return setup;
case MixBlend_First: case MixBlend_First:
return current + (setup - current) * alpha; return current + (setup - current) * alpha;
default: default:
return current; return current;
} }
} }
if (blend == MixBlend_Setup) return setup + (value - setup) * alpha; if (blend == MixBlend_Setup) return setup + (value - setup) * alpha;
return current + (value - current) * alpha; return current + (value - current) * alpha;
} }
float CurveTimeline1::getScaleValue(float time, float alpha, MixBlend blend, MixDirection direction, float current, float CurveTimeline1::getScaleValue(float time, float alpha, MixBlend blend, MixDirection direction, float current,
float setup) { float setup) {
if (time < _frames[0]) { if (time < _frames[0]) {
switch (blend) { switch (blend) {
case MixBlend_Setup: case MixBlend_Setup:
return setup; return setup;
case MixBlend_First: case MixBlend_First:
return current + (setup - current) * alpha; return current + (setup - current) * alpha;
default: default:
return current; return current;
} }
} }
float value = getCurveValue(time) * setup; float value = getCurveValue(time) * setup;
if (alpha == 1) { if (alpha == 1) {
if (blend == MixBlend_Add) return current + value - setup; if (blend == MixBlend_Add) return current + value - setup;
return value; return value;
} }
// Mixing out uses sign of setup or current pose, else use sign of key. // Mixing out uses sign of setup or current pose, else use sign of key.
if (direction == MixDirection_Out) { if (direction == MixDirection_Out) {
switch (blend) { switch (blend) {
case MixBlend_Setup: case MixBlend_Setup:
return setup + (MathUtil::abs(value) * MathUtil::sign(setup) - setup) * alpha; return setup + (MathUtil::abs(value) * MathUtil::sign(setup) - setup) * alpha;
case MixBlend_First: case MixBlend_First:
case MixBlend_Replace: case MixBlend_Replace:
return current + (MathUtil::abs(value) * MathUtil::sign(current) - current) * alpha; return current + (MathUtil::abs(value) * MathUtil::sign(current) - current) * alpha;
default: default:
break; break;
} }
} else { } else {
float s; float s;
switch (blend) { switch (blend) {
case MixBlend_Setup: case MixBlend_Setup:
s = MathUtil::abs(setup) * MathUtil::sign(value); s = MathUtil::abs(setup) * MathUtil::sign(value);
return s + (value - s) * alpha; return s + (value - s) * alpha;
case MixBlend_First: case MixBlend_First:
case MixBlend_Replace: case MixBlend_Replace:
s = MathUtil::abs(current) * MathUtil::sign(value); s = MathUtil::abs(current) * MathUtil::sign(value);
return s + (value - s) * alpha; return s + (value - s) * alpha;
default: default:
break; break;
} }
} }
return current + (value - setup) * alpha; return current + (value - setup) * alpha;
} }

View File

@ -85,15 +85,15 @@ void IkConstraint::apply(Bone &bone, float targetX, float targetY, bool compress
default:; default:;
} }
float b = bone._data.getLength() * sx; float b = bone._data.getLength() * sx;
if (b > 0.0001) { if (b > 0.0001) {
float dd = tx * tx + ty * ty; float dd = tx * tx + ty * ty;
if ((compress && dd < b * b) || (stretch && dd > b * b)) { if ((compress && dd < b * b) || (stretch && dd > b * b)) {
float s = (MathUtil::sqrt(dd) / b - 1) * alpha + 1; float s = (MathUtil::sqrt(dd) / b - 1) * alpha + 1;
sx *= s; sx *= s;
if (uniform) sy *= s; if (uniform) sy *= s;
} }
} }
} }
bone.updateWorldTransform(bone._ax, bone._ay, bone._arotation + rotationIK * alpha, sx, sy, bone._ashearX, bone.updateWorldTransform(bone._ax, bone._ay, bone._arotation + rotationIK * alpha, sx, sy, bone._ashearX,
bone._ashearY); bone._ashearY);
@ -369,10 +369,10 @@ void IkConstraint::setSoftness(float inValue) {
} }
void IkConstraint::setToSetupPose() { void IkConstraint::setToSetupPose() {
IkConstraintData &data = this->_data; IkConstraintData &data = this->_data;
this->_mix = data._mix; this->_mix = data._mix;
this->_softness = data._softness; this->_softness = data._softness;
this->_bendDirection = data._bendDirection; this->_bendDirection = data._bendDirection;
this->_compress = data._compress; this->_compress = data._compress;
this->_stretch = data._stretch; this->_stretch = data._stretch;
} }

View File

@ -68,7 +68,7 @@ float MathUtil::atan2(float y, float x) {
} }
float MathUtil::atan2Deg(float x, float y) { float MathUtil::atan2Deg(float x, float y) {
return MathUtil::atan2(x, y) * MathUtil::Deg_Rad; return MathUtil::atan2(x, y) * MathUtil::Deg_Rad;
} }
/// Returns the cosine in radians from a lookup table. /// Returns the cosine in radians from a lookup table.
@ -129,5 +129,5 @@ float MathUtil::pow(float a, float b) {
} }
float MathUtil::ceil(float v) { float MathUtil::ceil(float v) {
return ::ceil(v); return ::ceil(v);
} }

View File

@ -91,11 +91,10 @@ void PathConstraint::update(Physics) {
Bone *boneP = _bones[i]; Bone *boneP = _bones[i];
Bone &bone = *boneP; Bone &bone = *boneP;
float setupLength = bone._data.getLength(); float setupLength = bone._data.getLength();
float x = setupLength * bone._a; float x = setupLength * bone._a;
float y = setupLength * bone._c; float y = setupLength * bone._c;
_lengths[i] = MathUtil::sqrt(x * x + y * y); _lengths[i] = MathUtil::sqrt(x * x + y * y);
}
}
} }
for (size_t i = 1; i < spacesCount; ++i) { for (size_t i = 1; i < spacesCount; ++i) {
_spaces[i] = spacing; _spaces[i] = spacing;
@ -580,10 +579,10 @@ void PathConstraint::setActive(bool inValue) {
} }
void PathConstraint::setToSetupPose() { void PathConstraint::setToSetupPose() {
PathConstraintData &data = this->_data; PathConstraintData &data = this->_data;
this->_position = data._position; this->_position = data._position;
this->_spacing = data._spacing; this->_spacing = data._spacing;
this->_mixRotate = data._mixRotate; this->_mixRotate = data._mixRotate;
this->_mixX = data._mixX; this->_mixX = data._mixX;
this->_mixY = data._mixY; this->_mixY = data._mixY;
} }

View File

@ -45,7 +45,7 @@ RTTI_IMPL(PathConstraintMixTimeline, CurveTimeline)
PathConstraintMixTimeline::PathConstraintMixTimeline(size_t frameCount, size_t bezierCount, int pathConstraintIndex) PathConstraintMixTimeline::PathConstraintMixTimeline(size_t frameCount, size_t bezierCount, int pathConstraintIndex)
: CurveTimeline(frameCount, PathConstraintMixTimeline::ENTRIES, bezierCount), : CurveTimeline(frameCount, PathConstraintMixTimeline::ENTRIES, bezierCount),
_constraintIndex(pathConstraintIndex) { _constraintIndex(pathConstraintIndex) {
PropertyId ids[] = {((PropertyId) Property_PathConstraintMix << 32) | pathConstraintIndex}; PropertyId ids[] = {((PropertyId) Property_PathConstraintMix << 32) | pathConstraintIndex};
setPropertyIds(ids, 1); setPropertyIds(ids, 1);
} }

View File

@ -46,7 +46,7 @@ RTTI_IMPL(PathConstraintPositionTimeline, CurveTimeline1)
PathConstraintPositionTimeline::PathConstraintPositionTimeline(size_t frameCount, size_t bezierCount, PathConstraintPositionTimeline::PathConstraintPositionTimeline(size_t frameCount, size_t bezierCount,
int pathConstraintIndex) : CurveTimeline1(frameCount, int pathConstraintIndex) : CurveTimeline1(frameCount,
bezierCount), bezierCount),
_constraintIndex( _constraintIndex(
pathConstraintIndex) { pathConstraintIndex) {
PropertyId ids[] = {((PropertyId) Property_PathConstraintPosition << 32) | pathConstraintIndex}; PropertyId ids[] = {((PropertyId) Property_PathConstraintPosition << 32) | pathConstraintIndex};
setPropertyIds(ids, 1); setPropertyIds(ids, 1);
@ -62,5 +62,5 @@ void PathConstraintPositionTimeline::apply(Skeleton &skeleton, float lastTime, f
SP_UNUSED(direction); SP_UNUSED(direction);
PathConstraint *constraint = skeleton._pathConstraints[_constraintIndex]; PathConstraint *constraint = skeleton._pathConstraints[_constraintIndex];
if (constraint->_active) constraint->_position = getAbsoluteValue(time, alpha, blend, constraint->_position, constraint->_data._position); if (constraint->_active) constraint->_position = getAbsoluteValue(time, alpha, blend, constraint->_position, constraint->_data._position);
} }

View File

@ -59,6 +59,6 @@ void PathConstraintSpacingTimeline::apply(Skeleton &skeleton, float lastTime, fl
SP_UNUSED(direction); SP_UNUSED(direction);
PathConstraint *constraint = skeleton._pathConstraints[_pathConstraintIndex]; PathConstraint *constraint = skeleton._pathConstraints[_pathConstraintIndex];
if (constraint->_active) if (constraint->_active)
constraint->_spacing = getAbsoluteValue(time, alpha, blend, constraint->_spacing, constraint->_data._spacing); constraint->_spacing = getAbsoluteValue(time, alpha, blend, constraint->_spacing, constraint->_data._spacing);
} }

View File

@ -38,429 +38,429 @@ using namespace spine;
RTTI_IMPL(PhysicsConstraint, Updatable) RTTI_IMPL(PhysicsConstraint, Updatable)
PhysicsConstraint::PhysicsConstraint(PhysicsConstraintData& data, Skeleton& skeleton) PhysicsConstraint::PhysicsConstraint(PhysicsConstraintData &data, Skeleton &skeleton)
: _data(data), _skeleton(skeleton) { : _data(data), _skeleton(skeleton) {
_bone = skeleton.getBones()[data.getBone()->getIndex()]; _bone = skeleton.getBones()[data.getBone()->getIndex()];
_inertia = data.getInertia(); _inertia = data.getInertia();
_strength = data.getStrength(); _strength = data.getStrength();
_damping = data.getDamping(); _damping = data.getDamping();
_massInverse = data.getMassInverse(); _massInverse = data.getMassInverse();
_wind = data.getWind(); _wind = data.getWind();
_gravity = data.getGravity(); _gravity = data.getGravity();
_mix = data.getMix(); _mix = data.getMix();
_reset = true; _reset = true;
_ux = 0; _ux = 0;
_uy = 0; _uy = 0;
_cx = 0; _cx = 0;
_cy = 0; _cy = 0;
_tx = 0; _tx = 0;
_ty = 0; _ty = 0;
_xOffset = 0; _xOffset = 0;
_xVelocity = 0; _xVelocity = 0;
_yOffset = 0; _yOffset = 0;
_yVelocity = 0; _yVelocity = 0;
_rotateOffset = 0; _rotateOffset = 0;
_rotateVelocity = 0; _rotateVelocity = 0;
_scaleOffset = 0; _scaleOffset = 0;
_scaleVelocity = 0; _scaleVelocity = 0;
_active = false; _active = false;
_remaining = 0; _remaining = 0;
_lastTime = 0; _lastTime = 0;
} }
PhysicsConstraintData &PhysicsConstraint::getData() { PhysicsConstraintData &PhysicsConstraint::getData() {
return _data; return _data;
} }
void PhysicsConstraint::setBone(Bone* bone) { void PhysicsConstraint::setBone(Bone *bone) {
_bone = bone; _bone = bone;
} }
Bone* PhysicsConstraint::getBone(){ Bone *PhysicsConstraint::getBone() {
return _bone; return _bone;
} }
void PhysicsConstraint::setInertia(float value) { void PhysicsConstraint::setInertia(float value) {
_inertia = value; _inertia = value;
} }
float PhysicsConstraint::getInertia(){ float PhysicsConstraint::getInertia() {
return _inertia; return _inertia;
} }
void PhysicsConstraint::setStrength(float value) { void PhysicsConstraint::setStrength(float value) {
_strength = value; _strength = value;
} }
float PhysicsConstraint::getStrength(){ float PhysicsConstraint::getStrength() {
return _strength; return _strength;
} }
void PhysicsConstraint::setDamping(float value) { void PhysicsConstraint::setDamping(float value) {
_damping = value; _damping = value;
} }
float PhysicsConstraint::getDamping(){ float PhysicsConstraint::getDamping() {
return _damping; return _damping;
} }
void PhysicsConstraint::setMassInverse(float value) { void PhysicsConstraint::setMassInverse(float value) {
_massInverse = value; _massInverse = value;
} }
float PhysicsConstraint::getMassInverse(){ float PhysicsConstraint::getMassInverse() {
return _massInverse; return _massInverse;
} }
void PhysicsConstraint::setWind(float value) { void PhysicsConstraint::setWind(float value) {
_wind = value; _wind = value;
} }
float PhysicsConstraint::getWind(){ float PhysicsConstraint::getWind() {
return _wind; return _wind;
} }
void PhysicsConstraint::setGravity(float value) { void PhysicsConstraint::setGravity(float value) {
_gravity = value; _gravity = value;
} }
float PhysicsConstraint::getGravity(){ float PhysicsConstraint::getGravity() {
return _gravity; return _gravity;
} }
void PhysicsConstraint::setMix(float value) { void PhysicsConstraint::setMix(float value) {
_mix = value; _mix = value;
} }
float PhysicsConstraint::getMix(){ float PhysicsConstraint::getMix() {
return _mix; return _mix;
} }
void PhysicsConstraint::setReset(bool value) { void PhysicsConstraint::setReset(bool value) {
_reset = value; _reset = value;
} }
bool PhysicsConstraint::getReset(){ bool PhysicsConstraint::getReset() {
return _reset; return _reset;
} }
void PhysicsConstraint::setUx(float value) { void PhysicsConstraint::setUx(float value) {
_ux = value; _ux = value;
} }
float PhysicsConstraint::getUx(){ float PhysicsConstraint::getUx() {
return _ux; return _ux;
} }
void PhysicsConstraint::setUy(float value) { void PhysicsConstraint::setUy(float value) {
_uy = value; _uy = value;
} }
float PhysicsConstraint::getUy(){ float PhysicsConstraint::getUy() {
return _uy; return _uy;
} }
void PhysicsConstraint::setCx(float value) { void PhysicsConstraint::setCx(float value) {
_cx = value; _cx = value;
} }
float PhysicsConstraint::getCx(){ float PhysicsConstraint::getCx() {
return _cx; return _cx;
} }
void PhysicsConstraint::setCy(float value) { void PhysicsConstraint::setCy(float value) {
_cy = value; _cy = value;
} }
float PhysicsConstraint::getCy(){ float PhysicsConstraint::getCy() {
return _cy; return _cy;
} }
void PhysicsConstraint::setTx(float value) { void PhysicsConstraint::setTx(float value) {
_tx = value; _tx = value;
} }
float PhysicsConstraint::getTx(){ float PhysicsConstraint::getTx() {
return _tx; return _tx;
} }
void PhysicsConstraint::setTy(float value) { void PhysicsConstraint::setTy(float value) {
_ty = value; _ty = value;
} }
float PhysicsConstraint::getTy(){ float PhysicsConstraint::getTy() {
return _ty; return _ty;
} }
void PhysicsConstraint::setXOffset(float value) { void PhysicsConstraint::setXOffset(float value) {
_xOffset = value; _xOffset = value;
} }
float PhysicsConstraint::getXOffset(){ float PhysicsConstraint::getXOffset() {
return _xOffset; return _xOffset;
} }
void PhysicsConstraint::setXVelocity(float value) { void PhysicsConstraint::setXVelocity(float value) {
_xVelocity = value; _xVelocity = value;
} }
float PhysicsConstraint::getXVelocity(){ float PhysicsConstraint::getXVelocity() {
return _xVelocity; return _xVelocity;
} }
void PhysicsConstraint::setYOffset(float value) { void PhysicsConstraint::setYOffset(float value) {
_yOffset = value; _yOffset = value;
} }
float PhysicsConstraint::getYOffset(){ float PhysicsConstraint::getYOffset() {
return _yOffset; return _yOffset;
} }
void PhysicsConstraint::setYVelocity(float value) { void PhysicsConstraint::setYVelocity(float value) {
_yVelocity = value; _yVelocity = value;
} }
float PhysicsConstraint::getYVelocity(){ float PhysicsConstraint::getYVelocity() {
return _yVelocity; return _yVelocity;
} }
void PhysicsConstraint::setRotateOffset(float value) { void PhysicsConstraint::setRotateOffset(float value) {
_rotateOffset = value; _rotateOffset = value;
} }
float PhysicsConstraint::getRotateOffset(){ float PhysicsConstraint::getRotateOffset() {
return _rotateOffset; return _rotateOffset;
} }
void PhysicsConstraint::setRotateVelocity(float value) { void PhysicsConstraint::setRotateVelocity(float value) {
_rotateVelocity = value; _rotateVelocity = value;
} }
float PhysicsConstraint::getRotateVelocity(){ float PhysicsConstraint::getRotateVelocity() {
return _rotateVelocity; return _rotateVelocity;
} }
void PhysicsConstraint::setScaleOffset(float value) { void PhysicsConstraint::setScaleOffset(float value) {
_scaleOffset = value; _scaleOffset = value;
} }
float PhysicsConstraint::getScaleOffset(){ float PhysicsConstraint::getScaleOffset() {
return _scaleOffset; return _scaleOffset;
} }
void PhysicsConstraint::setScaleVelocity(float value) { void PhysicsConstraint::setScaleVelocity(float value) {
_scaleVelocity = value; _scaleVelocity = value;
} }
float PhysicsConstraint::getScaleVelocity(){ float PhysicsConstraint::getScaleVelocity() {
return _scaleVelocity; return _scaleVelocity;
} }
void PhysicsConstraint::setActive(bool value) { void PhysicsConstraint::setActive(bool value) {
_active = value; _active = value;
} }
bool PhysicsConstraint::isActive(){ bool PhysicsConstraint::isActive() {
return _active; return _active;
} }
void PhysicsConstraint::setRemaining(float value) { void PhysicsConstraint::setRemaining(float value) {
_remaining = value; _remaining = value;
} }
float PhysicsConstraint::getRemaining(){ float PhysicsConstraint::getRemaining() {
return _remaining; return _remaining;
} }
void PhysicsConstraint::setLastTime(float value) { void PhysicsConstraint::setLastTime(float value) {
_lastTime = value; _lastTime = value;
} }
float PhysicsConstraint::getLastTime(){ float PhysicsConstraint::getLastTime() {
return _lastTime; return _lastTime;
} }
void PhysicsConstraint::reset() { void PhysicsConstraint::reset() {
_remaining = 0; _remaining = 0;
_lastTime = _skeleton.getTime(); _lastTime = _skeleton.getTime();
_reset = true; _reset = true;
_xOffset = 0; _xOffset = 0;
_xVelocity = 0; _xVelocity = 0;
_yOffset = 0; _yOffset = 0;
_yVelocity = 0; _yVelocity = 0;
_rotateOffset = 0; _rotateOffset = 0;
_rotateVelocity = 0; _rotateVelocity = 0;
_scaleOffset = 0; _scaleOffset = 0;
_scaleVelocity = 0; _scaleVelocity = 0;
} }
void PhysicsConstraint::setToSetupPose() { void PhysicsConstraint::setToSetupPose() {
_inertia = _data.getInertia(); _inertia = _data.getInertia();
_strength = _data.getStrength(); _strength = _data.getStrength();
_damping = _data.getDamping(); _damping = _data.getDamping();
_massInverse = _data.getMassInverse(); _massInverse = _data.getMassInverse();
_wind = _data.getWind(); _wind = _data.getWind();
_gravity = _data.getGravity(); _gravity = _data.getGravity();
_mix = _data.getMix(); _mix = _data.getMix();
} }
void PhysicsConstraint::update(Physics physics) { void PhysicsConstraint::update(Physics physics) {
float mix = _mix; float mix = _mix;
if (mix == 0) return; if (mix == 0) return;
bool x = _data._x > 0; bool x = _data._x > 0;
bool y = _data._y > 0; bool y = _data._y > 0;
bool rotateOrShearX = _data._rotate > 0 || _data._shearX > 0; bool rotateOrShearX = _data._rotate > 0 || _data._shearX > 0;
bool scaleX = _data._scaleX > 0; bool scaleX = _data._scaleX > 0;
Bone* bone = _bone; Bone *bone = _bone;
float l = bone->_data.getLength(); float l = bone->_data.getLength();
switch (physics) { switch (physics) {
case Physics::Physics_None: case Physics::Physics_None:
return; return;
case Physics::Physics_Reset: case Physics::Physics_Reset:
reset(); reset();
// Fall through. // Fall through.
case Physics::Physics_Update: { case Physics::Physics_Update: {
_remaining += MathUtil::max(_skeleton.getTime() - _lastTime, 0.0f); _remaining += MathUtil::max(_skeleton.getTime() - _lastTime, 0.0f);
_lastTime = _skeleton.getTime(); _lastTime = _skeleton.getTime();
float bx = bone->_worldX, by = bone->_worldY; float bx = bone->_worldX, by = bone->_worldY;
if (_reset) { if (_reset) {
_reset = false; _reset = false;
_ux = bx; _ux = bx;
_uy = by; _uy = by;
} else { } else {
float remaining = _remaining, i = _inertia, step = _data._step; float remaining = _remaining, i = _inertia, step = _data._step;
if (x || y) { if (x || y) {
if (x) { if (x) {
_xOffset += (_ux - bx) * i; _xOffset += (_ux - bx) * i;
_ux = bx; _ux = bx;
} }
if (y) { if (y) {
_yOffset += (_uy - by) * i; _yOffset += (_uy - by) * i;
_uy = by; _uy = by;
} }
if (remaining >= step) { if (remaining >= step) {
float m = _massInverse * step, e = _strength, w = _wind * 100, g = _gravity * -100; float m = _massInverse * step, e = _strength, w = _wind * 100, g = _gravity * -100;
float d = MathUtil::pow(_damping, 60 * step); float d = MathUtil::pow(_damping, 60 * step);
do { do {
if (x) { if (x) {
_xVelocity += (w - _xOffset * e) * m; _xVelocity += (w - _xOffset * e) * m;
_xOffset += _xVelocity * step; _xOffset += _xVelocity * step;
_xVelocity *= d; _xVelocity *= d;
} }
if (y) { if (y) {
_yVelocity += (g - _yOffset * e) * m; _yVelocity += (g - _yOffset * e) * m;
_yOffset += _yVelocity * step; _yOffset += _yVelocity * step;
_yVelocity *= d; _yVelocity *= d;
} }
remaining -= step; remaining -= step;
} while (remaining >= step); } while (remaining >= step);
} }
if (x) bone->_worldX += _xOffset * mix * _data._x; if (x) bone->_worldX += _xOffset * mix * _data._x;
if (y) bone->_worldY += _yOffset * mix * _data._y; if (y) bone->_worldY += _yOffset * mix * _data._y;
} }
if (rotateOrShearX || scaleX) { if (rotateOrShearX || scaleX) {
float ca = MathUtil::atan2(bone->_c, bone->_a), c = 0, s = 0, mr = 0; float ca = MathUtil::atan2(bone->_c, bone->_a), c = 0, s = 0, mr = 0;
if (rotateOrShearX) { if (rotateOrShearX) {
mr = (_data._rotate + _data._shearX) * mix; mr = (_data._rotate + _data._shearX) * mix;
float dx = _cx - bone->_worldX, dy = _cy - bone->_worldY; float dx = _cx - bone->_worldX, dy = _cy - bone->_worldY;
float r = MathUtil::atan2(dy + _ty, dx + _tx) - ca - _rotateOffset * mr; float r = MathUtil::atan2(dy + _ty, dx + _tx) - ca - _rotateOffset * mr;
_rotateOffset += (r - MathUtil::ceil(r * MathUtil::InvPi_2 - 0.5) * MathUtil::Pi_2) * i; _rotateOffset += (r - MathUtil::ceil(r * MathUtil::InvPi_2 - 0.5) * MathUtil::Pi_2) * i;
r = _rotateOffset * mr + ca; r = _rotateOffset * mr + ca;
c = MathUtil::cos(r); c = MathUtil::cos(r);
s = MathUtil::sin(r); s = MathUtil::sin(r);
if (scaleX) { if (scaleX) {
r = l * bone->getWorldScaleX(); r = l * bone->getWorldScaleX();
if (r > 0) _scaleOffset += (dx * c + dy * s) * i / r; if (r > 0) _scaleOffset += (dx * c + dy * s) * i / r;
} }
} else { } else {
c = MathUtil::cos(ca); c = MathUtil::cos(ca);
s = MathUtil::sin(ca); s = MathUtil::sin(ca);
float r = l * bone->getWorldScaleX(); float r = l * bone->getWorldScaleX();
if (r > 0) _scaleOffset += ((this->_cx - bone->_worldX) * c + (this->_cy - bone->_worldY) * s) * i / r; if (r > 0) _scaleOffset += ((this->_cx - bone->_worldX) * c + (this->_cy - bone->_worldY) * s) * i / r;
} }
remaining = _remaining; remaining = _remaining;
if (remaining >= step) { if (remaining >= step) {
float m = _massInverse * step, e = _strength; float m = _massInverse * step, e = _strength;
float d = MathUtil::pow(_damping, 60 * step); float d = MathUtil::pow(_damping, 60 * step);
while(true) { while (true) {
remaining -= step; remaining -= step;
if (scaleX) { if (scaleX) {
_scaleVelocity += (_wind * c - _gravity * s - _scaleOffset * e) * m; _scaleVelocity += (_wind * c - _gravity * s - _scaleOffset * e) * m;
_scaleOffset += _scaleVelocity * step; _scaleOffset += _scaleVelocity * step;
_scaleVelocity *= d; _scaleVelocity *= d;
} }
if (rotateOrShearX) { if (rotateOrShearX) {
_rotateVelocity += (-0.01f * l * (_wind * s + _gravity * c) - _rotateOffset * e) * m; _rotateVelocity += (-0.01f * l * (_wind * s + _gravity * c) - _rotateOffset * e) * m;
_rotateOffset += _rotateVelocity * step; _rotateOffset += _rotateVelocity * step;
_rotateVelocity *= d; _rotateVelocity *= d;
if (remaining < step) break; if (remaining < step) break;
float r = _rotateOffset * mr + ca; float r = _rotateOffset * mr + ca;
c = MathUtil::cos(r); c = MathUtil::cos(r);
s = MathUtil::sin(r); s = MathUtil::sin(r);
} else if (remaining < step) // } else if (remaining < step)//
break; break;
} }
} }
} }
_remaining = remaining; _remaining = remaining;
} }
_cx = bone->_worldX; _cx = bone->_worldX;
_cy = bone->_worldY; _cy = bone->_worldY;
break; break;
} }
case Physics::Physics_Pose: { case Physics::Physics_Pose: {
if (x) bone->_worldX += _xOffset * mix * _data._x; if (x) bone->_worldX += _xOffset * mix * _data._x;
if (y) bone->_worldY += _yOffset * mix * _data._y; if (y) bone->_worldY += _yOffset * mix * _data._y;
break; break;
} }
} }
if (rotateOrShearX) { if (rotateOrShearX) {
float o = _rotateOffset * mix, s = 0, c = 0, a = 0; float o = _rotateOffset * mix, s = 0, c = 0, a = 0;
if (_data._shearX > 0) { if (_data._shearX > 0) {
float r = 0; float r = 0;
if (_data._rotate > 0) { if (_data._rotate > 0) {
r = o * _data._rotate; r = o * _data._rotate;
s = MathUtil::sin(r); s = MathUtil::sin(r);
c = MathUtil::cos(r); c = MathUtil::cos(r);
a = bone->_b; a = bone->_b;
bone->_b = c * a - s * bone->_d; bone->_b = c * a - s * bone->_d;
bone->_d = s * a + c * bone->_d; bone->_d = s * a + c * bone->_d;
} }
r += o * _data._shearX; r += o * _data._shearX;
s = MathUtil::sin(r); s = MathUtil::sin(r);
c = MathUtil::cos(r); c = MathUtil::cos(r);
a = bone->_a; a = bone->_a;
bone->_a = c * a - s * bone->_c; bone->_a = c * a - s * bone->_c;
bone->_c = s * a + c * bone->_c; bone->_c = s * a + c * bone->_c;
} else { } else {
o *= _data._rotate; o *= _data._rotate;
s = MathUtil::sin(o); s = MathUtil::sin(o);
c = MathUtil::cos(o); c = MathUtil::cos(o);
a = bone->_a; a = bone->_a;
bone->_a = c * a - s * bone->_c; bone->_a = c * a - s * bone->_c;
bone->_c = s * a + c * bone->_c; bone->_c = s * a + c * bone->_c;
a = bone->_b; a = bone->_b;
bone->_b = c * a - s * bone->_d; bone->_b = c * a - s * bone->_d;
bone->_d = s * a + c * bone->_d; bone->_d = s * a + c * bone->_d;
} }
} }
if (scaleX) { if (scaleX) {
float s = 1 + _scaleOffset * mix * _data._scaleX; float s = 1 + _scaleOffset * mix * _data._scaleX;
bone->_a *= s; bone->_a *= s;
bone->_c *= s; bone->_c *= s;
} }
if (physics != Physics::Physics_Pose) { if (physics != Physics::Physics_Pose) {
_tx = l * bone->_a; _tx = l * bone->_a;
_ty = l * bone->_c; _ty = l * bone->_c;
} }
bone->updateAppliedTransform(); bone->updateAppliedTransform();
} }

View File

@ -38,179 +38,178 @@ using namespace spine;
RTTI_IMPL(PhysicsConstraintData, ConstraintData) RTTI_IMPL(PhysicsConstraintData, ConstraintData)
PhysicsConstraintData::PhysicsConstraintData(const String &name) : ConstraintData(name), PhysicsConstraintData::PhysicsConstraintData(const String &name) : ConstraintData(name),
_bone(nullptr), _bone(nullptr),
_x(0), _y(0), _rotate(0), _scaleX(0), _shearX(0), _x(0), _y(0), _rotate(0), _scaleX(0), _shearX(0),
_step(0), _inertia(0), _strength(0), _damping(0), _massInverse(0), _wind(0), _gravity(0), _mix(0), _step(0), _inertia(0), _strength(0), _damping(0), _massInverse(0), _wind(0), _gravity(0), _mix(0),
_inertiaGlobal(false), _strengthGlobal(false), _dampingGlobal(false), _massGlobal(false), _inertiaGlobal(false), _strengthGlobal(false), _dampingGlobal(false), _massGlobal(false),
_windGlobal(false), _gravityGlobal(false), _mixGlobal(false) _windGlobal(false), _gravityGlobal(false), _mixGlobal(false) {
{
} }
void PhysicsConstraintData::setBone(BoneData* bone) { void PhysicsConstraintData::setBone(BoneData *bone) {
_bone = bone; _bone = bone;
} }
BoneData* PhysicsConstraintData::getBone() const { BoneData *PhysicsConstraintData::getBone() const {
return _bone; return _bone;
} }
void PhysicsConstraintData::setX(float x) { void PhysicsConstraintData::setX(float x) {
_x = x; _x = x;
} }
float PhysicsConstraintData::getX() const { float PhysicsConstraintData::getX() const {
return _x; return _x;
} }
void PhysicsConstraintData::setY(float y) { void PhysicsConstraintData::setY(float y) {
_y = y; _y = y;
} }
float PhysicsConstraintData::getY() const { float PhysicsConstraintData::getY() const {
return _y; return _y;
} }
void PhysicsConstraintData::setRotate(float rotate) { void PhysicsConstraintData::setRotate(float rotate) {
_rotate = rotate; _rotate = rotate;
} }
float PhysicsConstraintData::getRotate() const { float PhysicsConstraintData::getRotate() const {
return _rotate; return _rotate;
} }
void PhysicsConstraintData::setScaleX(float scaleX) { void PhysicsConstraintData::setScaleX(float scaleX) {
_scaleX = scaleX; _scaleX = scaleX;
} }
float PhysicsConstraintData::getScaleX() const { float PhysicsConstraintData::getScaleX() const {
return _scaleX; return _scaleX;
} }
void PhysicsConstraintData::setShearX(float shearX) { void PhysicsConstraintData::setShearX(float shearX) {
_shearX = shearX; _shearX = shearX;
} }
float PhysicsConstraintData::getShearX() const { float PhysicsConstraintData::getShearX() const {
return _shearX; return _shearX;
} }
void PhysicsConstraintData::setStep(float step) { void PhysicsConstraintData::setStep(float step) {
_step = step; _step = step;
} }
float PhysicsConstraintData::getStep() const { float PhysicsConstraintData::getStep() const {
return _step; return _step;
} }
void PhysicsConstraintData::setInertia(float inertia) { void PhysicsConstraintData::setInertia(float inertia) {
_inertia = inertia; _inertia = inertia;
} }
float PhysicsConstraintData::getInertia() const { float PhysicsConstraintData::getInertia() const {
return _inertia; return _inertia;
} }
void PhysicsConstraintData::setStrength(float strength) { void PhysicsConstraintData::setStrength(float strength) {
_strength = strength; _strength = strength;
} }
float PhysicsConstraintData::getStrength() const { float PhysicsConstraintData::getStrength() const {
return _strength; return _strength;
} }
void PhysicsConstraintData::setDamping(float damping) { void PhysicsConstraintData::setDamping(float damping) {
_damping = damping; _damping = damping;
} }
float PhysicsConstraintData::getDamping() const { float PhysicsConstraintData::getDamping() const {
return _damping; return _damping;
} }
void PhysicsConstraintData::setMassInverse(float massInverse) { void PhysicsConstraintData::setMassInverse(float massInverse) {
_massInverse = massInverse; _massInverse = massInverse;
} }
float PhysicsConstraintData::getMassInverse() const { float PhysicsConstraintData::getMassInverse() const {
return _massInverse; return _massInverse;
} }
void PhysicsConstraintData::setWind(float wind) { void PhysicsConstraintData::setWind(float wind) {
_wind = wind; _wind = wind;
} }
float PhysicsConstraintData::getWind() const { float PhysicsConstraintData::getWind() const {
return _wind; return _wind;
} }
void PhysicsConstraintData::setGravity(float gravity) { void PhysicsConstraintData::setGravity(float gravity) {
_gravity = gravity; _gravity = gravity;
} }
float PhysicsConstraintData::getGravity() const { float PhysicsConstraintData::getGravity() const {
return _gravity; return _gravity;
} }
void PhysicsConstraintData::setMix(float mix) { void PhysicsConstraintData::setMix(float mix) {
_mix = mix; _mix = mix;
} }
float PhysicsConstraintData::getMix() const { float PhysicsConstraintData::getMix() const {
return _mix; return _mix;
} }
void PhysicsConstraintData::setInertiaGlobal(bool inertiaGlobal) { void PhysicsConstraintData::setInertiaGlobal(bool inertiaGlobal) {
_inertiaGlobal = inertiaGlobal; _inertiaGlobal = inertiaGlobal;
} }
bool PhysicsConstraintData::isInertiaGlobal() const { bool PhysicsConstraintData::isInertiaGlobal() const {
return _inertiaGlobal; return _inertiaGlobal;
} }
void PhysicsConstraintData::setStrengthGlobal(bool strengthGlobal) { void PhysicsConstraintData::setStrengthGlobal(bool strengthGlobal) {
_strengthGlobal = strengthGlobal; _strengthGlobal = strengthGlobal;
} }
bool PhysicsConstraintData::isStrengthGlobal() const { bool PhysicsConstraintData::isStrengthGlobal() const {
return _strengthGlobal; return _strengthGlobal;
} }
void PhysicsConstraintData::setDampingGlobal(bool dampingGlobal) { void PhysicsConstraintData::setDampingGlobal(bool dampingGlobal) {
_dampingGlobal = dampingGlobal; _dampingGlobal = dampingGlobal;
} }
bool PhysicsConstraintData::isDampingGlobal() const { bool PhysicsConstraintData::isDampingGlobal() const {
return _dampingGlobal; return _dampingGlobal;
} }
void PhysicsConstraintData::setMassGlobal(bool massGlobal) { void PhysicsConstraintData::setMassGlobal(bool massGlobal) {
_massGlobal = massGlobal; _massGlobal = massGlobal;
} }
bool PhysicsConstraintData::isMassGlobal() const { bool PhysicsConstraintData::isMassGlobal() const {
return _massGlobal; return _massGlobal;
} }
void PhysicsConstraintData::setWindGlobal(bool windGlobal) { void PhysicsConstraintData::setWindGlobal(bool windGlobal) {
_windGlobal = windGlobal; _windGlobal = windGlobal;
} }
bool PhysicsConstraintData::isWindGlobal() const { bool PhysicsConstraintData::isWindGlobal() const {
return _windGlobal; return _windGlobal;
} }
void PhysicsConstraintData::setGravityGlobal(bool gravityGlobal) { void PhysicsConstraintData::setGravityGlobal(bool gravityGlobal) {
_gravityGlobal = gravityGlobal; _gravityGlobal = gravityGlobal;
} }
bool PhysicsConstraintData::isGravityGlobal() const { bool PhysicsConstraintData::isGravityGlobal() const {
return _gravityGlobal; return _gravityGlobal;
} }
void PhysicsConstraintData::setMixGlobal(bool mixGlobal) { void PhysicsConstraintData::setMixGlobal(bool mixGlobal) {
_mixGlobal = mixGlobal; _mixGlobal = mixGlobal;
} }
bool PhysicsConstraintData::isMixGlobal() const { bool PhysicsConstraintData::isMixGlobal() const {
return _mixGlobal; return _mixGlobal;
} }

View File

@ -52,51 +52,51 @@ RTTI_IMPL(PhysicsConstraintMixTimeline, PhysicsConstraintTimeline)
RTTI_IMPL(PhysicsConstraintResetTimeline, Timeline) RTTI_IMPL(PhysicsConstraintResetTimeline, Timeline)
PhysicsConstraintTimeline::PhysicsConstraintTimeline(size_t frameCount, size_t bezierCount, PhysicsConstraintTimeline::PhysicsConstraintTimeline(size_t frameCount, size_t bezierCount,
int constraintIndex, Property property) : CurveTimeline1(frameCount, bezierCount), int constraintIndex, Property property) : CurveTimeline1(frameCount, bezierCount),
_constraintIndex(constraintIndex) { _constraintIndex(constraintIndex) {
PropertyId ids[] = {((PropertyId) property << 32) | constraintIndex}; PropertyId ids[] = {((PropertyId) property << 32) | constraintIndex};
setPropertyIds(ids, 1); setPropertyIds(ids, 1);
} }
void PhysicsConstraintTimeline::apply(Skeleton &skeleton, float, float time, Vector<Event *> *, void PhysicsConstraintTimeline::apply(Skeleton &skeleton, float, float time, Vector<Event *> *,
float alpha, MixBlend blend, MixDirection) { float alpha, MixBlend blend, MixDirection) {
if (_constraintIndex == -1) { if (_constraintIndex == -1) {
float value = time >= _frames[0] ?getCurveValue(time) : 0; float value = time >= _frames[0] ? getCurveValue(time) : 0;
Vector<PhysicsConstraint*> &physicsConstraints = skeleton.getPhysicsConstraints(); Vector<PhysicsConstraint *> &physicsConstraints = skeleton.getPhysicsConstraints();
for (size_t i = 0; i < physicsConstraints.size(); i++) { for (size_t i = 0; i < physicsConstraints.size(); i++) {
PhysicsConstraint *constraint = physicsConstraints[i]; PhysicsConstraint *constraint = physicsConstraints[i];
if (constraint->_active && global(constraint->_data)) if (constraint->_active && global(constraint->_data))
set(constraint, getAbsoluteValue(time, alpha, blend, get(constraint), setup(constraint), value)); set(constraint, getAbsoluteValue(time, alpha, blend, get(constraint), setup(constraint), value));
} }
} else { } else {
PhysicsConstraint *constraint = skeleton.getPhysicsConstraints()[_constraintIndex]; PhysicsConstraint *constraint = skeleton.getPhysicsConstraints()[_constraintIndex];
if (constraint->_active) set(constraint, getAbsoluteValue(time, alpha, blend, get(constraint), setup(constraint))); if (constraint->_active) set(constraint, getAbsoluteValue(time, alpha, blend, get(constraint), setup(constraint)));
} }
} }
void PhysicsConstraintResetTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *, float alpha, MixBlend blend, MixDirection direction) { void PhysicsConstraintResetTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *, float alpha, MixBlend blend, MixDirection direction) {
PhysicsConstraint *constraint = nullptr; PhysicsConstraint *constraint = nullptr;
if (_constraintIndex != -1) { if (_constraintIndex != -1) {
constraint = skeleton.getPhysicsConstraints()[_constraintIndex]; constraint = skeleton.getPhysicsConstraints()[_constraintIndex];
if (!constraint->_active) return; if (!constraint->_active) return;
} }
if (lastTime > time) { // Apply after lastTime for looped animations. if (lastTime > time) {// Apply after lastTime for looped animations.
apply(skeleton, lastTime, FLT_MAX, nullptr, alpha, blend, direction); apply(skeleton, lastTime, FLT_MAX, nullptr, alpha, blend, direction);
lastTime = -1; lastTime = -1;
} else if (lastTime >= _frames[_frames.size() - 1]) // Last time is after last frame. } else if (lastTime >= _frames[_frames.size() - 1])// Last time is after last frame.
return; return;
if (time < _frames[0]) return; if (time < _frames[0]) return;
if (lastTime < _frames[0] || time >= _frames[Animation::search(_frames, lastTime) + 1]) { if (lastTime < _frames[0] || time >= _frames[Animation::search(_frames, lastTime) + 1]) {
if (constraint != nullptr) if (constraint != nullptr)
constraint->reset(); constraint->reset();
else { else {
Vector<PhysicsConstraint *> &physicsConstraints = skeleton.getPhysicsConstraints(); Vector<PhysicsConstraint *> &physicsConstraints = skeleton.getPhysicsConstraints();
for (size_t i = 0; i < physicsConstraints.size(); i++) { for (size_t i = 0; i < physicsConstraints.size(); i++) {
if (constraint->_active) constraint->reset(); if (constraint->_active) constraint->reset();
} }
} }
} }
} }

View File

@ -45,10 +45,10 @@ void PointAttachment::computeWorldPosition(Bone &bone, float &ox, float &oy) {
} }
float PointAttachment::computeWorldRotation(Bone &bone) { float PointAttachment::computeWorldRotation(Bone &bone) {
float r = _rotation * MathUtil::Deg_Rad, cosine = MathUtil::cos(r), sine = MathUtil::sin(r); float r = _rotation * MathUtil::Deg_Rad, cosine = MathUtil::cos(r), sine = MathUtil::sin(r);
float x = cosine * bone._a + sine * bone._b; float x = cosine * bone._a + sine * bone._b;
float y = cosine * bone._c + sine * bone._d; float y = cosine * bone._c + sine * bone._d;
return MathUtil::atan2Deg(y, x); return MathUtil::atan2Deg(y, x);
} }
float PointAttachment::getX() { float PointAttachment::getX() {

View File

@ -55,5 +55,5 @@ void RotateTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vecto
SP_UNUSED(direction); SP_UNUSED(direction);
Bone *bone = skeleton._bones[_boneIndex]; Bone *bone = skeleton._bones[_boneIndex];
if (bone->isActive()) bone->_rotation = getRelativeValue(time, alpha, blend, bone->_rotation, bone->getData()._rotation); if (bone->isActive()) bone->_rotation = getRelativeValue(time, alpha, blend, bone->_rotation, bone->getData()._rotation);
} }

View File

@ -170,7 +170,7 @@ void ScaleXTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vecto
SP_UNUSED(pEvents); SP_UNUSED(pEvents);
Bone *bone = skeleton._bones[_boneIndex]; Bone *bone = skeleton._bones[_boneIndex];
if (bone->_active) bone->_scaleX = getScaleValue(time, alpha, blend, direction, bone->_scaleX, bone->_data._scaleX); if (bone->_active) bone->_scaleX = getScaleValue(time, alpha, blend, direction, bone->_scaleX, bone->_data._scaleX);
} }
RTTI_IMPL(ScaleYTimeline, CurveTimeline1) RTTI_IMPL(ScaleYTimeline, CurveTimeline1)
@ -190,5 +190,5 @@ void ScaleYTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vecto
SP_UNUSED(pEvents); SP_UNUSED(pEvents);
Bone *bone = skeleton._bones[_boneIndex]; Bone *bone = skeleton._bones[_boneIndex];
if (bone->_active) bone->_scaleY = getScaleValue(time, alpha, blend, direction, bone->_scaleX, bone->_data._scaleY); if (bone->_active) bone->_scaleY = getScaleValue(time, alpha, blend, direction, bone->_scaleX, bone->_data._scaleY);
} }

View File

@ -136,7 +136,7 @@ void ShearXTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vecto
SP_UNUSED(direction); SP_UNUSED(direction);
Bone *bone = skeleton._bones[_boneIndex]; Bone *bone = skeleton._bones[_boneIndex];
if (bone->_active) bone->_shearX = getRelativeValue(time, alpha, blend, bone->_shearX, bone->_data._shearX); if (bone->_active) bone->_shearX = getRelativeValue(time, alpha, blend, bone->_shearX, bone->_data._shearX);
} }
RTTI_IMPL(ShearYTimeline, CurveTimeline1) RTTI_IMPL(ShearYTimeline, CurveTimeline1)
@ -158,5 +158,5 @@ void ShearYTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vecto
SP_UNUSED(direction); SP_UNUSED(direction);
Bone *bone = skeleton._bones[_boneIndex]; Bone *bone = skeleton._bones[_boneIndex];
if (bone->_active) bone->_shearY = getRelativeValue(time, alpha, blend, bone->_shearX, bone->_data._shearY); if (bone->_active) bone->_shearY = getRelativeValue(time, alpha, blend, bone->_shearX, bone->_data._shearY);
} }

View File

@ -62,7 +62,7 @@ Skeleton::Skeleton(SkeletonData *skeletonData) : _data(skeletonData),
_scaleY(1), _scaleY(1),
_x(0), _x(0),
_y(0), _y(0),
_time(0){ _time(0) {
_bones.ensureCapacity(_data->getBones().size()); _bones.ensureCapacity(_data->getBones().size());
for (size_t i = 0; i < _data->getBones().size(); ++i) { for (size_t i = 0; i < _data->getBones().size(); ++i) {
BoneData *data = _data->getBones()[i]; BoneData *data = _data->getBones()[i];
@ -118,14 +118,14 @@ Skeleton::Skeleton(SkeletonData *skeletonData) : _data(skeletonData),
_pathConstraints.add(constraint); _pathConstraints.add(constraint);
} }
_physicsConstraints.ensureCapacity(_data->getPhysicsConstraints().size()); _physicsConstraints.ensureCapacity(_data->getPhysicsConstraints().size());
for (size_t i = 0; i < _data->getPhysicsConstraints().size(); ++i) { for (size_t i = 0; i < _data->getPhysicsConstraints().size(); ++i) {
PhysicsConstraintData *data = _data->getPhysicsConstraints()[i]; PhysicsConstraintData *data = _data->getPhysicsConstraints()[i];
PhysicsConstraint *constraint = new (__FILE__, __LINE__) PhysicsConstraint(*data, *this); PhysicsConstraint *constraint = new (__FILE__, __LINE__) PhysicsConstraint(*data, *this);
_physicsConstraints.add(constraint); _physicsConstraints.add(constraint);
} }
updateCache(); updateCache();
} }
@ -162,7 +162,7 @@ void Skeleton::updateCache() {
size_t ikCount = _ikConstraints.size(); size_t ikCount = _ikConstraints.size();
size_t transformCount = _transformConstraints.size(); size_t transformCount = _transformConstraints.size();
size_t pathCount = _pathConstraints.size(); size_t pathCount = _pathConstraints.size();
size_t physicsCount = _physicsConstraints.size(); size_t physicsCount = _physicsConstraints.size();
size_t constraintCount = ikCount + transformCount + pathCount + physicsCount; size_t constraintCount = ikCount + transformCount + pathCount + physicsCount;
@ -196,14 +196,14 @@ continue_outer:
} }
} }
for (size_t ii = 0; ii < pathCount; ++ii) { for (size_t ii = 0; ii < pathCount; ++ii) {
PhysicsConstraint *constraint = _physicsConstraints[ii]; PhysicsConstraint *constraint = _physicsConstraints[ii];
if (constraint->getData().getOrder() == i) { if (constraint->getData().getOrder() == i) {
sortPhysicsConstraint(constraint); sortPhysicsConstraint(constraint);
i++; i++;
goto continue_outer; goto continue_outer;
} }
} }
} }
size_t n = _bones.size(); size_t n = _bones.size();
@ -241,7 +241,7 @@ void Skeleton::updateWorldTransform(Physics physics) {
for (size_t i = 0, n = _updateCache.size(); i < n; ++i) { for (size_t i = 0, n = _updateCache.size(); i < n; ++i) {
Updatable *updatable = _updateCache[i]; Updatable *updatable = _updateCache[i];
updatable->update(physics); updatable->update(physics);
} }
} }
@ -252,12 +252,12 @@ void Skeleton::updateWorldTransform(Physics physics, Bone *parent) {
rootBone->_worldX = pa * _x + pb * _y + parent->_worldX; rootBone->_worldX = pa * _x + pb * _y + parent->_worldX;
rootBone->_worldY = pc * _x + pd * _y + parent->_worldY; rootBone->_worldY = pc * _x + pd * _y + parent->_worldY;
float rx = (rootBone->_rotation + rootBone->_shearX) * MathUtil::Deg_Rad; float rx = (rootBone->_rotation + rootBone->_shearX) * MathUtil::Deg_Rad;
float ry = (rootBone->_rotation + 90 + rootBone->_shearY) * MathUtil::Deg_Rad; float ry = (rootBone->_rotation + 90 + rootBone->_shearY) * MathUtil::Deg_Rad;
float la = MathUtil::cos(rx) * rootBone->_scaleX; float la = MathUtil::cos(rx) * rootBone->_scaleX;
float lb = MathUtil::cos(ry) * rootBone->_scaleY; float lb = MathUtil::cos(ry) * rootBone->_scaleY;
float lc = MathUtil::sin(rx) * rootBone->_scaleX; float lc = MathUtil::sin(rx) * rootBone->_scaleX;
float ld = MathUtil::sin(ry) * rootBone->_scaleY; float ld = MathUtil::sin(ry) * rootBone->_scaleY;
rootBone->_a = (pa * la + pb * lc) * _scaleX; rootBone->_a = (pa * la + pb * lc) * _scaleX;
rootBone->_b = (pa * lb + pb * ld) * _scaleX; rootBone->_b = (pa * lb + pb * ld) * _scaleX;
rootBone->_c = (pc * la + pd * lc) * _scaleY; rootBone->_c = (pc * la + pd * lc) * _scaleY;
@ -293,9 +293,9 @@ void Skeleton::setBonesToSetupPose() {
_pathConstraints[i]->setToSetupPose(); _pathConstraints[i]->setToSetupPose();
} }
for (size_t i = 0, n = _physicsConstraints.size(); i < n; ++i) { for (size_t i = 0, n = _physicsConstraints.size(); i < n; ++i) {
_physicsConstraints[i]->setToSetupPose(); _physicsConstraints[i]->setToSetupPose();
} }
} }
void Skeleton::setSlotsToSetupPose() { void Skeleton::setSlotsToSetupPose() {
@ -644,15 +644,15 @@ void Skeleton::sortTransformConstraint(TransformConstraint *constraint) {
} }
void Skeleton::sortPhysicsConstraint(PhysicsConstraint *constraint) { void Skeleton::sortPhysicsConstraint(PhysicsConstraint *constraint) {
Bone *bone = constraint->getBone(); Bone *bone = constraint->getBone();
constraint->_active = bone->_active && (!constraint->_data.isSkinRequired() || constraint->_active = bone->_active && (!constraint->_data.isSkinRequired() ||
(_skin && _skin->_constraints.contains(&constraint->_data))); (_skin && _skin->_constraints.contains(&constraint->_data)));
if (!constraint->_active) return; if (!constraint->_active) return;
sortBone(bone); sortBone(bone);
_updateCache.add(constraint); _updateCache.add(constraint);
sortReset(bone->getChildren()); sortReset(bone->getChildren());
bone->_sorted = true; bone->_sorted = true;
} }
void Skeleton::sortPathConstraintAttachment(Skin *skin, size_t slotIndex, Bone &slotBone) { void Skeleton::sortPathConstraintAttachment(Skin *skin, size_t slotIndex, Bone &slotBone) {
@ -701,14 +701,13 @@ void Skeleton::sortReset(Vector<Bone *> &bones) {
} }
float Skeleton::getTime() { float Skeleton::getTime() {
return _time; return _time;
} }
void Skeleton::setTime(float time) { void Skeleton::setTime(float time) {
_time = time; _time = time;
} }
void Skeleton::update(float delta) { void Skeleton::update(float delta) {
_time += delta; _time += delta;
} }

View File

@ -67,7 +67,7 @@ SkeletonData::~SkeletonData() {
ContainerUtil::cleanUpVectorOfPointers(_ikConstraints); ContainerUtil::cleanUpVectorOfPointers(_ikConstraints);
ContainerUtil::cleanUpVectorOfPointers(_transformConstraints); ContainerUtil::cleanUpVectorOfPointers(_transformConstraints);
ContainerUtil::cleanUpVectorOfPointers(_pathConstraints); ContainerUtil::cleanUpVectorOfPointers(_pathConstraints);
ContainerUtil::cleanUpVectorOfPointers(_physicsConstraints); ContainerUtil::cleanUpVectorOfPointers(_physicsConstraints);
for (size_t i = 0; i < _strings.size(); i++) { for (size_t i = 0; i < _strings.size(); i++) {
SpineExtension::free(_strings[i], __FILE__, __LINE__); SpineExtension::free(_strings[i], __FILE__, __LINE__);
} }
@ -106,7 +106,7 @@ PathConstraintData *SkeletonData::findPathConstraint(const String &constraintNam
} }
PhysicsConstraintData *SkeletonData::findPhysicsConstraint(const String &constraintName) { PhysicsConstraintData *SkeletonData::findPhysicsConstraint(const String &constraintName) {
return ContainerUtil::findWithName(_physicsConstraints, constraintName); return ContainerUtil::findWithName(_physicsConstraints, constraintName);
} }
const String &SkeletonData::getName() { const String &SkeletonData::getName() {
@ -158,7 +158,7 @@ Vector<PathConstraintData *> &SkeletonData::getPathConstraints() {
} }
Vector<PhysicsConstraintData *> &SkeletonData::getPhysicsConstraints() { Vector<PhysicsConstraintData *> &SkeletonData::getPhysicsConstraints() {
return _physicsConstraints; return _physicsConstraints;
} }
float SkeletonData::getX() { float SkeletonData::getX() {

View File

@ -41,7 +41,7 @@ SlotData::SlotData(int index, const String &name, BoneData &boneData) : _index(i
_hasDarkColor(false), _hasDarkColor(false),
_attachmentName(), _attachmentName(),
_blendMode(BlendMode_Normal), _blendMode(BlendMode_Normal),
_visible(true) { _visible(true) {
assert(_index >= 0); assert(_index >= 0);
assert(_name.length() > 0); assert(_name.length() > 0);
} }
@ -91,9 +91,9 @@ void SlotData::setBlendMode(BlendMode inValue) {
} }
bool SlotData::isVisible() { bool SlotData::isVisible() {
return _visible; return _visible;
} }
void SlotData::setVisible(bool inValue) { void SlotData::setVisible(bool inValue) {
this->_visible = inValue; this->_visible = inValue;
} }

View File

@ -47,7 +47,7 @@ TransformConstraintTimeline::TransformConstraintTimeline(size_t frameCount, size
int transformConstraintIndex) : CurveTimeline(frameCount, int transformConstraintIndex) : CurveTimeline(frameCount,
TransformConstraintTimeline::ENTRIES, TransformConstraintTimeline::ENTRIES,
bezierCount), bezierCount),
_constraintIndex( _constraintIndex(
transformConstraintIndex) { transformConstraintIndex) {
PropertyId ids[] = {((PropertyId) Property_TransformConstraint << 32) | transformConstraintIndex}; PropertyId ids[] = {((PropertyId) Property_TransformConstraint << 32) | transformConstraintIndex};
setPropertyIds(ids, 1); setPropertyIds(ids, 1);

View File

@ -136,7 +136,7 @@ void TranslateXTimeline::apply(Skeleton &skeleton, float lastTime, float time, V
SP_UNUSED(direction); SP_UNUSED(direction);
Bone *bone = skeleton._bones[_boneIndex]; Bone *bone = skeleton._bones[_boneIndex];
if (bone->_active) bone->_x = getRelativeValue(time, alpha, blend, bone->_x, bone->_data._x); if (bone->_active) bone->_x = getRelativeValue(time, alpha, blend, bone->_x, bone->_data._x);
} }
RTTI_IMPL(TranslateYTimeline, CurveTimeline1) RTTI_IMPL(TranslateYTimeline, CurveTimeline1)
@ -158,5 +158,5 @@ void TranslateYTimeline::apply(Skeleton &skeleton, float lastTime, float time, V
SP_UNUSED(direction); SP_UNUSED(direction);
Bone *bone = skeleton._bones[_boneIndex]; Bone *bone = skeleton._bones[_boneIndex];
if (bone->_active) bone->_y = getRelativeValue(time, alpha, blend, bone->_y, bone->_data._y); if (bone->_active) bone->_y = getRelativeValue(time, alpha, blend, bone->_y, bone->_data._y);
} }