[cpp] 4.3 porting WIP

This commit is contained in:
Mario Zechner 2025-06-11 23:13:15 +02:00
parent e5c9f9b86a
commit f71fd28ac9
8 changed files with 197 additions and 290 deletions

View File

@ -38,6 +38,7 @@
namespace spine { namespace spine {
/// Stores a bone's local pose. /// Stores a bone's local pose.
class SP_API BoneLocal : public Pose<BoneLocal> { class SP_API BoneLocal : public Pose<BoneLocal> {
friend class IkConstraint;
friend class BoneTimeline1; friend class BoneTimeline1;
friend class BoneTimeline2; friend class BoneTimeline2;
friend class RotateTimeline; friend class RotateTimeline;

View File

@ -39,6 +39,7 @@ namespace spine {
class Skeleton; class Skeleton;
class SP_API BonePose : public BoneLocal, public Update { class SP_API BonePose : public BoneLocal, public Update {
friend class IkConstraint;
RTTI_DECL RTTI_DECL
public: public:

View File

@ -42,7 +42,7 @@ namespace spine {
RTTI_DECL RTTI_DECL
public: public:
Constraint(D& data, P& pose, P& constrained) : PosedActive<D, P, P>(data, pose, constrained) { Constraint(D& data) : PosedActive<D, P, P>(data) {
} }
virtual ~Constraint() { virtual ~Constraint() {

View File

@ -27,15 +27,14 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
#ifndef Spine_Constraint_h #ifndef Spine_ConstraintData_h
#define Spine_Constraint_h #define Spine_ConstraintData_h
#include <spine/PosedData.h> #include <spine/PosedData.h>
#include <spine/SpineString.h> #include <spine/SpineString.h>
#include <spine/RTTI.h> #include <spine/RTTI.h>
namespace spine { namespace spine {
class Constraint;
class Skeleton; class Skeleton;
/// Base class for all constraint data. /// Base class for all constraint data.
@ -61,4 +60,4 @@ namespace spine {
} }
} }
#endif /* Spine_Constraint_h */ #endif /* Spine_ConstraintData_h */

View File

@ -30,18 +30,18 @@
#ifndef Spine_IkConstraint_h #ifndef Spine_IkConstraint_h
#define Spine_IkConstraint_h #define Spine_IkConstraint_h
#include <spine/Constraint.h>
#include <spine/ConstraintData.h> #include <spine/ConstraintData.h>
#include <spine/IkConstraintData.h>
#include <spine/IkConstraintPose.h>
#include <spine/Vector.h> #include <spine/Vector.h>
namespace spine { namespace spine {
class IkConstraintData;
class Skeleton; class Skeleton;
class Bone; class Bone;
class BonePose;
class SP_API IkConstraint : public Updatable { class SP_API IkConstraint : public Constraint<IkConstraint, IkConstraintData, IkConstraintPose> {
friend class Skeleton; friend class Skeleton;
friend class IkConstraintTimeline; friend class IkConstraintTimeline;
@ -52,66 +52,36 @@ namespace spine {
/// Adjusts the bone rotation so the tip is as close to the target position as possible. The target is specified /// Adjusts the bone rotation so the tip is as close to the target position as possible. The target is specified
/// in the world coordinate system. /// in the world coordinate system.
static void static void
apply(Bone &bone, float targetX, float targetY, bool compress, bool stretch, bool uniform, float alpha); apply(Skeleton& skeleton, BonePose& bone, float targetX, float targetY, bool compress, bool stretch, bool uniform, float mix);
/// Adjusts the parent and child bone rotations so the tip of the child is as close to the target position as /// Adjusts the parent and child bone rotations so the tip of the child is as close to the target position as
/// possible. The target is specified in the world coordinate system. /// possible. The target is specified in the world coordinate system.
/// @param child A direct descendant of the parent bone. /// @param child A direct descendant of the parent bone.
static void static void
apply(Bone &parent, Bone &child, float targetX, float targetY, int bendDir, bool stretch, bool uniform, apply(Skeleton& skeleton, BonePose& parent, BonePose& child, float targetX, float targetY, int bendDirection, bool stretch, bool uniform,
float softness, float softness, float mix);
float alpha);
IkConstraint(IkConstraintData &data, Skeleton &skeleton); IkConstraint(IkConstraintData &data, Skeleton &skeleton);
virtual void update(Physics physics); virtual void update(Skeleton& skeleton, Physics physics);
virtual int getOrder(); virtual void sort(Skeleton& skeleton);
virtual bool isSourceActive();
virtual IkConstraint* copy(Skeleton& skeleton);
IkConstraintData &getData(); IkConstraintData &getData();
Vector<Bone *> &getBones(); Vector<BonePose *> &getBones();
Bone *getTarget(); Bone *getTarget();
void setTarget(Bone *inValue); void setTarget(Bone *inValue);
int getBendDirection();
void setBendDirection(int inValue);
bool getCompress();
void setCompress(bool inValue);
bool getStretch();
void setStretch(bool inValue);
float getMix();
void setMix(float inValue);
float getSoftness();
void setSoftness(float inValue);
bool isActive();
void setActive(bool inValue);
void setToSetupPose();
private: private:
IkConstraintData &_data; Vector<BonePose *> _bones;
Vector<Bone *> _bones;
int _bendDirection;
bool _compress;
bool _stretch;
float _mix;
float _softness;
Bone *_target; Bone *_target;
bool _active;
}; };
} }

View File

@ -37,6 +37,7 @@ namespace spine {
/// Stores the current pose for an IK constraint. /// Stores the current pose for an IK constraint.
class SP_API IkConstraintPose : public Pose<IkConstraintPose> { class SP_API IkConstraintPose : public Pose<IkConstraintPose> {
friend class IkConstraint;
RTTI_DECL RTTI_DECL
public: public:

View File

@ -79,7 +79,7 @@ namespace spine {
} }
void setupPose() { void setupPose() {
_pose.set(*_data.getSetupPose()); _pose.set(_data.getSetupPose());
} }
/// The constraint's setup pose data. /// The constraint's setup pose data.

View File

@ -30,6 +30,8 @@
#include <spine/IkConstraint.h> #include <spine/IkConstraint.h>
#include <spine/Bone.h> #include <spine/Bone.h>
#include <spine/BonePose.h>
#include <spine/ConstraintData.h>
#include <spine/IkConstraintData.h> #include <spine/IkConstraintData.h>
#include <spine/Skeleton.h> #include <spine/Skeleton.h>
@ -37,92 +39,80 @@
using namespace spine; using namespace spine;
RTTI_IMPL(IkConstraint, Updatable) RTTI_IMPL_NOPARENT(IkConstraint)
void IkConstraint::apply(Bone &bone, float targetX, float targetY, bool compress, bool stretch, bool uniform, float alpha) {
Bone *p = bone.getParent();
float pa = p->_a, pb = p->_b, pc = p->_c, pd = p->_d;
float rotationIK = -bone._ashearX - bone._arotation;
float tx = 0, ty = 0;
void IkConstraint::apply(Skeleton& skeleton, BonePose& bone, float targetX, float targetY, bool compress, bool stretch, bool uniform, float mix) {
bone.modifyLocal(skeleton);
BonePose& p = bone._bone->getParent()->getAppliedPose();
float pa = p._a, pb = p._b, pc = p._c, pd = p._d;
float rotationIK = -bone._shearX - bone._rotation, tx, ty;
switch (bone._inherit) { switch (bone._inherit) {
case Inherit_OnlyTranslation: case Inherit_OnlyTranslation:
tx = (targetX - bone._worldX) * MathUtil::sign(bone.getSkeleton().getScaleX()); tx = (targetX - bone._worldX) * MathUtil::sign(skeleton.getScaleX());
ty = (targetY - bone._worldY) * MathUtil::sign(bone.getSkeleton().getScaleY()); ty = (targetY - bone._worldY) * MathUtil::sign(skeleton.getScaleY());
break; break;
case Inherit_NoRotationOrReflection: { case Inherit_NoRotationOrReflection: {
float s = MathUtil::abs(pa * pd - pb * pc) / MathUtil::max(0.0001f, pa * pa + pc * pc); float s = MathUtil::abs(pa * pd - pb * pc) / MathUtil::max(0.0001f, pa * pa + pc * pc);
float sa = pa / bone._skeleton.getScaleX(); float sa = pa / skeleton.getScaleX();
float sc = pc / bone._skeleton.getScaleY(); float sc = pc / skeleton.getScaleY();
pb = -sc * s * bone._skeleton.getScaleX(); pb = -sc * s * skeleton.getScaleX();
pd = sa * s * bone._skeleton.getScaleY(); pd = sa * s * skeleton.getScaleY();
rotationIK += MathUtil::atan2Deg(sc, sa); rotationIK += MathUtil::atan2Deg(sc, sa);
// Fall through.
}
default:
float x = targetX - p._worldX, y = targetY - p._worldY;
float d = pa * pd - pb * pc;
if (MathUtil::abs(d) <= 0.0001f) {
tx = 0;
ty = 0;
} else {
tx = (x * pd - y * pb) / d - bone._x;
ty = (y * pa - x * pc) / d - bone._y;
} }
default:
float x = targetX - p->_worldX, y = targetY - p->_worldY;
float d = pa * pd - pb * pc;
if (MathUtil::abs(d) <= 0.0001f) {
tx = 0;
ty = 0;
} else {
tx = (x * pd - y * pb) / d - bone._ax;
ty = (y * pa - x * pc) / d - bone._ay;
}
} }
rotationIK += MathUtil::atan2Deg(ty, tx); rotationIK += MathUtil::atan2Deg(ty, tx);
if (bone._ascaleX < 0) rotationIK += 180; if (bone._scaleX < 0) rotationIK += 180;
if (rotationIK > 180) rotationIK -= 360; if (rotationIK > 180)
else if (rotationIK < -180) rotationIK -= 360;
else if (rotationIK < -180) //
rotationIK += 360; rotationIK += 360;
float sx = bone._ascaleX; bone._rotation += rotationIK * mix;
float sy = bone._ascaleY;
if (compress || stretch) { if (compress || stretch) {
switch (bone._inherit) { switch (bone._inherit) {
case Inherit_NoScale: case Inherit_NoScale:
case Inherit_NoScaleOrReflection: case Inherit_NoScaleOrReflection:
tx = targetX - bone._worldX; tx = targetX - bone._worldX;
ty = targetY - bone._worldY; ty = targetY - bone._worldY;
default:; break;
default:
break;
} }
float b = bone._bone->getData().getLength() * bone._scaleX;
float b = bone._data.getLength() * sx; if (b > 0.0001f) {
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) * mix + 1;
sx *= s; bone._scaleX *= s;
if (uniform) sy *= s; if (uniform) bone._scaleY *= s;
} }
} }
} }
bone.updateWorldTransform(bone._ax, bone._ay, bone._arotation + rotationIK * alpha, sx, sy, bone._ashearX,
bone._ashearY);
} }
void IkConstraint::apply(Bone &parent, Bone &child, float targetX, float targetY, int bendDir, bool stretch, bool uniform, void IkConstraint::apply(Skeleton& skeleton, BonePose& parent, BonePose& child, float targetX, float targetY, int bendDir,
float softness, bool stretch, bool uniform, float softness, float mix) {
float alpha) {
float a, b, c, d;
float px, py, psx, psy, sx, sy;
float cx, cy, csx, cwx, cwy;
int o1, o2, s2, u;
Bone *pp = parent.getParent();
float tx, ty, dx, dy, dd, l1, l2, a1, a2, r, td, sd, p;
float id, x, y;
if (parent._inherit != Inherit_Normal || child._inherit != Inherit_Normal) return; if (parent._inherit != Inherit_Normal || child._inherit != Inherit_Normal) return;
px = parent._ax; parent.modifyLocal(skeleton);
py = parent._ay; child.modifyLocal(skeleton);
psx = parent._ascaleX; float px = parent._x, py = parent._y, psx = parent._scaleX, psy = parent._scaleY, csx = child._scaleX;
psy = parent._ascaleY; int os1, os2, s2;
sx = psx;
sy = psy;
csx = child._ascaleX;
if (psx < 0) { if (psx < 0) {
psx = -psx; psx = -psx;
o1 = 180; os1 = 180;
s2 = -1; s2 = -1;
} else { } else {
o1 = 0; os1 = 0;
s2 = 1; s2 = 1;
} }
if (psy < 0) { if (psy < 0) {
@ -131,185 +121,166 @@ void IkConstraint::apply(Bone &parent, Bone &child, float targetX, float targetY
} }
if (csx < 0) { if (csx < 0) {
csx = -csx; csx = -csx;
o2 = 180; os2 = 180;
} else } else
o2 = 0; os2 = 0;
r = psx - psy; float cwx, cwy, a = parent._a, b = parent._b, c = parent._c, d = parent._d;
cx = child._ax; bool u = MathUtil::abs(psx - psy) <= 0.0001f;
u = (r < 0 ? -r : r) <= 0.0001f;
if (!u || stretch) { if (!u || stretch) {
cy = 0; child._y = 0;
cwx = parent._a * cx + parent._worldX; cwx = a * child._x + parent._worldX;
cwy = parent._c * cx + parent._worldY; cwy = c * child._x + parent._worldY;
} else { } else {
cy = child._ay; cwx = a * child._x + b * child._y + parent._worldX;
cwx = parent._a * cx + parent._b * cy + parent._worldX; cwy = c * child._x + d * child._y + parent._worldY;
cwy = parent._c * cx + parent._d * cy + parent._worldY;
} }
a = pp->_a; BonePose& pp = parent._bone->getParent()->getAppliedPose();
b = pp->_b; a = pp._a;
c = pp->_c; b = pp._b;
d = pp->_d; c = pp._c;
id = a * d - b * c; d = pp._d;
float id = a * d - b * c, x = cwx - pp._worldX, y = cwy - pp._worldY;
id = MathUtil::abs(id) <= 0.0001f ? 0 : 1 / id; id = MathUtil::abs(id) <= 0.0001f ? 0 : 1 / id;
x = cwx - pp->_worldX; float dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py;
y = cwy - pp->_worldY; float l1 = MathUtil::sqrt(dx * dx + dy * dy), l2 = child._bone->getData().getLength() * csx, a1, a2;
dx = (x * d - y * b) * id - px; if (l1 < 0.0001f) {
dy = (y * a - x * c) * id - py; apply(skeleton, parent, targetX, targetY, false, stretch, false, mix);
l1 = MathUtil::sqrt(dx * dx + dy * dy); child._rotation = 0;
l2 = child._data.getLength() * csx;
if (l1 < 0.0001) {
apply(parent, targetX, targetY, false, stretch, false, alpha);
child.updateWorldTransform(cx, cy, 0, child._ascaleX, child._ascaleY, child._ashearX, child._ashearY);
return; return;
} }
x = targetX - pp->_worldX; x = targetX - pp._worldX;
y = targetY - pp->_worldY; y = targetY - pp._worldY;
tx = (x * d - y * b) * id - px; float tx = (x * d - y * b) * id - px, ty = (y * a - x * c) * id - py;
ty = (y * a - x * c) * id - py; float dd = tx * tx + ty * ty;
dd = tx * tx + ty * ty;
if (softness != 0) { if (softness != 0) {
softness *= psx * (csx + 1) * 0.5f; softness *= psx * (csx + 1) * 0.5f;
td = MathUtil::sqrt(dd); float td = MathUtil::sqrt(dd), sd = td - l1 - l2 * psx + softness;
sd = td - l1 - l2 * psx + softness;
if (sd > 0) { if (sd > 0) {
p = MathUtil::min(1.0f, sd / (softness * 2)) - 1; float p = MathUtil::min(1.0f, sd / (softness * 2)) - 1;
p = (sd - softness * (1 - p * p)) / td; p = (sd - softness * (1 - p * p)) / td;
tx -= p * tx; tx -= p * tx;
ty -= p * ty; ty -= p * ty;
dd = tx * tx + ty * ty; dd = tx * tx + ty * ty;
} }
} }
outer:
if (u) { if (u) {
float cosine;
l2 *= psx; l2 *= psx;
cosine = (dd - l1 * l1 - l2 * l2) / (2 * l1 * l2); float cos = (dd - l1 * l1 - l2 * l2) / (2 * l1 * l2);
if (cosine < -1) { if (cos < -1) {
cosine = -1; cos = -1;
a2 = MathUtil::Pi * bendDir; a2 = MathUtil::Pi * bendDir;
} else if (cosine > 1) { } else if (cos > 1) {
cosine = 1; cos = 1;
a2 = 0; a2 = 0;
if (stretch) { if (stretch) {
a = (MathUtil::sqrt(dd) / (l1 + l2) - 1) * alpha + 1; a = (MathUtil::sqrt(dd) / (l1 + l2) - 1) * mix + 1;
sx *= a; parent._scaleX *= a;
if (uniform) sy *= a; if (uniform) parent._scaleY *= a;
} }
} else } else
a2 = MathUtil::acos(cosine) * bendDir; a2 = MathUtil::acos(cos) * bendDir;
a = l1 + l2 * cosine; a = l1 + l2 * cos;
b = l2 * MathUtil::sin(a2); b = l2 * MathUtil::sin(a2);
a1 = MathUtil::atan2(ty * a - tx * b, tx * a + ty * b); a1 = MathUtil::atan2(ty * a - tx * b, tx * a + ty * b);
} else { } else {
a = psx * l2; a = psx * l2;
b = psy * l2; b = psy * l2;
float aa = a * a, bb = b * b, ll = l1 * l1, ta = MathUtil::atan2(ty, tx); float aa = a * a, bb = b * b, ta = MathUtil::atan2(ty, tx);
float c0 = bb * ll + aa * dd - aa * bb, c1 = -2 * bb * l1, c2 = bb - aa; c = bb * l1 * l1 + aa * dd - aa * bb;
d = c1 * c1 - 4 * c2 * c0; float c1 = -2 * bb * l1, c2 = bb - aa;
d = c1 * c1 - 4 * c2 * c;
if (d >= 0) { if (d >= 0) {
float q = MathUtil::sqrt(d), r0, r1; float q = MathUtil::sqrt(d);
if (c1 < 0) q = -q; if (c1 < 0) q = -q;
q = -(c1 + q) * 0.5f; q = -(c1 + q) * 0.5f;
r0 = q / c2; float r0 = q / c2, r1 = c / q;
r1 = c0 / q; float r = MathUtil::abs(r0) < MathUtil::abs(r1) ? r0 : r1;
r = MathUtil::abs(r0) < MathUtil::abs(r1) ? r0 : r1; r0 = dd - r * r;
if (dd - r * r >= 0) { if (r0 >= 0) {
y = MathUtil::sqrt(dd - r * r) * bendDir; y = MathUtil::sqrt(r0) * bendDir;
a1 = ta - MathUtil::atan2(y, r); a1 = ta - MathUtil::atan2(y, r);
a2 = MathUtil::atan2(y / psy, (r - l1) / psx); a2 = MathUtil::atan2(y / psy, (r - l1) / psx);
goto break_outer; goto outer_break;
} }
} }
{ float minAngle = MathUtil::Pi, minX = l1 - a, minDist = minX * minX, minY = 0;
float minAngle = MathUtil::Pi, minX = l1 - a, minDist = minX * minX, minY = 0; float maxAngle = 0, maxX = l1 + a, maxDist = maxX * maxX, maxY = 0;
float maxAngle = 0, maxX = l1 + a, maxDist = maxX * maxX, maxY = 0; c = -a * l1 / (aa - bb);
c0 = -a * l1 / (aa - bb); if (c >= -1 && c <= 1) {
if (c0 >= -1 && c0 <= 1) { c = MathUtil::acos(c);
c0 = MathUtil::acos(c0); x = a * MathUtil::cos(c) + l1;
x = a * MathUtil::cos(c0) + l1; y = b * MathUtil::sin(c);
y = b * MathUtil::sin(c0); d = x * x + y * y;
d = x * x + y * y; if (d < minDist) {
if (d < minDist) { minAngle = c;
minAngle = c0; minDist = d;
minDist = d; minX = x;
minX = x; minY = y;
minY = y;
}
if (d > maxDist) {
maxAngle = c0;
maxDist = d;
maxX = x;
maxY = y;
}
} }
if (dd <= (minDist + maxDist) * 0.5f) { if (d > maxDist) {
a1 = ta - MathUtil::atan2(minY * bendDir, minX); maxAngle = c;
a2 = minAngle * bendDir; maxDist = d;
} else { maxX = x;
a1 = ta - MathUtil::atan2(maxY * bendDir, maxX); maxY = y;
a2 = maxAngle * bendDir;
} }
} }
if (dd <= (minDist + maxDist) * 0.5f) {
a1 = ta - MathUtil::atan2(minY * bendDir, minX);
a2 = minAngle * bendDir;
} else {
a1 = ta - MathUtil::atan2(maxY * bendDir, maxX);
a2 = maxAngle * bendDir;
}
} }
break_outer : { outer_break:
float os = MathUtil::atan2(cy, cx) * s2; float os = MathUtil::atan2(child._y, child._x) * s2;
a1 = (a1 - os) * MathUtil::Rad_Deg + o1 - parent._arotation; a1 = (a1 - os) * MathUtil::Rad_Deg + os1 - parent._rotation;
if (a1 > 180) a1 -= 360; if (a1 > 180)
else if (a1 < -180) a1 -= 360;
else if (a1 < -180) //
a1 += 360; a1 += 360;
parent.updateWorldTransform(px, py, parent._arotation + a1 * alpha, sx, sy, 0, 0); parent._rotation += a1 * mix;
a2 = ((a2 + os) * MathUtil::Rad_Deg - child._ashearX) * s2 + o2 - child._arotation; a2 = ((a2 + os) * MathUtil::Rad_Deg - child._shearX) * s2 + os2 - child._rotation;
if (a2 > 180) a2 -= 360; if (a2 > 180)
else if (a2 < -180) a2 -= 360;
else if (a2 < -180) //
a2 += 360; a2 += 360;
child.updateWorldTransform(cx, cy, child._arotation + a2 * alpha, child._ascaleX, child._ascaleY, child._rotation += a2 * mix;
child._ashearX, child._ashearY);
}
} }
IkConstraint::IkConstraint(IkConstraintData &data, Skeleton &skeleton) : Updatable(), IkConstraint::IkConstraint(IkConstraintData &data, Skeleton &skeleton) :
_data(data), Constraint<IkConstraint, IkConstraintData, IkConstraintPose>(data),
_bendDirection(data.getBendDirection()), _target(skeleton.findBone(data.getTarget()->getName())) {
_compress(data.getCompress()),
_stretch(data.getStretch()), _bones.ensureCapacity(data.getBones().size());
_mix(data.getMix()), for (size_t i = 0; i < data.getBones().size(); i++) {
_softness(data.getSoftness()), BoneData *boneData = data.getBones()[i];
_target(skeleton.findBone( _bones.add(&skeleton.findBone(boneData->getName())->getAppliedPose());
data.getTarget()->getName())),
_active(false) {
_bones.ensureCapacity(_data.getBones().size());
for (size_t i = 0; i < _data.getBones().size(); i++) {
BoneData *boneData = _data.getBones()[i];
_bones.add(skeleton.findBone(boneData->getName()));
} }
} }
void IkConstraint::update(Physics) { void IkConstraint::update(Skeleton& skeleton, Physics physics) {
if (_mix == 0) return; IkConstraintPose& p = *_applied;
if (p._mix == 0) return;
BonePose& target = _target->getAppliedPose();
switch (_bones.size()) { switch (_bones.size()) {
case 1: { case 1: {
Bone *bone0 = _bones[0]; apply(skeleton, *_bones[0], target._worldX, target._worldY, p._compress, p._stretch, _data._uniform, p._mix);
apply(*bone0, _target->getWorldX(), _target->getWorldY(), _compress, _stretch, _data._uniform, _mix);
} break; } break;
case 2: { case 2: {
Bone *bone0 = _bones[0]; apply(skeleton, *_bones[0], *_bones[1], target._worldX, target._worldY, p._bendDirection, p._stretch, _data._uniform,
Bone *bone1 = _bones[1]; p._softness, p._mix);
apply(*bone0, *bone1, _target->getWorldX(), _target->getWorldY(), _bendDirection, _stretch, _data._uniform,
_softness,
_mix);
} break; } break;
} }
} }
int IkConstraint::getOrder() {
return (int) _data.getOrder();
}
IkConstraintData &IkConstraint::getData() { IkConstraintData &IkConstraint::getData() {
return _data; return _data;
} }
Vector<Bone *> &IkConstraint::getBones() { Vector<BonePose *> &IkConstraint::getBones() {
return _bones; return _bones;
} }
@ -317,63 +288,27 @@ Bone *IkConstraint::getTarget() {
return _target; return _target;
} }
void IkConstraint::setTarget(Bone *inValue) { void IkConstraint::setTarget(Bone *target) {
_target = inValue; _target = target;
} }
int IkConstraint::getBendDirection() { void IkConstraint::sort(Skeleton& skeleton) {
return _bendDirection; skeleton.sortBone(_target);
Bone* parent = _bones[0]->_bone;
skeleton.sortBone(parent);
skeleton.updateCache.add(this);
parent->_sorted = false;
skeleton.sortReset(parent->_children);
skeleton.constrained(parent);
if (_bones.size() > 1) skeleton.constrained(_bones[1]->_bone);
} }
void IkConstraint::setBendDirection(int inValue) { bool IkConstraint::isSourceActive() {
_bendDirection = inValue; return _target->_active;
} }
float IkConstraint::getMix() { IkConstraint* IkConstraint::copy(Skeleton& skeleton) {
return _mix; IkConstraint* copy = new IkConstraint(_data, skeleton);
} copy->_pose.set(_pose);
return copy;
void IkConstraint::setMix(float inValue) {
_mix = inValue;
}
bool IkConstraint::getStretch() {
return _stretch;
}
void IkConstraint::setStretch(bool inValue) {
_stretch = inValue;
}
bool IkConstraint::getCompress() {
return _compress;
}
void IkConstraint::setCompress(bool inValue) {
_compress = inValue;
}
bool IkConstraint::isActive() {
return _active;
}
void IkConstraint::setActive(bool inValue) {
_active = inValue;
}
float IkConstraint::getSoftness() {
return _softness;
}
void IkConstraint::setSoftness(float inValue) {
_softness = 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;
} }