mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 22:34:53 +08:00
[cpp] Formatting
This commit is contained in:
parent
62080c6c8b
commit
d03f535ed8
@ -96,6 +96,6 @@ void _spAttachmentLoader_setError(spAttachmentLoader *self, const char *error1,
|
||||
|
||||
void _spAttachmentLoader_setUnknownTypeError(spAttachmentLoader *self, spAttachmentType type) {
|
||||
char buffer[16];
|
||||
snprintf(buffer, 16,"%d", type);
|
||||
snprintf(buffer, 16, "%d", type);
|
||||
_spAttachmentLoader_setError(self, "Unknown attachment type: ", buffer);
|
||||
}
|
||||
|
||||
@ -262,30 +262,30 @@ void spBone_updateAppliedTransform(spBone *self) {
|
||||
}
|
||||
case SP_TRANSFORMMODE_NOSCALE:
|
||||
case SP_TRANSFORMMODE_NOSCALEORREFLECTION: {
|
||||
cosine = COS_DEG(self->rotation), sine = SIN_DEG(self->rotation);
|
||||
pa = (pa * cosine + pb * sine) / self->skeleton->scaleX;
|
||||
pc = (pc * cosine + pd * sine) / self->skeleton->scaleY;
|
||||
s = SQRT(pa * pa + pc * pc);
|
||||
if (s > 0.00001f) s = 1 / s;
|
||||
pa *= s;
|
||||
pc *= s;
|
||||
s = SQRT(pa * pa + pc * pc);
|
||||
if (self->data->transformMode == SP_TRANSFORMMODE_NOSCALE &&
|
||||
pid < 0 != (self->skeleton->scaleX < 0 != self->skeleton->scaleY < 0))
|
||||
s = -s;
|
||||
r = PI / 2 + ATAN2(pc, pa);
|
||||
pb = COS(r) * s;
|
||||
pd = SIN(r) * s;
|
||||
pid = 1 / (pa * pd - pb * pc);
|
||||
ia = pd * pid;
|
||||
ib = pb * pid;
|
||||
ic = pc * pid;
|
||||
id = pa * pid;
|
||||
break;
|
||||
}
|
||||
case SP_TRANSFORMMODE_ONLYTRANSLATION:
|
||||
case SP_TRANSFORMMODE_NORMAL:
|
||||
break;
|
||||
cosine = COS_DEG(self->rotation), sine = SIN_DEG(self->rotation);
|
||||
pa = (pa * cosine + pb * sine) / self->skeleton->scaleX;
|
||||
pc = (pc * cosine + pd * sine) / self->skeleton->scaleY;
|
||||
s = SQRT(pa * pa + pc * pc);
|
||||
if (s > 0.00001f) s = 1 / s;
|
||||
pa *= s;
|
||||
pc *= s;
|
||||
s = SQRT(pa * pa + pc * pc);
|
||||
if (self->data->transformMode == SP_TRANSFORMMODE_NOSCALE &&
|
||||
pid < 0 != (self->skeleton->scaleX < 0 != self->skeleton->scaleY < 0))
|
||||
s = -s;
|
||||
r = PI / 2 + ATAN2(pc, pa);
|
||||
pb = COS(r) * s;
|
||||
pd = SIN(r) * s;
|
||||
pid = 1 / (pa * pd - pb * pc);
|
||||
ia = pd * pid;
|
||||
ib = pb * pid;
|
||||
ic = pc * pid;
|
||||
id = pa * pid;
|
||||
break;
|
||||
}
|
||||
case SP_TRANSFORMMODE_ONLYTRANSLATION:
|
||||
case SP_TRANSFORMMODE_NORMAL:
|
||||
break;
|
||||
}
|
||||
ra = ia * self->a - ib * self->c;
|
||||
rb = ia * self->b - ib * self->d;
|
||||
|
||||
@ -211,7 +211,7 @@ float TrackEntry::getTrackComplete() {
|
||||
}
|
||||
|
||||
bool TrackEntry::wasApplied() {
|
||||
return _nextTrackLast != -1;
|
||||
return _nextTrackLast != -1;
|
||||
}
|
||||
|
||||
EventQueueEntry::EventQueueEntry(EventType eventType, TrackEntry *trackEntry, Event *event) : _type(eventType),
|
||||
@ -438,14 +438,14 @@ bool AnimationState::apply(Skeleton &skeleton) {
|
||||
// apply mixing from entries first.
|
||||
float alpha = current._alpha;
|
||||
if (current._mixingFrom != NULL) {
|
||||
alpha *= applyMixingFrom(currentP, skeleton, blend);
|
||||
alpha *= applyMixingFrom(currentP, skeleton, blend);
|
||||
} 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 applyTime = animationTime;
|
||||
Vector<Event *> *applyEvents = &_events;
|
||||
@ -456,8 +456,8 @@ bool AnimationState::apply(Skeleton &skeleton) {
|
||||
size_t timelineCount = current._animation->_timelines.size();
|
||||
Vector<Timeline *> &timelines = current._animation->_timelines;
|
||||
if ((i == 0 && alpha == 1) || blend == MixBlend_Add) {
|
||||
if (i == 0) attachments = true;
|
||||
for (size_t ii = 0; ii < timelineCount; ++ii) {
|
||||
if (i == 0) attachments = true;
|
||||
for (size_t ii = 0; ii < timelineCount; ++ii) {
|
||||
Timeline *timeline = timelines[ii];
|
||||
if (timeline->getRTTI().isExactly(AttachmentTimeline::rtti))
|
||||
applyAttachmentTimeline(static_cast<AttachmentTimeline *>(timeline), skeleton, applyTime, blend,
|
||||
@ -481,13 +481,13 @@ bool AnimationState::apply(Skeleton &skeleton) {
|
||||
|
||||
if (!shortestRotation && timeline->getRTTI().isExactly(RotateTimeline::rtti))
|
||||
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))
|
||||
applyAttachmentTimeline(static_cast<AttachmentTimeline *>(timeline), skeleton, applyTime,
|
||||
timelineBlend, true);
|
||||
else
|
||||
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.
|
||||
float total, diff = r2 - r1;
|
||||
diff -= MathUtil::ceil(diff / 360 - 0.5) * 360;
|
||||
if (diff == 0) {
|
||||
diff -= MathUtil::ceil(diff / 360 - 0.5) * 360;
|
||||
if (diff == 0) {
|
||||
total = timelinesRotation[i];
|
||||
} else {
|
||||
float lastTotal, lastDiff;
|
||||
@ -885,7 +885,7 @@ float AnimationState::applyMixingFrom(TrackEntry *to, Skeleton &skeleton, MixBle
|
||||
timelinesRotation, i << 1, firstFrame);
|
||||
} else if (timeline->getRTTI().isExactly(AttachmentTimeline::rtti)) {
|
||||
applyAttachmentTimeline(static_cast<AttachmentTimeline *>(timeline), skeleton, applyTime, timelineBlend,
|
||||
attachments && alpha >= from->_alphaAttachmentThreshold);
|
||||
attachments && alpha >= from->_alphaAttachmentThreshold);
|
||||
} else {
|
||||
if (drawOrder && timeline->getRTTI().isExactly(DrawOrderTimeline::rtti) &&
|
||||
timelineBlend == MixBlend_Setup)
|
||||
@ -986,7 +986,7 @@ TrackEntry *AnimationState::newTrackEntry(size_t trackIndex, Animation *animatio
|
||||
|
||||
entry._eventThreshold = 0;
|
||||
entry._mixAttachmentThreshold = 0;
|
||||
entry._alphaAttachmentThreshold = 0;
|
||||
entry._alphaAttachmentThreshold = 0;
|
||||
entry._mixDrawOrderThreshold = 0;
|
||||
|
||||
entry._animationStart = 0;
|
||||
|
||||
@ -96,15 +96,15 @@ void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX,
|
||||
_ashearY = shearY;
|
||||
|
||||
if (!parent) { /* Root bone. */
|
||||
Skeleton &skeleton = this->_skeleton;
|
||||
float sx = skeleton.getScaleX();
|
||||
float sy = skeleton.getScaleY();
|
||||
float rx = (rotation + shearX) * MathUtil::Deg_Rad;
|
||||
float ry = (rotation + 90 + shearY) * MathUtil::Deg_Rad;
|
||||
_a = MathUtil::cos(rx) * scaleX * sx;
|
||||
_b = MathUtil::cos(ry) * scaleY * sx;
|
||||
_c = MathUtil::sin(rx) * scaleX * sy;
|
||||
_d = MathUtil::sin(ry) * scaleY * sy;
|
||||
Skeleton &skeleton = this->_skeleton;
|
||||
float sx = skeleton.getScaleX();
|
||||
float sy = skeleton.getScaleY();
|
||||
float rx = (rotation + shearX) * MathUtil::Deg_Rad;
|
||||
float ry = (rotation + 90 + shearY) * MathUtil::Deg_Rad;
|
||||
_a = MathUtil::cos(rx) * scaleX * sx;
|
||||
_b = MathUtil::cos(ry) * scaleY * sx;
|
||||
_c = MathUtil::sin(rx) * scaleX * sy;
|
||||
_d = MathUtil::sin(ry) * scaleY * sy;
|
||||
_worldX = x * sx + _skeleton.getX();
|
||||
_worldY = y * sy + _skeleton.getY();
|
||||
return;
|
||||
@ -120,12 +120,12 @@ void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX,
|
||||
|
||||
switch (_data.getTransformMode()) {
|
||||
case TransformMode_Normal: {
|
||||
float rx = (rotation + shearX) * MathUtil::Deg_Rad;
|
||||
float ry = (rotation + 90 + shearY) * MathUtil::Deg_Rad;
|
||||
float la = MathUtil::cos(rx) * scaleX;
|
||||
float lb = MathUtil::cos(ry) * scaleY;
|
||||
float lc = MathUtil::sin(rx) * scaleX;
|
||||
float ld = MathUtil::sin(ry) * scaleY;
|
||||
float rx = (rotation + shearX) * MathUtil::Deg_Rad;
|
||||
float ry = (rotation + 90 + shearY) * MathUtil::Deg_Rad;
|
||||
float la = MathUtil::cos(rx) * scaleX;
|
||||
float lb = MathUtil::cos(ry) * scaleY;
|
||||
float lc = MathUtil::sin(rx) * scaleX;
|
||||
float ld = MathUtil::sin(ry) * scaleY;
|
||||
_a = pa * la + pb * lc;
|
||||
_b = pa * lb + pb * ld;
|
||||
_c = pc * la + pd * lc;
|
||||
@ -133,12 +133,12 @@ void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX,
|
||||
return;
|
||||
}
|
||||
case TransformMode_OnlyTranslation: {
|
||||
float rx = (rotation + shearX) * MathUtil::Deg_Rad;
|
||||
float ry = (rotation + 90 + shearY) * MathUtil::Deg_Rad;
|
||||
_a = MathUtil::cos(rx) * scaleX;
|
||||
_b = MathUtil::cos(ry) * scaleY;
|
||||
_c = MathUtil::sin(rx) * scaleX;
|
||||
_d = MathUtil::sin(ry) * scaleY;
|
||||
float rx = (rotation + shearX) * MathUtil::Deg_Rad;
|
||||
float ry = (rotation + 90 + shearY) * MathUtil::Deg_Rad;
|
||||
_a = MathUtil::cos(rx) * scaleX;
|
||||
_b = MathUtil::cos(ry) * scaleY;
|
||||
_c = MathUtil::sin(rx) * scaleX;
|
||||
_d = MathUtil::sin(ry) * scaleY;
|
||||
break;
|
||||
}
|
||||
case TransformMode_NoRotationOrReflection: {
|
||||
@ -156,12 +156,12 @@ void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX,
|
||||
pc = 0;
|
||||
prx = 90 - MathUtil::atan2(pd, pb) * MathUtil::Rad_Deg;
|
||||
}
|
||||
float rx = (rotation + shearX - prx) * MathUtil::Deg_Rad;
|
||||
float ry = (rotation + shearY - prx + 90) * MathUtil::Deg_Rad;
|
||||
float la = MathUtil::cos(rx) * scaleX;
|
||||
float lb = MathUtil::cos(ry) * scaleY;
|
||||
float lc = MathUtil::sin(rx) * scaleX;
|
||||
float ld = MathUtil::sin(ry) * scaleY;
|
||||
float rx = (rotation + shearX - prx) * MathUtil::Deg_Rad;
|
||||
float ry = (rotation + shearY - prx + 90) * MathUtil::Deg_Rad;
|
||||
float la = MathUtil::cos(rx) * scaleX;
|
||||
float lb = MathUtil::cos(ry) * scaleY;
|
||||
float lc = MathUtil::sin(rx) * scaleX;
|
||||
float ld = MathUtil::sin(ry) * scaleY;
|
||||
_a = pa * la - pb * lc;
|
||||
_b = pa * lb - pb * ld;
|
||||
_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_NoScaleOrReflection: {
|
||||
rotation *= MathUtil::Deg_Rad;
|
||||
float cosine = MathUtil::cos(rotation);
|
||||
float sine = MathUtil::sin(rotation);
|
||||
rotation *= MathUtil::Deg_Rad;
|
||||
float cosine = MathUtil::cos(rotation);
|
||||
float sine = MathUtil::sin(rotation);
|
||||
float za = (pa * cosine + pb * sine) / _skeleton.getScaleX();
|
||||
float zc = (pc * cosine + pd * sine) / _skeleton.getScaleY();
|
||||
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 &&
|
||||
(pa * pd - pb * pc < 0) != (_skeleton.getScaleX() < 0 != _skeleton.getScaleY() < 0))
|
||||
s = -s;
|
||||
rotation = MathUtil::Pi / 2 + MathUtil::atan2(zc, za);
|
||||
float zb = MathUtil::cos(rotation) * s;
|
||||
float zd = MathUtil::sin(rotation) * s;
|
||||
shearX *= MathUtil::Deg_Rad;
|
||||
shearY = (90 + shearY) * MathUtil::Deg_Rad;
|
||||
float la = MathUtil::cos(shearX) * scaleX;
|
||||
float lb = MathUtil::cos(shearY) * scaleY;
|
||||
float lc = MathUtil::sin(shearX) * scaleX;
|
||||
float ld = MathUtil::sin(shearY) * scaleY;
|
||||
rotation = MathUtil::Pi / 2 + MathUtil::atan2(zc, za);
|
||||
float zb = MathUtil::cos(rotation) * s;
|
||||
float zd = MathUtil::sin(rotation) * s;
|
||||
shearX *= MathUtil::Deg_Rad;
|
||||
shearY = (90 + shearY) * MathUtil::Deg_Rad;
|
||||
float la = MathUtil::cos(shearX) * scaleX;
|
||||
float lb = MathUtil::cos(shearY) * scaleY;
|
||||
float lc = MathUtil::sin(shearX) * scaleX;
|
||||
float ld = MathUtil::sin(shearY) * scaleY;
|
||||
_a = za * la + zb * lc;
|
||||
_b = za * lb + zb * ld;
|
||||
_c = zc * la + zd * lc;
|
||||
@ -251,13 +251,13 @@ float Bone::localToWorldRotation(float localRotation) {
|
||||
}
|
||||
|
||||
void Bone::rotateWorld(float degrees) {
|
||||
degrees *= MathUtil::Deg_Rad;
|
||||
float sine = MathUtil::sin(degrees), cosine = MathUtil::cos(degrees);
|
||||
float ra = _a, rb = _b;
|
||||
_a = cosine * ra - sine * _c;
|
||||
_b = cosine * rb - sine * _d;
|
||||
_c = sine * ra + cosine * _c;
|
||||
_d = sine * rb + cosine * _d;
|
||||
degrees *= MathUtil::Deg_Rad;
|
||||
float sine = MathUtil::sin(degrees), cosine = MathUtil::cos(degrees);
|
||||
float ra = _a, rb = _b;
|
||||
_a = cosine * ra - sine * _c;
|
||||
_b = cosine * rb - sine * _d;
|
||||
_c = sine * ra + cosine * _c;
|
||||
_d = sine * rb + cosine * _d;
|
||||
}
|
||||
|
||||
float Bone::getWorldToLocalRotationX() {
|
||||
@ -497,70 +497,70 @@ void Bone::updateAppliedTransform() {
|
||||
}
|
||||
float pa = parent->_a, pb = parent->_b, pc = parent->_c, pd = parent->_d;
|
||||
float pid = 1 / (pa * pd - pb * pc);
|
||||
float ia = pd * pid, ib = pb * pid, ic = pc * pid, id = pa * pid;
|
||||
float dx = _worldX - parent->_worldX, dy = _worldY - parent->_worldY;
|
||||
float ia = pd * pid, ib = pb * pid, ic = pc * pid, id = pa * pid;
|
||||
float dx = _worldX - parent->_worldX, dy = _worldY - parent->_worldY;
|
||||
_ax = (dx * ia - dy * ib);
|
||||
_ay = (dy * id - dx * ic);
|
||||
|
||||
float ra, rb, rc, rd;
|
||||
if (_data.getTransformMode() == TransformMode_OnlyTranslation) {
|
||||
ra = _a;
|
||||
rb = _b;
|
||||
rc = _c;
|
||||
rd = _d;
|
||||
} else {
|
||||
switch (_data.getTransformMode()) {
|
||||
case TransformMode_NoRotationOrReflection: {
|
||||
float s = MathUtil::abs(pa * pd - pb * pc) / (pa * pa + pc * pc);
|
||||
float sa = pa / _skeleton.getScaleX();
|
||||
float sc = pc / _skeleton.getScaleY();
|
||||
pb = -sc * s * _skeleton.getScaleX();
|
||||
pd = sa * s * _skeleton.getScaleY();
|
||||
pid = 1 / (pa * pd - pb * pc);
|
||||
ia = pd * pid;
|
||||
ib = pb * pid;
|
||||
break;
|
||||
}
|
||||
case TransformMode_NoScale:
|
||||
case TransformMode_NoScaleOrReflection: {
|
||||
float cos = MathUtil::cosDeg(_rotation), sin = MathUtil::sinDeg(_rotation);
|
||||
pa = (pa * cos + pb * sin) / _skeleton.getScaleX();
|
||||
pc = (pc * cos + pd * sin) / _skeleton.getScaleY();
|
||||
float s = MathUtil::sqrt(pa * pa + pc * pc);
|
||||
if (s > 0.00001) s = 1 / s;
|
||||
pa *= s;
|
||||
pc *= s;
|
||||
s = MathUtil::sqrt(pa * pa + pc * pc);
|
||||
if (_data.getTransformMode() == TransformMode_NoScale &&
|
||||
pid < 0 != (_skeleton.getScaleX() < 0 != _skeleton.getScaleY() < 0))
|
||||
s = -s;
|
||||
float r = MathUtil::Pi / 2 + MathUtil::atan2(pc, pa);
|
||||
pb = MathUtil::cos(r) * s;
|
||||
pd = MathUtil::sin(r) * s;
|
||||
pid = 1 / (pa * pd - pb * pc);
|
||||
ia = pd * pid;
|
||||
ib = pb * pid;
|
||||
ic = pc * pid;
|
||||
id = pa * pid;
|
||||
break;
|
||||
}
|
||||
case TransformMode_Normal:
|
||||
case TransformMode_OnlyTranslation:
|
||||
break;
|
||||
}
|
||||
ra = ia * _a - ib * _c;
|
||||
rb = ia * _b - ib * _d;
|
||||
rc = id * _c - ic * _a;
|
||||
rd = id * _d - ic * _b;
|
||||
}
|
||||
float ra, rb, rc, rd;
|
||||
if (_data.getTransformMode() == TransformMode_OnlyTranslation) {
|
||||
ra = _a;
|
||||
rb = _b;
|
||||
rc = _c;
|
||||
rd = _d;
|
||||
} else {
|
||||
switch (_data.getTransformMode()) {
|
||||
case TransformMode_NoRotationOrReflection: {
|
||||
float s = MathUtil::abs(pa * pd - pb * pc) / (pa * pa + pc * pc);
|
||||
float sa = pa / _skeleton.getScaleX();
|
||||
float sc = pc / _skeleton.getScaleY();
|
||||
pb = -sc * s * _skeleton.getScaleX();
|
||||
pd = sa * s * _skeleton.getScaleY();
|
||||
pid = 1 / (pa * pd - pb * pc);
|
||||
ia = pd * pid;
|
||||
ib = pb * pid;
|
||||
break;
|
||||
}
|
||||
case TransformMode_NoScale:
|
||||
case TransformMode_NoScaleOrReflection: {
|
||||
float cos = MathUtil::cosDeg(_rotation), sin = MathUtil::sinDeg(_rotation);
|
||||
pa = (pa * cos + pb * sin) / _skeleton.getScaleX();
|
||||
pc = (pc * cos + pd * sin) / _skeleton.getScaleY();
|
||||
float s = MathUtil::sqrt(pa * pa + pc * pc);
|
||||
if (s > 0.00001) s = 1 / s;
|
||||
pa *= s;
|
||||
pc *= s;
|
||||
s = MathUtil::sqrt(pa * pa + pc * pc);
|
||||
if (_data.getTransformMode() == TransformMode_NoScale &&
|
||||
pid < 0 != (_skeleton.getScaleX() < 0 != _skeleton.getScaleY() < 0))
|
||||
s = -s;
|
||||
float r = MathUtil::Pi / 2 + MathUtil::atan2(pc, pa);
|
||||
pb = MathUtil::cos(r) * s;
|
||||
pd = MathUtil::sin(r) * s;
|
||||
pid = 1 / (pa * pd - pb * pc);
|
||||
ia = pd * pid;
|
||||
ib = pb * pid;
|
||||
ic = pc * pid;
|
||||
id = pa * pid;
|
||||
break;
|
||||
}
|
||||
case TransformMode_Normal:
|
||||
case TransformMode_OnlyTranslation:
|
||||
break;
|
||||
}
|
||||
ra = ia * _a - ib * _c;
|
||||
rb = ia * _b - ib * _d;
|
||||
rc = id * _c - ic * _a;
|
||||
rd = id * _d - ic * _b;
|
||||
}
|
||||
|
||||
_ashearX = 0;
|
||||
_ashearX = 0;
|
||||
_ascaleX = MathUtil::sqrt(ra * ra + rc * rc);
|
||||
if (_ascaleX > 0.0001f) {
|
||||
float det = ra * rd - rb * rc;
|
||||
_ascaleY = det / _ascaleX;
|
||||
_ashearY = -MathUtil::atan2(ra * rb + rc * rd, det) * MathUtil::Rad_Deg;
|
||||
_arotation = MathUtil::atan2(rc, ra) * MathUtil::Rad_Deg;
|
||||
_ashearY = -MathUtil::atan2(ra * rb + rc * rd, det) * MathUtil::Rad_Deg;
|
||||
_arotation = MathUtil::atan2(rc, ra) * MathUtil::Rad_Deg;
|
||||
} else {
|
||||
_ascaleX = 0;
|
||||
_ascaleY = MathUtil::sqrt(rb * rb + rd * rd);
|
||||
|
||||
@ -47,8 +47,8 @@ BoneData::BoneData(int index, const String &name, BoneData *parent) : _index(ind
|
||||
_transformMode(TransformMode_Normal),
|
||||
_skinRequired(false),
|
||||
_color(),
|
||||
_icon(),
|
||||
_visible(true){
|
||||
_icon(),
|
||||
_visible(true) {
|
||||
assert(index >= 0);
|
||||
assert(_name.length() > 0);
|
||||
}
|
||||
@ -150,18 +150,17 @@ Color &BoneData::getColor() {
|
||||
}
|
||||
|
||||
const String &BoneData::getIcon() {
|
||||
return _icon;
|
||||
return _icon;
|
||||
}
|
||||
|
||||
void BoneData::setIcon(const String &icon) {
|
||||
this->_icon = icon;
|
||||
this->_icon = icon;
|
||||
}
|
||||
|
||||
bool BoneData::isVisible() {
|
||||
return _visible;
|
||||
return _visible;
|
||||
}
|
||||
|
||||
void BoneData::setVisible(bool inValue) {
|
||||
this->_visible = inValue;
|
||||
this->_visible = inValue;
|
||||
}
|
||||
|
||||
|
||||
@ -133,105 +133,104 @@ float CurveTimeline1::getCurveValue(float time) {
|
||||
}
|
||||
|
||||
float CurveTimeline1::getRelativeValue(float time, float alpha, MixBlend blend, float current, float setup) {
|
||||
if (time < _frames[0]) {
|
||||
switch (blend) {
|
||||
case MixBlend_Setup:
|
||||
return setup;
|
||||
case MixBlend_First:
|
||||
return current + (setup - current) * alpha;
|
||||
default:
|
||||
return current;
|
||||
}
|
||||
}
|
||||
float value = getCurveValue(time);
|
||||
switch (blend) {
|
||||
case MixBlend_Setup:
|
||||
return setup + value * alpha;
|
||||
case MixBlend_First:
|
||||
case MixBlend_Replace:
|
||||
value += setup - current;
|
||||
break;
|
||||
case MixBlend_Add:
|
||||
break;
|
||||
}
|
||||
return current + value * alpha;
|
||||
|
||||
if (time < _frames[0]) {
|
||||
switch (blend) {
|
||||
case MixBlend_Setup:
|
||||
return setup;
|
||||
case MixBlend_First:
|
||||
return current + (setup - current) * alpha;
|
||||
default:
|
||||
return current;
|
||||
}
|
||||
}
|
||||
float value = getCurveValue(time);
|
||||
switch (blend) {
|
||||
case MixBlend_Setup:
|
||||
return setup + value * alpha;
|
||||
case MixBlend_First:
|
||||
case MixBlend_Replace:
|
||||
value += setup - current;
|
||||
break;
|
||||
case MixBlend_Add:
|
||||
break;
|
||||
}
|
||||
return current + value * alpha;
|
||||
}
|
||||
|
||||
float CurveTimeline1::getAbsoluteValue(float time, float alpha, MixBlend blend, float current, float setup) {
|
||||
if (time < _frames[0]) {
|
||||
switch (blend) {
|
||||
case MixBlend_Setup:
|
||||
return setup;
|
||||
case MixBlend_First:
|
||||
return current + (setup - current) * alpha;
|
||||
default:
|
||||
return current;
|
||||
}
|
||||
}
|
||||
float value = getCurveValue(time);
|
||||
if (blend == MixBlend_Setup) return setup + (value - setup) * alpha;
|
||||
return current + (value - current) * alpha;
|
||||
if (time < _frames[0]) {
|
||||
switch (blend) {
|
||||
case MixBlend_Setup:
|
||||
return setup;
|
||||
case MixBlend_First:
|
||||
return current + (setup - current) * alpha;
|
||||
default:
|
||||
return current;
|
||||
}
|
||||
}
|
||||
float value = getCurveValue(time);
|
||||
if (blend == MixBlend_Setup) return setup + (value - setup) * alpha;
|
||||
return current + (value - current) * alpha;
|
||||
}
|
||||
|
||||
float CurveTimeline1::getAbsoluteValue(float time, float alpha, MixBlend blend, float current, float setup, float value) {
|
||||
if (time < _frames[0]) {
|
||||
switch (blend) {
|
||||
case MixBlend_Setup:
|
||||
return setup;
|
||||
case MixBlend_First:
|
||||
return current + (setup - current) * alpha;
|
||||
default:
|
||||
return current;
|
||||
}
|
||||
}
|
||||
if (blend == MixBlend_Setup) return setup + (value - setup) * alpha;
|
||||
return current + (value - current) * alpha;
|
||||
if (time < _frames[0]) {
|
||||
switch (blend) {
|
||||
case MixBlend_Setup:
|
||||
return setup;
|
||||
case MixBlend_First:
|
||||
return current + (setup - current) * alpha;
|
||||
default:
|
||||
return current;
|
||||
}
|
||||
}
|
||||
if (blend == MixBlend_Setup) return setup + (value - setup) * alpha;
|
||||
return current + (value - current) * alpha;
|
||||
}
|
||||
|
||||
float CurveTimeline1::getScaleValue(float time, float alpha, MixBlend blend, MixDirection direction, float current,
|
||||
float setup) {
|
||||
if (time < _frames[0]) {
|
||||
switch (blend) {
|
||||
case MixBlend_Setup:
|
||||
return setup;
|
||||
case MixBlend_First:
|
||||
return current + (setup - current) * alpha;
|
||||
default:
|
||||
return current;
|
||||
}
|
||||
}
|
||||
float value = getCurveValue(time) * setup;
|
||||
if (alpha == 1) {
|
||||
if (blend == MixBlend_Add) return current + value - setup;
|
||||
return value;
|
||||
}
|
||||
// Mixing out uses sign of setup or current pose, else use sign of key.
|
||||
if (direction == MixDirection_Out) {
|
||||
switch (blend) {
|
||||
case MixBlend_Setup:
|
||||
return setup + (MathUtil::abs(value) * MathUtil::sign(setup) - setup) * alpha;
|
||||
case MixBlend_First:
|
||||
case MixBlend_Replace:
|
||||
return current + (MathUtil::abs(value) * MathUtil::sign(current) - current) * alpha;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
float s;
|
||||
switch (blend) {
|
||||
case MixBlend_Setup:
|
||||
s = MathUtil::abs(setup) * MathUtil::sign(value);
|
||||
return s + (value - s) * alpha;
|
||||
case MixBlend_First:
|
||||
case MixBlend_Replace:
|
||||
s = MathUtil::abs(current) * MathUtil::sign(value);
|
||||
return s + (value - s) * alpha;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return current + (value - setup) * alpha;
|
||||
float setup) {
|
||||
if (time < _frames[0]) {
|
||||
switch (blend) {
|
||||
case MixBlend_Setup:
|
||||
return setup;
|
||||
case MixBlend_First:
|
||||
return current + (setup - current) * alpha;
|
||||
default:
|
||||
return current;
|
||||
}
|
||||
}
|
||||
float value = getCurveValue(time) * setup;
|
||||
if (alpha == 1) {
|
||||
if (blend == MixBlend_Add) return current + value - setup;
|
||||
return value;
|
||||
}
|
||||
// Mixing out uses sign of setup or current pose, else use sign of key.
|
||||
if (direction == MixDirection_Out) {
|
||||
switch (blend) {
|
||||
case MixBlend_Setup:
|
||||
return setup + (MathUtil::abs(value) * MathUtil::sign(setup) - setup) * alpha;
|
||||
case MixBlend_First:
|
||||
case MixBlend_Replace:
|
||||
return current + (MathUtil::abs(value) * MathUtil::sign(current) - current) * alpha;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
float s;
|
||||
switch (blend) {
|
||||
case MixBlend_Setup:
|
||||
s = MathUtil::abs(setup) * MathUtil::sign(value);
|
||||
return s + (value - s) * alpha;
|
||||
case MixBlend_First:
|
||||
case MixBlend_Replace:
|
||||
s = MathUtil::abs(current) * MathUtil::sign(value);
|
||||
return s + (value - s) * alpha;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return current + (value - setup) * alpha;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -85,15 +85,15 @@ void IkConstraint::apply(Bone &bone, float targetX, float targetY, bool compress
|
||||
default:;
|
||||
}
|
||||
|
||||
float b = bone._data.getLength() * sx;
|
||||
if (b > 0.0001) {
|
||||
float dd = tx * tx + ty * ty;
|
||||
if ((compress && dd < b * b) || (stretch && dd > b * b)) {
|
||||
float s = (MathUtil::sqrt(dd) / b - 1) * alpha + 1;
|
||||
sx *= s;
|
||||
if (uniform) sy *= s;
|
||||
}
|
||||
}
|
||||
float b = bone._data.getLength() * sx;
|
||||
if (b > 0.0001) {
|
||||
float dd = tx * tx + ty * ty;
|
||||
if ((compress && dd < b * b) || (stretch && dd > b * b)) {
|
||||
float s = (MathUtil::sqrt(dd) / b - 1) * alpha + 1;
|
||||
sx *= s;
|
||||
if (uniform) sy *= s;
|
||||
}
|
||||
}
|
||||
}
|
||||
bone.updateWorldTransform(bone._ax, bone._ay, bone._arotation + rotationIK * alpha, sx, sy, bone._ashearX,
|
||||
bone._ashearY);
|
||||
@ -369,10 +369,10 @@ void IkConstraint::setSoftness(float inValue) {
|
||||
}
|
||||
|
||||
void IkConstraint::setToSetupPose() {
|
||||
IkConstraintData &data = this->_data;
|
||||
this->_mix = data._mix;
|
||||
this->_softness = data._softness;
|
||||
this->_bendDirection = data._bendDirection;
|
||||
this->_compress = data._compress;
|
||||
this->_stretch = data._stretch;
|
||||
IkConstraintData &data = this->_data;
|
||||
this->_mix = data._mix;
|
||||
this->_softness = data._softness;
|
||||
this->_bendDirection = data._bendDirection;
|
||||
this->_compress = data._compress;
|
||||
this->_stretch = data._stretch;
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ float MathUtil::atan2(float y, float x) {
|
||||
}
|
||||
|
||||
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.
|
||||
@ -129,5 +129,5 @@ float MathUtil::pow(float a, float b) {
|
||||
}
|
||||
|
||||
float MathUtil::ceil(float v) {
|
||||
return ::ceil(v);
|
||||
return ::ceil(v);
|
||||
}
|
||||
|
||||
@ -91,11 +91,10 @@ void PathConstraint::update(Physics) {
|
||||
Bone *boneP = _bones[i];
|
||||
Bone &bone = *boneP;
|
||||
float setupLength = bone._data.getLength();
|
||||
float x = setupLength * bone._a;
|
||||
float y = setupLength * bone._c;
|
||||
_lengths[i] = MathUtil::sqrt(x * x + y * y);
|
||||
|
||||
}
|
||||
float x = setupLength * bone._a;
|
||||
float y = setupLength * bone._c;
|
||||
_lengths[i] = MathUtil::sqrt(x * x + y * y);
|
||||
}
|
||||
}
|
||||
for (size_t i = 1; i < spacesCount; ++i) {
|
||||
_spaces[i] = spacing;
|
||||
@ -580,10 +579,10 @@ void PathConstraint::setActive(bool inValue) {
|
||||
}
|
||||
|
||||
void PathConstraint::setToSetupPose() {
|
||||
PathConstraintData &data = this->_data;
|
||||
this->_position = data._position;
|
||||
this->_spacing = data._spacing;
|
||||
this->_mixRotate = data._mixRotate;
|
||||
this->_mixX = data._mixX;
|
||||
this->_mixY = data._mixY;
|
||||
PathConstraintData &data = this->_data;
|
||||
this->_position = data._position;
|
||||
this->_spacing = data._spacing;
|
||||
this->_mixRotate = data._mixRotate;
|
||||
this->_mixX = data._mixX;
|
||||
this->_mixY = data._mixY;
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ RTTI_IMPL(PathConstraintMixTimeline, CurveTimeline)
|
||||
|
||||
PathConstraintMixTimeline::PathConstraintMixTimeline(size_t frameCount, size_t bezierCount, int pathConstraintIndex)
|
||||
: CurveTimeline(frameCount, PathConstraintMixTimeline::ENTRIES, bezierCount),
|
||||
_constraintIndex(pathConstraintIndex) {
|
||||
_constraintIndex(pathConstraintIndex) {
|
||||
PropertyId ids[] = {((PropertyId) Property_PathConstraintMix << 32) | pathConstraintIndex};
|
||||
setPropertyIds(ids, 1);
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ RTTI_IMPL(PathConstraintPositionTimeline, CurveTimeline1)
|
||||
PathConstraintPositionTimeline::PathConstraintPositionTimeline(size_t frameCount, size_t bezierCount,
|
||||
int pathConstraintIndex) : CurveTimeline1(frameCount,
|
||||
bezierCount),
|
||||
_constraintIndex(
|
||||
_constraintIndex(
|
||||
pathConstraintIndex) {
|
||||
PropertyId ids[] = {((PropertyId) Property_PathConstraintPosition << 32) | pathConstraintIndex};
|
||||
setPropertyIds(ids, 1);
|
||||
@ -62,5 +62,5 @@ void PathConstraintPositionTimeline::apply(Skeleton &skeleton, float lastTime, f
|
||||
SP_UNUSED(direction);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -59,6 +59,6 @@ void PathConstraintSpacingTimeline::apply(Skeleton &skeleton, float lastTime, fl
|
||||
SP_UNUSED(direction);
|
||||
|
||||
PathConstraint *constraint = skeleton._pathConstraints[_pathConstraintIndex];
|
||||
if (constraint->_active)
|
||||
constraint->_spacing = getAbsoluteValue(time, alpha, blend, constraint->_spacing, constraint->_data._spacing);
|
||||
if (constraint->_active)
|
||||
constraint->_spacing = getAbsoluteValue(time, alpha, blend, constraint->_spacing, constraint->_data._spacing);
|
||||
}
|
||||
|
||||
@ -38,429 +38,429 @@ using namespace spine;
|
||||
|
||||
RTTI_IMPL(PhysicsConstraint, Updatable)
|
||||
|
||||
PhysicsConstraint::PhysicsConstraint(PhysicsConstraintData& data, Skeleton& skeleton)
|
||||
: _data(data), _skeleton(skeleton) {
|
||||
_bone = skeleton.getBones()[data.getBone()->getIndex()];
|
||||
PhysicsConstraint::PhysicsConstraint(PhysicsConstraintData &data, Skeleton &skeleton)
|
||||
: _data(data), _skeleton(skeleton) {
|
||||
_bone = skeleton.getBones()[data.getBone()->getIndex()];
|
||||
|
||||
_inertia = data.getInertia();
|
||||
_strength = data.getStrength();
|
||||
_damping = data.getDamping();
|
||||
_massInverse = data.getMassInverse();
|
||||
_wind = data.getWind();
|
||||
_gravity = data.getGravity();
|
||||
_mix = data.getMix();
|
||||
_inertia = data.getInertia();
|
||||
_strength = data.getStrength();
|
||||
_damping = data.getDamping();
|
||||
_massInverse = data.getMassInverse();
|
||||
_wind = data.getWind();
|
||||
_gravity = data.getGravity();
|
||||
_mix = data.getMix();
|
||||
|
||||
_reset = true;
|
||||
_ux = 0;
|
||||
_uy = 0;
|
||||
_cx = 0;
|
||||
_cy = 0;
|
||||
_tx = 0;
|
||||
_ty = 0;
|
||||
_xOffset = 0;
|
||||
_xVelocity = 0;
|
||||
_yOffset = 0;
|
||||
_yVelocity = 0;
|
||||
_rotateOffset = 0;
|
||||
_rotateVelocity = 0;
|
||||
_scaleOffset = 0;
|
||||
_scaleVelocity = 0;
|
||||
_active = false;
|
||||
_remaining = 0;
|
||||
_lastTime = 0;
|
||||
_reset = true;
|
||||
_ux = 0;
|
||||
_uy = 0;
|
||||
_cx = 0;
|
||||
_cy = 0;
|
||||
_tx = 0;
|
||||
_ty = 0;
|
||||
_xOffset = 0;
|
||||
_xVelocity = 0;
|
||||
_yOffset = 0;
|
||||
_yVelocity = 0;
|
||||
_rotateOffset = 0;
|
||||
_rotateVelocity = 0;
|
||||
_scaleOffset = 0;
|
||||
_scaleVelocity = 0;
|
||||
_active = false;
|
||||
_remaining = 0;
|
||||
_lastTime = 0;
|
||||
}
|
||||
|
||||
PhysicsConstraintData &PhysicsConstraint::getData() {
|
||||
return _data;
|
||||
return _data;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setBone(Bone* bone) {
|
||||
_bone = bone;
|
||||
void PhysicsConstraint::setBone(Bone *bone) {
|
||||
_bone = bone;
|
||||
}
|
||||
|
||||
Bone* PhysicsConstraint::getBone(){
|
||||
return _bone;
|
||||
Bone *PhysicsConstraint::getBone() {
|
||||
return _bone;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setInertia(float value) {
|
||||
_inertia = value;
|
||||
_inertia = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getInertia(){
|
||||
return _inertia;
|
||||
float PhysicsConstraint::getInertia() {
|
||||
return _inertia;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setStrength(float value) {
|
||||
_strength = value;
|
||||
_strength = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getStrength(){
|
||||
return _strength;
|
||||
float PhysicsConstraint::getStrength() {
|
||||
return _strength;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setDamping(float value) {
|
||||
_damping = value;
|
||||
_damping = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getDamping(){
|
||||
return _damping;
|
||||
float PhysicsConstraint::getDamping() {
|
||||
return _damping;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setMassInverse(float value) {
|
||||
_massInverse = value;
|
||||
_massInverse = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getMassInverse(){
|
||||
return _massInverse;
|
||||
float PhysicsConstraint::getMassInverse() {
|
||||
return _massInverse;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setWind(float value) {
|
||||
_wind = value;
|
||||
_wind = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getWind(){
|
||||
return _wind;
|
||||
float PhysicsConstraint::getWind() {
|
||||
return _wind;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setGravity(float value) {
|
||||
_gravity = value;
|
||||
_gravity = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getGravity(){
|
||||
return _gravity;
|
||||
float PhysicsConstraint::getGravity() {
|
||||
return _gravity;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setMix(float value) {
|
||||
_mix = value;
|
||||
_mix = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getMix(){
|
||||
return _mix;
|
||||
float PhysicsConstraint::getMix() {
|
||||
return _mix;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setReset(bool value) {
|
||||
_reset = value;
|
||||
_reset = value;
|
||||
}
|
||||
|
||||
bool PhysicsConstraint::getReset(){
|
||||
return _reset;
|
||||
bool PhysicsConstraint::getReset() {
|
||||
return _reset;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setUx(float value) {
|
||||
_ux = value;
|
||||
_ux = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getUx(){
|
||||
return _ux;
|
||||
float PhysicsConstraint::getUx() {
|
||||
return _ux;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setUy(float value) {
|
||||
_uy = value;
|
||||
_uy = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getUy(){
|
||||
return _uy;
|
||||
float PhysicsConstraint::getUy() {
|
||||
return _uy;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setCx(float value) {
|
||||
_cx = value;
|
||||
_cx = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getCx(){
|
||||
return _cx;
|
||||
float PhysicsConstraint::getCx() {
|
||||
return _cx;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setCy(float value) {
|
||||
_cy = value;
|
||||
_cy = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getCy(){
|
||||
return _cy;
|
||||
float PhysicsConstraint::getCy() {
|
||||
return _cy;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setTx(float value) {
|
||||
_tx = value;
|
||||
_tx = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getTx(){
|
||||
return _tx;
|
||||
float PhysicsConstraint::getTx() {
|
||||
return _tx;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setTy(float value) {
|
||||
_ty = value;
|
||||
_ty = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getTy(){
|
||||
return _ty;
|
||||
float PhysicsConstraint::getTy() {
|
||||
return _ty;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setXOffset(float value) {
|
||||
_xOffset = value;
|
||||
_xOffset = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getXOffset(){
|
||||
return _xOffset;
|
||||
float PhysicsConstraint::getXOffset() {
|
||||
return _xOffset;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setXVelocity(float value) {
|
||||
_xVelocity = value;
|
||||
_xVelocity = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getXVelocity(){
|
||||
return _xVelocity;
|
||||
float PhysicsConstraint::getXVelocity() {
|
||||
return _xVelocity;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setYOffset(float value) {
|
||||
_yOffset = value;
|
||||
_yOffset = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getYOffset(){
|
||||
return _yOffset;
|
||||
float PhysicsConstraint::getYOffset() {
|
||||
return _yOffset;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setYVelocity(float value) {
|
||||
_yVelocity = value;
|
||||
_yVelocity = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getYVelocity(){
|
||||
return _yVelocity;
|
||||
float PhysicsConstraint::getYVelocity() {
|
||||
return _yVelocity;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setRotateOffset(float value) {
|
||||
_rotateOffset = value;
|
||||
_rotateOffset = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getRotateOffset(){
|
||||
return _rotateOffset;
|
||||
float PhysicsConstraint::getRotateOffset() {
|
||||
return _rotateOffset;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setRotateVelocity(float value) {
|
||||
_rotateVelocity = value;
|
||||
_rotateVelocity = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getRotateVelocity(){
|
||||
return _rotateVelocity;
|
||||
float PhysicsConstraint::getRotateVelocity() {
|
||||
return _rotateVelocity;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setScaleOffset(float value) {
|
||||
_scaleOffset = value;
|
||||
_scaleOffset = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getScaleOffset(){
|
||||
return _scaleOffset;
|
||||
float PhysicsConstraint::getScaleOffset() {
|
||||
return _scaleOffset;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setScaleVelocity(float value) {
|
||||
_scaleVelocity = value;
|
||||
_scaleVelocity = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getScaleVelocity(){
|
||||
return _scaleVelocity;
|
||||
float PhysicsConstraint::getScaleVelocity() {
|
||||
return _scaleVelocity;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setActive(bool value) {
|
||||
_active = value;
|
||||
_active = value;
|
||||
}
|
||||
|
||||
bool PhysicsConstraint::isActive(){
|
||||
return _active;
|
||||
bool PhysicsConstraint::isActive() {
|
||||
return _active;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setRemaining(float value) {
|
||||
_remaining = value;
|
||||
_remaining = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getRemaining(){
|
||||
return _remaining;
|
||||
float PhysicsConstraint::getRemaining() {
|
||||
return _remaining;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setLastTime(float value) {
|
||||
_lastTime = value;
|
||||
_lastTime = value;
|
||||
}
|
||||
|
||||
float PhysicsConstraint::getLastTime(){
|
||||
return _lastTime;
|
||||
float PhysicsConstraint::getLastTime() {
|
||||
return _lastTime;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::reset() {
|
||||
_remaining = 0;
|
||||
_lastTime = _skeleton.getTime();
|
||||
_reset = true;
|
||||
_xOffset = 0;
|
||||
_xVelocity = 0;
|
||||
_yOffset = 0;
|
||||
_yVelocity = 0;
|
||||
_rotateOffset = 0;
|
||||
_rotateVelocity = 0;
|
||||
_scaleOffset = 0;
|
||||
_scaleVelocity = 0;
|
||||
_remaining = 0;
|
||||
_lastTime = _skeleton.getTime();
|
||||
_reset = true;
|
||||
_xOffset = 0;
|
||||
_xVelocity = 0;
|
||||
_yOffset = 0;
|
||||
_yVelocity = 0;
|
||||
_rotateOffset = 0;
|
||||
_rotateVelocity = 0;
|
||||
_scaleOffset = 0;
|
||||
_scaleVelocity = 0;
|
||||
}
|
||||
|
||||
void PhysicsConstraint::setToSetupPose() {
|
||||
_inertia = _data.getInertia();
|
||||
_strength = _data.getStrength();
|
||||
_damping = _data.getDamping();
|
||||
_massInverse = _data.getMassInverse();
|
||||
_wind = _data.getWind();
|
||||
_gravity = _data.getGravity();
|
||||
_mix = _data.getMix();
|
||||
_inertia = _data.getInertia();
|
||||
_strength = _data.getStrength();
|
||||
_damping = _data.getDamping();
|
||||
_massInverse = _data.getMassInverse();
|
||||
_wind = _data.getWind();
|
||||
_gravity = _data.getGravity();
|
||||
_mix = _data.getMix();
|
||||
}
|
||||
void PhysicsConstraint::update(Physics physics) {
|
||||
float mix = _mix;
|
||||
if (mix == 0) return;
|
||||
float mix = _mix;
|
||||
if (mix == 0) return;
|
||||
|
||||
bool x = _data._x > 0;
|
||||
bool y = _data._y > 0;
|
||||
bool rotateOrShearX = _data._rotate > 0 || _data._shearX > 0;
|
||||
bool scaleX = _data._scaleX > 0;
|
||||
bool x = _data._x > 0;
|
||||
bool y = _data._y > 0;
|
||||
bool rotateOrShearX = _data._rotate > 0 || _data._shearX > 0;
|
||||
bool scaleX = _data._scaleX > 0;
|
||||
|
||||
Bone* bone = _bone;
|
||||
float l = bone->_data.getLength();
|
||||
Bone *bone = _bone;
|
||||
float l = bone->_data.getLength();
|
||||
|
||||
switch (physics) {
|
||||
case Physics::Physics_None:
|
||||
return;
|
||||
case Physics::Physics_Reset:
|
||||
reset();
|
||||
// Fall through.
|
||||
case Physics::Physics_Update: {
|
||||
_remaining += MathUtil::max(_skeleton.getTime() - _lastTime, 0.0f);
|
||||
_lastTime = _skeleton.getTime();
|
||||
switch (physics) {
|
||||
case Physics::Physics_None:
|
||||
return;
|
||||
case Physics::Physics_Reset:
|
||||
reset();
|
||||
// Fall through.
|
||||
case Physics::Physics_Update: {
|
||||
_remaining += MathUtil::max(_skeleton.getTime() - _lastTime, 0.0f);
|
||||
_lastTime = _skeleton.getTime();
|
||||
|
||||
float bx = bone->_worldX, by = bone->_worldY;
|
||||
if (_reset) {
|
||||
_reset = false;
|
||||
_ux = bx;
|
||||
_uy = by;
|
||||
} else {
|
||||
float remaining = _remaining, i = _inertia, step = _data._step;
|
||||
if (x || y) {
|
||||
if (x) {
|
||||
_xOffset += (_ux - bx) * i;
|
||||
_ux = bx;
|
||||
}
|
||||
if (y) {
|
||||
_yOffset += (_uy - by) * i;
|
||||
_uy = by;
|
||||
}
|
||||
if (remaining >= step) {
|
||||
float m = _massInverse * step, e = _strength, w = _wind * 100, g = _gravity * -100;
|
||||
float d = MathUtil::pow(_damping, 60 * step);
|
||||
do {
|
||||
if (x) {
|
||||
_xVelocity += (w - _xOffset * e) * m;
|
||||
_xOffset += _xVelocity * step;
|
||||
_xVelocity *= d;
|
||||
}
|
||||
if (y) {
|
||||
_yVelocity += (g - _yOffset * e) * m;
|
||||
_yOffset += _yVelocity * step;
|
||||
_yVelocity *= d;
|
||||
}
|
||||
remaining -= step;
|
||||
} while (remaining >= step);
|
||||
}
|
||||
if (x) bone->_worldX += _xOffset * mix * _data._x;
|
||||
if (y) bone->_worldY += _yOffset * mix * _data._y;
|
||||
}
|
||||
float bx = bone->_worldX, by = bone->_worldY;
|
||||
if (_reset) {
|
||||
_reset = false;
|
||||
_ux = bx;
|
||||
_uy = by;
|
||||
} else {
|
||||
float remaining = _remaining, i = _inertia, step = _data._step;
|
||||
if (x || y) {
|
||||
if (x) {
|
||||
_xOffset += (_ux - bx) * i;
|
||||
_ux = bx;
|
||||
}
|
||||
if (y) {
|
||||
_yOffset += (_uy - by) * i;
|
||||
_uy = by;
|
||||
}
|
||||
if (remaining >= step) {
|
||||
float m = _massInverse * step, e = _strength, w = _wind * 100, g = _gravity * -100;
|
||||
float d = MathUtil::pow(_damping, 60 * step);
|
||||
do {
|
||||
if (x) {
|
||||
_xVelocity += (w - _xOffset * e) * m;
|
||||
_xOffset += _xVelocity * step;
|
||||
_xVelocity *= d;
|
||||
}
|
||||
if (y) {
|
||||
_yVelocity += (g - _yOffset * e) * m;
|
||||
_yOffset += _yVelocity * step;
|
||||
_yVelocity *= d;
|
||||
}
|
||||
remaining -= step;
|
||||
} while (remaining >= step);
|
||||
}
|
||||
if (x) bone->_worldX += _xOffset * mix * _data._x;
|
||||
if (y) bone->_worldY += _yOffset * mix * _data._y;
|
||||
}
|
||||
|
||||
if (rotateOrShearX || scaleX) {
|
||||
float ca = MathUtil::atan2(bone->_c, bone->_a), c = 0, s = 0, mr = 0;
|
||||
if (rotateOrShearX) {
|
||||
mr = (_data._rotate + _data._shearX) * mix;
|
||||
float dx = _cx - bone->_worldX, dy = _cy - bone->_worldY;
|
||||
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;
|
||||
r = _rotateOffset * mr + ca;
|
||||
c = MathUtil::cos(r);
|
||||
s = MathUtil::sin(r);
|
||||
if (scaleX) {
|
||||
r = l * bone->getWorldScaleX();
|
||||
if (r > 0) _scaleOffset += (dx * c + dy * s) * i / r;
|
||||
}
|
||||
} else {
|
||||
c = MathUtil::cos(ca);
|
||||
s = MathUtil::sin(ca);
|
||||
float r = l * bone->getWorldScaleX();
|
||||
if (r > 0) _scaleOffset += ((this->_cx - bone->_worldX) * c + (this->_cy - bone->_worldY) * s) * i / r;
|
||||
}
|
||||
if (rotateOrShearX || scaleX) {
|
||||
float ca = MathUtil::atan2(bone->_c, bone->_a), c = 0, s = 0, mr = 0;
|
||||
if (rotateOrShearX) {
|
||||
mr = (_data._rotate + _data._shearX) * mix;
|
||||
float dx = _cx - bone->_worldX, dy = _cy - bone->_worldY;
|
||||
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;
|
||||
r = _rotateOffset * mr + ca;
|
||||
c = MathUtil::cos(r);
|
||||
s = MathUtil::sin(r);
|
||||
if (scaleX) {
|
||||
r = l * bone->getWorldScaleX();
|
||||
if (r > 0) _scaleOffset += (dx * c + dy * s) * i / r;
|
||||
}
|
||||
} else {
|
||||
c = MathUtil::cos(ca);
|
||||
s = MathUtil::sin(ca);
|
||||
float r = l * bone->getWorldScaleX();
|
||||
if (r > 0) _scaleOffset += ((this->_cx - bone->_worldX) * c + (this->_cy - bone->_worldY) * s) * i / r;
|
||||
}
|
||||
|
||||
remaining = _remaining;
|
||||
if (remaining >= step) {
|
||||
float m = _massInverse * step, e = _strength;
|
||||
float d = MathUtil::pow(_damping, 60 * step);
|
||||
while(true) {
|
||||
remaining -= step;
|
||||
if (scaleX) {
|
||||
_scaleVelocity += (_wind * c - _gravity * s - _scaleOffset * e) * m;
|
||||
_scaleOffset += _scaleVelocity * step;
|
||||
_scaleVelocity *= d;
|
||||
}
|
||||
if (rotateOrShearX) {
|
||||
_rotateVelocity += (-0.01f * l * (_wind * s + _gravity * c) - _rotateOffset * e) * m;
|
||||
_rotateOffset += _rotateVelocity * step;
|
||||
_rotateVelocity *= d;
|
||||
if (remaining < step) break;
|
||||
float r = _rotateOffset * mr + ca;
|
||||
c = MathUtil::cos(r);
|
||||
s = MathUtil::sin(r);
|
||||
} else if (remaining < step) //
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
_remaining = remaining;
|
||||
}
|
||||
remaining = _remaining;
|
||||
if (remaining >= step) {
|
||||
float m = _massInverse * step, e = _strength;
|
||||
float d = MathUtil::pow(_damping, 60 * step);
|
||||
while (true) {
|
||||
remaining -= step;
|
||||
if (scaleX) {
|
||||
_scaleVelocity += (_wind * c - _gravity * s - _scaleOffset * e) * m;
|
||||
_scaleOffset += _scaleVelocity * step;
|
||||
_scaleVelocity *= d;
|
||||
}
|
||||
if (rotateOrShearX) {
|
||||
_rotateVelocity += (-0.01f * l * (_wind * s + _gravity * c) - _rotateOffset * e) * m;
|
||||
_rotateOffset += _rotateVelocity * step;
|
||||
_rotateVelocity *= d;
|
||||
if (remaining < step) break;
|
||||
float r = _rotateOffset * mr + ca;
|
||||
c = MathUtil::cos(r);
|
||||
s = MathUtil::sin(r);
|
||||
} else if (remaining < step)//
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
_remaining = remaining;
|
||||
}
|
||||
|
||||
_cx = bone->_worldX;
|
||||
_cy = bone->_worldY;
|
||||
break;
|
||||
}
|
||||
case Physics::Physics_Pose: {
|
||||
if (x) bone->_worldX += _xOffset * mix * _data._x;
|
||||
if (y) bone->_worldY += _yOffset * mix * _data._y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_cx = bone->_worldX;
|
||||
_cy = bone->_worldY;
|
||||
break;
|
||||
}
|
||||
case Physics::Physics_Pose: {
|
||||
if (x) bone->_worldX += _xOffset * mix * _data._x;
|
||||
if (y) bone->_worldY += _yOffset * mix * _data._y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (rotateOrShearX) {
|
||||
float o = _rotateOffset * mix, s = 0, c = 0, a = 0;
|
||||
if (_data._shearX > 0) {
|
||||
float r = 0;
|
||||
if (_data._rotate > 0) {
|
||||
r = o * _data._rotate;
|
||||
s = MathUtil::sin(r);
|
||||
c = MathUtil::cos(r);
|
||||
a = bone->_b;
|
||||
bone->_b = c * a - s * bone->_d;
|
||||
bone->_d = s * a + c * bone->_d;
|
||||
}
|
||||
r += o * _data._shearX;
|
||||
s = MathUtil::sin(r);
|
||||
c = MathUtil::cos(r);
|
||||
a = bone->_a;
|
||||
bone->_a = c * a - s * bone->_c;
|
||||
bone->_c = s * a + c * bone->_c;
|
||||
} else {
|
||||
o *= _data._rotate;
|
||||
s = MathUtil::sin(o);
|
||||
c = MathUtil::cos(o);
|
||||
a = bone->_a;
|
||||
bone->_a = c * a - s * bone->_c;
|
||||
bone->_c = s * a + c * bone->_c;
|
||||
a = bone->_b;
|
||||
bone->_b = c * a - s * bone->_d;
|
||||
bone->_d = s * a + c * bone->_d;
|
||||
}
|
||||
}
|
||||
if (scaleX) {
|
||||
float s = 1 + _scaleOffset * mix * _data._scaleX;
|
||||
bone->_a *= s;
|
||||
bone->_c *= s;
|
||||
}
|
||||
if (physics != Physics::Physics_Pose) {
|
||||
_tx = l * bone->_a;
|
||||
_ty = l * bone->_c;
|
||||
}
|
||||
bone->updateAppliedTransform();
|
||||
if (rotateOrShearX) {
|
||||
float o = _rotateOffset * mix, s = 0, c = 0, a = 0;
|
||||
if (_data._shearX > 0) {
|
||||
float r = 0;
|
||||
if (_data._rotate > 0) {
|
||||
r = o * _data._rotate;
|
||||
s = MathUtil::sin(r);
|
||||
c = MathUtil::cos(r);
|
||||
a = bone->_b;
|
||||
bone->_b = c * a - s * bone->_d;
|
||||
bone->_d = s * a + c * bone->_d;
|
||||
}
|
||||
r += o * _data._shearX;
|
||||
s = MathUtil::sin(r);
|
||||
c = MathUtil::cos(r);
|
||||
a = bone->_a;
|
||||
bone->_a = c * a - s * bone->_c;
|
||||
bone->_c = s * a + c * bone->_c;
|
||||
} else {
|
||||
o *= _data._rotate;
|
||||
s = MathUtil::sin(o);
|
||||
c = MathUtil::cos(o);
|
||||
a = bone->_a;
|
||||
bone->_a = c * a - s * bone->_c;
|
||||
bone->_c = s * a + c * bone->_c;
|
||||
a = bone->_b;
|
||||
bone->_b = c * a - s * bone->_d;
|
||||
bone->_d = s * a + c * bone->_d;
|
||||
}
|
||||
}
|
||||
if (scaleX) {
|
||||
float s = 1 + _scaleOffset * mix * _data._scaleX;
|
||||
bone->_a *= s;
|
||||
bone->_c *= s;
|
||||
}
|
||||
if (physics != Physics::Physics_Pose) {
|
||||
_tx = l * bone->_a;
|
||||
_ty = l * bone->_c;
|
||||
}
|
||||
bone->updateAppliedTransform();
|
||||
}
|
||||
|
||||
@ -38,179 +38,178 @@ using namespace spine;
|
||||
RTTI_IMPL(PhysicsConstraintData, ConstraintData)
|
||||
|
||||
PhysicsConstraintData::PhysicsConstraintData(const String &name) : ConstraintData(name),
|
||||
_bone(nullptr),
|
||||
_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),
|
||||
_inertiaGlobal(false), _strengthGlobal(false), _dampingGlobal(false), _massGlobal(false),
|
||||
_windGlobal(false), _gravityGlobal(false), _mixGlobal(false)
|
||||
{
|
||||
_bone(nullptr),
|
||||
_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),
|
||||
_inertiaGlobal(false), _strengthGlobal(false), _dampingGlobal(false), _massGlobal(false),
|
||||
_windGlobal(false), _gravityGlobal(false), _mixGlobal(false) {
|
||||
}
|
||||
|
||||
|
||||
void PhysicsConstraintData::setBone(BoneData* bone) {
|
||||
_bone = bone;
|
||||
void PhysicsConstraintData::setBone(BoneData *bone) {
|
||||
_bone = bone;
|
||||
}
|
||||
|
||||
BoneData* PhysicsConstraintData::getBone() const {
|
||||
return _bone;
|
||||
BoneData *PhysicsConstraintData::getBone() const {
|
||||
return _bone;
|
||||
}
|
||||
|
||||
void PhysicsConstraintData::setX(float x) {
|
||||
_x = x;
|
||||
_x = x;
|
||||
}
|
||||
|
||||
float PhysicsConstraintData::getX() const {
|
||||
return _x;
|
||||
return _x;
|
||||
}
|
||||
|
||||
void PhysicsConstraintData::setY(float y) {
|
||||
_y = y;
|
||||
_y = y;
|
||||
}
|
||||
|
||||
float PhysicsConstraintData::getY() const {
|
||||
return _y;
|
||||
return _y;
|
||||
}
|
||||
|
||||
void PhysicsConstraintData::setRotate(float rotate) {
|
||||
_rotate = rotate;
|
||||
_rotate = rotate;
|
||||
}
|
||||
|
||||
float PhysicsConstraintData::getRotate() const {
|
||||
return _rotate;
|
||||
return _rotate;
|
||||
}
|
||||
|
||||
void PhysicsConstraintData::setScaleX(float scaleX) {
|
||||
_scaleX = scaleX;
|
||||
_scaleX = scaleX;
|
||||
}
|
||||
|
||||
float PhysicsConstraintData::getScaleX() const {
|
||||
return _scaleX;
|
||||
return _scaleX;
|
||||
}
|
||||
|
||||
void PhysicsConstraintData::setShearX(float shearX) {
|
||||
_shearX = shearX;
|
||||
_shearX = shearX;
|
||||
}
|
||||
|
||||
float PhysicsConstraintData::getShearX() const {
|
||||
return _shearX;
|
||||
return _shearX;
|
||||
}
|
||||
|
||||
void PhysicsConstraintData::setStep(float step) {
|
||||
_step = step;
|
||||
_step = step;
|
||||
}
|
||||
|
||||
float PhysicsConstraintData::getStep() const {
|
||||
return _step;
|
||||
return _step;
|
||||
}
|
||||
|
||||
void PhysicsConstraintData::setInertia(float inertia) {
|
||||
_inertia = inertia;
|
||||
_inertia = inertia;
|
||||
}
|
||||
|
||||
float PhysicsConstraintData::getInertia() const {
|
||||
return _inertia;
|
||||
return _inertia;
|
||||
}
|
||||
|
||||
void PhysicsConstraintData::setStrength(float strength) {
|
||||
_strength = strength;
|
||||
_strength = strength;
|
||||
}
|
||||
|
||||
float PhysicsConstraintData::getStrength() const {
|
||||
return _strength;
|
||||
return _strength;
|
||||
}
|
||||
|
||||
void PhysicsConstraintData::setDamping(float damping) {
|
||||
_damping = damping;
|
||||
_damping = damping;
|
||||
}
|
||||
|
||||
float PhysicsConstraintData::getDamping() const {
|
||||
return _damping;
|
||||
return _damping;
|
||||
}
|
||||
|
||||
void PhysicsConstraintData::setMassInverse(float massInverse) {
|
||||
_massInverse = massInverse;
|
||||
_massInverse = massInverse;
|
||||
}
|
||||
|
||||
float PhysicsConstraintData::getMassInverse() const {
|
||||
return _massInverse;
|
||||
return _massInverse;
|
||||
}
|
||||
|
||||
void PhysicsConstraintData::setWind(float wind) {
|
||||
_wind = wind;
|
||||
_wind = wind;
|
||||
}
|
||||
|
||||
float PhysicsConstraintData::getWind() const {
|
||||
return _wind;
|
||||
return _wind;
|
||||
}
|
||||
|
||||
void PhysicsConstraintData::setGravity(float gravity) {
|
||||
_gravity = gravity;
|
||||
_gravity = gravity;
|
||||
}
|
||||
|
||||
float PhysicsConstraintData::getGravity() const {
|
||||
return _gravity;
|
||||
return _gravity;
|
||||
}
|
||||
|
||||
void PhysicsConstraintData::setMix(float mix) {
|
||||
_mix = mix;
|
||||
_mix = mix;
|
||||
}
|
||||
|
||||
float PhysicsConstraintData::getMix() const {
|
||||
return _mix;
|
||||
return _mix;
|
||||
}
|
||||
|
||||
void PhysicsConstraintData::setInertiaGlobal(bool inertiaGlobal) {
|
||||
_inertiaGlobal = inertiaGlobal;
|
||||
_inertiaGlobal = inertiaGlobal;
|
||||
}
|
||||
|
||||
bool PhysicsConstraintData::isInertiaGlobal() const {
|
||||
return _inertiaGlobal;
|
||||
return _inertiaGlobal;
|
||||
}
|
||||
|
||||
void PhysicsConstraintData::setStrengthGlobal(bool strengthGlobal) {
|
||||
_strengthGlobal = strengthGlobal;
|
||||
_strengthGlobal = strengthGlobal;
|
||||
}
|
||||
|
||||
bool PhysicsConstraintData::isStrengthGlobal() const {
|
||||
return _strengthGlobal;
|
||||
return _strengthGlobal;
|
||||
}
|
||||
|
||||
void PhysicsConstraintData::setDampingGlobal(bool dampingGlobal) {
|
||||
_dampingGlobal = dampingGlobal;
|
||||
_dampingGlobal = dampingGlobal;
|
||||
}
|
||||
|
||||
bool PhysicsConstraintData::isDampingGlobal() const {
|
||||
return _dampingGlobal;
|
||||
return _dampingGlobal;
|
||||
}
|
||||
|
||||
void PhysicsConstraintData::setMassGlobal(bool massGlobal) {
|
||||
_massGlobal = massGlobal;
|
||||
_massGlobal = massGlobal;
|
||||
}
|
||||
|
||||
bool PhysicsConstraintData::isMassGlobal() const {
|
||||
return _massGlobal;
|
||||
return _massGlobal;
|
||||
}
|
||||
|
||||
void PhysicsConstraintData::setWindGlobal(bool windGlobal) {
|
||||
_windGlobal = windGlobal;
|
||||
_windGlobal = windGlobal;
|
||||
}
|
||||
|
||||
bool PhysicsConstraintData::isWindGlobal() const {
|
||||
return _windGlobal;
|
||||
return _windGlobal;
|
||||
}
|
||||
|
||||
void PhysicsConstraintData::setGravityGlobal(bool gravityGlobal) {
|
||||
_gravityGlobal = gravityGlobal;
|
||||
_gravityGlobal = gravityGlobal;
|
||||
}
|
||||
|
||||
bool PhysicsConstraintData::isGravityGlobal() const {
|
||||
return _gravityGlobal;
|
||||
return _gravityGlobal;
|
||||
}
|
||||
|
||||
void PhysicsConstraintData::setMixGlobal(bool mixGlobal) {
|
||||
_mixGlobal = mixGlobal;
|
||||
_mixGlobal = mixGlobal;
|
||||
}
|
||||
|
||||
bool PhysicsConstraintData::isMixGlobal() const {
|
||||
return _mixGlobal;
|
||||
return _mixGlobal;
|
||||
}
|
||||
|
||||
@ -52,51 +52,51 @@ RTTI_IMPL(PhysicsConstraintMixTimeline, PhysicsConstraintTimeline)
|
||||
RTTI_IMPL(PhysicsConstraintResetTimeline, Timeline)
|
||||
|
||||
PhysicsConstraintTimeline::PhysicsConstraintTimeline(size_t frameCount, size_t bezierCount,
|
||||
int constraintIndex, Property property) : CurveTimeline1(frameCount, bezierCount),
|
||||
_constraintIndex(constraintIndex) {
|
||||
int constraintIndex, Property property) : CurveTimeline1(frameCount, bezierCount),
|
||||
_constraintIndex(constraintIndex) {
|
||||
PropertyId ids[] = {((PropertyId) property << 32) | constraintIndex};
|
||||
setPropertyIds(ids, 1);
|
||||
}
|
||||
|
||||
void PhysicsConstraintTimeline::apply(Skeleton &skeleton, float, float time, Vector<Event *> *,
|
||||
float alpha, MixBlend blend, MixDirection) {
|
||||
if (_constraintIndex == -1) {
|
||||
float value = time >= _frames[0] ?getCurveValue(time) : 0;
|
||||
float alpha, MixBlend blend, MixDirection) {
|
||||
if (_constraintIndex == -1) {
|
||||
float value = time >= _frames[0] ? getCurveValue(time) : 0;
|
||||
|
||||
Vector<PhysicsConstraint*> &physicsConstraints = skeleton.getPhysicsConstraints();
|
||||
for (size_t i = 0; i < physicsConstraints.size(); i++) {
|
||||
PhysicsConstraint *constraint = physicsConstraints[i];
|
||||
if (constraint->_active && global(constraint->_data))
|
||||
set(constraint, getAbsoluteValue(time, alpha, blend, get(constraint), setup(constraint), value));
|
||||
}
|
||||
} else {
|
||||
PhysicsConstraint *constraint = skeleton.getPhysicsConstraints()[_constraintIndex];
|
||||
if (constraint->_active) set(constraint, getAbsoluteValue(time, alpha, blend, get(constraint), setup(constraint)));
|
||||
}
|
||||
Vector<PhysicsConstraint *> &physicsConstraints = skeleton.getPhysicsConstraints();
|
||||
for (size_t i = 0; i < physicsConstraints.size(); i++) {
|
||||
PhysicsConstraint *constraint = physicsConstraints[i];
|
||||
if (constraint->_active && global(constraint->_data))
|
||||
set(constraint, getAbsoluteValue(time, alpha, blend, get(constraint), setup(constraint), value));
|
||||
}
|
||||
} else {
|
||||
PhysicsConstraint *constraint = skeleton.getPhysicsConstraints()[_constraintIndex];
|
||||
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) {
|
||||
PhysicsConstraint *constraint = nullptr;
|
||||
if (_constraintIndex != -1) {
|
||||
constraint = skeleton.getPhysicsConstraints()[_constraintIndex];
|
||||
if (!constraint->_active) return;
|
||||
}
|
||||
PhysicsConstraint *constraint = nullptr;
|
||||
if (_constraintIndex != -1) {
|
||||
constraint = skeleton.getPhysicsConstraints()[_constraintIndex];
|
||||
if (!constraint->_active) return;
|
||||
}
|
||||
|
||||
if (lastTime > time) { // Apply after lastTime for looped animations.
|
||||
apply(skeleton, lastTime, FLT_MAX, nullptr, alpha, blend, direction);
|
||||
lastTime = -1;
|
||||
} else if (lastTime >= _frames[_frames.size() - 1]) // Last time is after last frame.
|
||||
return;
|
||||
if (time < _frames[0]) return;
|
||||
if (lastTime > time) {// Apply after lastTime for looped animations.
|
||||
apply(skeleton, lastTime, FLT_MAX, nullptr, alpha, blend, direction);
|
||||
lastTime = -1;
|
||||
} else if (lastTime >= _frames[_frames.size() - 1])// Last time is after last frame.
|
||||
return;
|
||||
if (time < _frames[0]) return;
|
||||
|
||||
if (lastTime < _frames[0] || time >= _frames[Animation::search(_frames, lastTime) + 1]) {
|
||||
if (constraint != nullptr)
|
||||
constraint->reset();
|
||||
else {
|
||||
Vector<PhysicsConstraint *> &physicsConstraints = skeleton.getPhysicsConstraints();
|
||||
for (size_t i = 0; i < physicsConstraints.size(); i++) {
|
||||
if (constraint->_active) constraint->reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lastTime < _frames[0] || time >= _frames[Animation::search(_frames, lastTime) + 1]) {
|
||||
if (constraint != nullptr)
|
||||
constraint->reset();
|
||||
else {
|
||||
Vector<PhysicsConstraint *> &physicsConstraints = skeleton.getPhysicsConstraints();
|
||||
for (size_t i = 0; i < physicsConstraints.size(); i++) {
|
||||
if (constraint->_active) constraint->reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -45,10 +45,10 @@ void PointAttachment::computeWorldPosition(Bone &bone, float &ox, float &oy) {
|
||||
}
|
||||
|
||||
float PointAttachment::computeWorldRotation(Bone &bone) {
|
||||
float r = _rotation * MathUtil::Deg_Rad, cosine = MathUtil::cos(r), sine = MathUtil::sin(r);
|
||||
float x = cosine * bone._a + sine * bone._b;
|
||||
float y = cosine * bone._c + sine * bone._d;
|
||||
return MathUtil::atan2Deg(y, x);
|
||||
float r = _rotation * MathUtil::Deg_Rad, cosine = MathUtil::cos(r), sine = MathUtil::sin(r);
|
||||
float x = cosine * bone._a + sine * bone._b;
|
||||
float y = cosine * bone._c + sine * bone._d;
|
||||
return MathUtil::atan2Deg(y, x);
|
||||
}
|
||||
|
||||
float PointAttachment::getX() {
|
||||
|
||||
@ -55,5 +55,5 @@ void RotateTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vecto
|
||||
SP_UNUSED(direction);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -170,7 +170,7 @@ void ScaleXTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vecto
|
||||
SP_UNUSED(pEvents);
|
||||
|
||||
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)
|
||||
@ -190,5 +190,5 @@ void ScaleYTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vecto
|
||||
SP_UNUSED(pEvents);
|
||||
|
||||
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);
|
||||
}
|
||||
@ -136,7 +136,7 @@ void ShearXTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vecto
|
||||
SP_UNUSED(direction);
|
||||
|
||||
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)
|
||||
@ -158,5 +158,5 @@ void ShearYTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vecto
|
||||
SP_UNUSED(direction);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ Skeleton::Skeleton(SkeletonData *skeletonData) : _data(skeletonData),
|
||||
_scaleY(1),
|
||||
_x(0),
|
||||
_y(0),
|
||||
_time(0){
|
||||
_time(0) {
|
||||
_bones.ensureCapacity(_data->getBones().size());
|
||||
for (size_t i = 0; i < _data->getBones().size(); ++i) {
|
||||
BoneData *data = _data->getBones()[i];
|
||||
@ -118,14 +118,14 @@ Skeleton::Skeleton(SkeletonData *skeletonData) : _data(skeletonData),
|
||||
_pathConstraints.add(constraint);
|
||||
}
|
||||
|
||||
_physicsConstraints.ensureCapacity(_data->getPhysicsConstraints().size());
|
||||
for (size_t i = 0; i < _data->getPhysicsConstraints().size(); ++i) {
|
||||
PhysicsConstraintData *data = _data->getPhysicsConstraints()[i];
|
||||
_physicsConstraints.ensureCapacity(_data->getPhysicsConstraints().size());
|
||||
for (size_t i = 0; i < _data->getPhysicsConstraints().size(); ++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();
|
||||
}
|
||||
@ -162,7 +162,7 @@ void Skeleton::updateCache() {
|
||||
size_t ikCount = _ikConstraints.size();
|
||||
size_t transformCount = _transformConstraints.size();
|
||||
size_t pathCount = _pathConstraints.size();
|
||||
size_t physicsCount = _physicsConstraints.size();
|
||||
size_t physicsCount = _physicsConstraints.size();
|
||||
|
||||
size_t constraintCount = ikCount + transformCount + pathCount + physicsCount;
|
||||
|
||||
@ -196,14 +196,14 @@ continue_outer:
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t ii = 0; ii < pathCount; ++ii) {
|
||||
PhysicsConstraint *constraint = _physicsConstraints[ii];
|
||||
if (constraint->getData().getOrder() == i) {
|
||||
sortPhysicsConstraint(constraint);
|
||||
i++;
|
||||
goto continue_outer;
|
||||
}
|
||||
}
|
||||
for (size_t ii = 0; ii < pathCount; ++ii) {
|
||||
PhysicsConstraint *constraint = _physicsConstraints[ii];
|
||||
if (constraint->getData().getOrder() == i) {
|
||||
sortPhysicsConstraint(constraint);
|
||||
i++;
|
||||
goto continue_outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
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->_worldY = pc * _x + pd * _y + parent->_worldY;
|
||||
|
||||
float rx = (rootBone->_rotation + rootBone->_shearX) * MathUtil::Deg_Rad;
|
||||
float ry = (rootBone->_rotation + 90 + rootBone->_shearY) * MathUtil::Deg_Rad;
|
||||
float la = MathUtil::cos(rx) * rootBone->_scaleX;
|
||||
float lb = MathUtil::cos(ry) * rootBone->_scaleY;
|
||||
float lc = MathUtil::sin(rx) * rootBone->_scaleX;
|
||||
float ld = MathUtil::sin(ry) * rootBone->_scaleY;
|
||||
float rx = (rootBone->_rotation + rootBone->_shearX) * MathUtil::Deg_Rad;
|
||||
float ry = (rootBone->_rotation + 90 + rootBone->_shearY) * MathUtil::Deg_Rad;
|
||||
float la = MathUtil::cos(rx) * rootBone->_scaleX;
|
||||
float lb = MathUtil::cos(ry) * rootBone->_scaleY;
|
||||
float lc = MathUtil::sin(rx) * rootBone->_scaleX;
|
||||
float ld = MathUtil::sin(ry) * rootBone->_scaleY;
|
||||
rootBone->_a = (pa * la + pb * lc) * _scaleX;
|
||||
rootBone->_b = (pa * lb + pb * ld) * _scaleX;
|
||||
rootBone->_c = (pc * la + pd * lc) * _scaleY;
|
||||
@ -293,9 +293,9 @@ void Skeleton::setBonesToSetupPose() {
|
||||
_pathConstraints[i]->setToSetupPose();
|
||||
}
|
||||
|
||||
for (size_t i = 0, n = _physicsConstraints.size(); i < n; ++i) {
|
||||
_physicsConstraints[i]->setToSetupPose();
|
||||
}
|
||||
for (size_t i = 0, n = _physicsConstraints.size(); i < n; ++i) {
|
||||
_physicsConstraints[i]->setToSetupPose();
|
||||
}
|
||||
}
|
||||
|
||||
void Skeleton::setSlotsToSetupPose() {
|
||||
@ -644,15 +644,15 @@ void Skeleton::sortTransformConstraint(TransformConstraint *constraint) {
|
||||
}
|
||||
|
||||
void Skeleton::sortPhysicsConstraint(PhysicsConstraint *constraint) {
|
||||
Bone *bone = constraint->getBone();
|
||||
constraint->_active = bone->_active && (!constraint->_data.isSkinRequired() ||
|
||||
(_skin && _skin->_constraints.contains(&constraint->_data)));
|
||||
if (!constraint->_active) return;
|
||||
Bone *bone = constraint->getBone();
|
||||
constraint->_active = bone->_active && (!constraint->_data.isSkinRequired() ||
|
||||
(_skin && _skin->_constraints.contains(&constraint->_data)));
|
||||
if (!constraint->_active) return;
|
||||
|
||||
sortBone(bone);
|
||||
_updateCache.add(constraint);
|
||||
sortReset(bone->getChildren());
|
||||
bone->_sorted = true;
|
||||
sortBone(bone);
|
||||
_updateCache.add(constraint);
|
||||
sortReset(bone->getChildren());
|
||||
bone->_sorted = true;
|
||||
}
|
||||
|
||||
void Skeleton::sortPathConstraintAttachment(Skin *skin, size_t slotIndex, Bone &slotBone) {
|
||||
@ -701,14 +701,13 @@ void Skeleton::sortReset(Vector<Bone *> &bones) {
|
||||
}
|
||||
|
||||
float Skeleton::getTime() {
|
||||
return _time;
|
||||
return _time;
|
||||
}
|
||||
|
||||
void Skeleton::setTime(float time) {
|
||||
_time = time;
|
||||
_time = time;
|
||||
}
|
||||
|
||||
void Skeleton::update(float delta) {
|
||||
_time += delta;
|
||||
_time += delta;
|
||||
}
|
||||
|
||||
|
||||
@ -67,7 +67,7 @@ SkeletonData::~SkeletonData() {
|
||||
ContainerUtil::cleanUpVectorOfPointers(_ikConstraints);
|
||||
ContainerUtil::cleanUpVectorOfPointers(_transformConstraints);
|
||||
ContainerUtil::cleanUpVectorOfPointers(_pathConstraints);
|
||||
ContainerUtil::cleanUpVectorOfPointers(_physicsConstraints);
|
||||
ContainerUtil::cleanUpVectorOfPointers(_physicsConstraints);
|
||||
for (size_t i = 0; i < _strings.size(); i++) {
|
||||
SpineExtension::free(_strings[i], __FILE__, __LINE__);
|
||||
}
|
||||
@ -106,7 +106,7 @@ PathConstraintData *SkeletonData::findPathConstraint(const String &constraintNam
|
||||
}
|
||||
|
||||
PhysicsConstraintData *SkeletonData::findPhysicsConstraint(const String &constraintName) {
|
||||
return ContainerUtil::findWithName(_physicsConstraints, constraintName);
|
||||
return ContainerUtil::findWithName(_physicsConstraints, constraintName);
|
||||
}
|
||||
|
||||
const String &SkeletonData::getName() {
|
||||
@ -158,7 +158,7 @@ Vector<PathConstraintData *> &SkeletonData::getPathConstraints() {
|
||||
}
|
||||
|
||||
Vector<PhysicsConstraintData *> &SkeletonData::getPhysicsConstraints() {
|
||||
return _physicsConstraints;
|
||||
return _physicsConstraints;
|
||||
}
|
||||
|
||||
float SkeletonData::getX() {
|
||||
|
||||
@ -41,7 +41,7 @@ SlotData::SlotData(int index, const String &name, BoneData &boneData) : _index(i
|
||||
_hasDarkColor(false),
|
||||
_attachmentName(),
|
||||
_blendMode(BlendMode_Normal),
|
||||
_visible(true) {
|
||||
_visible(true) {
|
||||
assert(_index >= 0);
|
||||
assert(_name.length() > 0);
|
||||
}
|
||||
@ -91,9 +91,9 @@ void SlotData::setBlendMode(BlendMode inValue) {
|
||||
}
|
||||
|
||||
bool SlotData::isVisible() {
|
||||
return _visible;
|
||||
return _visible;
|
||||
}
|
||||
|
||||
void SlotData::setVisible(bool inValue) {
|
||||
this->_visible = inValue;
|
||||
this->_visible = inValue;
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ TransformConstraintTimeline::TransformConstraintTimeline(size_t frameCount, size
|
||||
int transformConstraintIndex) : CurveTimeline(frameCount,
|
||||
TransformConstraintTimeline::ENTRIES,
|
||||
bezierCount),
|
||||
_constraintIndex(
|
||||
_constraintIndex(
|
||||
transformConstraintIndex) {
|
||||
PropertyId ids[] = {((PropertyId) Property_TransformConstraint << 32) | transformConstraintIndex};
|
||||
setPropertyIds(ids, 1);
|
||||
|
||||
@ -136,7 +136,7 @@ void TranslateXTimeline::apply(Skeleton &skeleton, float lastTime, float time, V
|
||||
SP_UNUSED(direction);
|
||||
|
||||
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)
|
||||
@ -158,5 +158,5 @@ void TranslateYTimeline::apply(Skeleton &skeleton, float lastTime, float time, V
|
||||
SP_UNUSED(direction);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user