mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 09:16:01 +08:00
[c][c++] port of PathConstraint changes, see #1109.
This commit is contained in:
parent
7da4a9e63c
commit
6f1ef88f1e
@ -84,8 +84,7 @@ void spPathConstraint_apply (spPathConstraint* self) {
|
||||
int/*bool*/ translate = translateMix > 0, rotate = rotateMix > 0;
|
||||
spPathAttachment* attachment = (spPathAttachment*)self->target->attachment;
|
||||
spPathConstraintData* data = self->data;
|
||||
spSpacingMode spacingMode = data->spacingMode;
|
||||
int lengthSpacing = spacingMode == SP_SPACING_MODE_LENGTH;
|
||||
int percentSpacing = data->spacingMode == SP_SPACING_MODE_PERCENT;
|
||||
spRotateMode rotateMode = data->rotateMode;
|
||||
int tangents = rotateMode == SP_ROTATE_MODE_TANGENT, scale = rotateMode == SP_ROTATE_MODE_CHAIN_SCALE;
|
||||
int boneCount = self->bonesCount, spacesCount = tangents ? boneCount : boneCount + 1;
|
||||
@ -104,7 +103,7 @@ void spPathConstraint_apply (spPathConstraint* self) {
|
||||
spaces[0] = 0;
|
||||
lengths = 0;
|
||||
spacing = self->spacing;
|
||||
if (scale || lengthSpacing) {
|
||||
if (scale || !percentSpacing) {
|
||||
if (scale) {
|
||||
if (self->lengthsCount != boneCount) {
|
||||
if (self->lengths) FREE(self->lengths);
|
||||
@ -113,12 +112,20 @@ void spPathConstraint_apply (spPathConstraint* self) {
|
||||
}
|
||||
lengths = self->lengths;
|
||||
}
|
||||
int lengthSpacing = data->spacingMode == SP_SPACING_MODE_LENGTH;
|
||||
for (i = 0, n = spacesCount - 1; i < n;) {
|
||||
spBone *bone = bones[i];
|
||||
setupLength = bone->data->length;
|
||||
if (setupLength < EPSILON) {
|
||||
if (scale) lengths[i] = 0;
|
||||
spaces[++i] = 0;
|
||||
} else if (percentSpacing) {
|
||||
if (scale) {
|
||||
float x = setupLength * bone->a, y = setupLength * bone->c;
|
||||
float length = SQRT(x * x + y * y);
|
||||
lengths[i] = length;
|
||||
}
|
||||
spaces[++i] = spacing;
|
||||
} else {
|
||||
x = setupLength * bone->a, y = setupLength * bone->c;
|
||||
length = SQRT(x * x + y * y);
|
||||
@ -133,7 +140,7 @@ void spPathConstraint_apply (spPathConstraint* self) {
|
||||
}
|
||||
|
||||
positions = spPathConstraint_computeWorldPositions(self, attachment, spacesCount, tangents,
|
||||
data->positionMode == SP_POSITION_MODE_PERCENT, spacingMode == SP_SPACING_MODE_PERCENT);
|
||||
data->positionMode == SP_POSITION_MODE_PERCENT, percentSpacing);
|
||||
boneX = positions[0], boneY = positions[1], offsetRotation = self->data->offsetRotation;
|
||||
tip = 0;
|
||||
if (offsetRotation == 0)
|
||||
@ -373,7 +380,10 @@ float* spPathConstraint_computeWorldPositions(spPathConstraint* self, spPathAtta
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
}
|
||||
if (percentPosition) position *= pathLength;
|
||||
if (percentPosition)
|
||||
position *= pathLength;
|
||||
else
|
||||
position *= pathLength / path->lengths[curveCount - 1];
|
||||
if (percentSpacing) {
|
||||
for (i = 0; i < spacesCount; i++)
|
||||
spaces[i] *= pathLength;
|
||||
|
||||
@ -86,18 +86,18 @@ void PathConstraint::update() {
|
||||
}
|
||||
|
||||
PathConstraintData &data = _data;
|
||||
SpacingMode spacingMode = data._spacingMode;
|
||||
bool lengthSpacing = spacingMode == SpacingMode_Length;
|
||||
bool percentSpacing = data._spacingMode == SpacingMode_Percent;
|
||||
RotateMode rotateMode = data._rotateMode;
|
||||
bool tangents = rotateMode == RotateMode_Tangent, scale = rotateMode == RotateMode_ChainScale;
|
||||
size_t boneCount = _bones.size();
|
||||
int spacesCount = static_cast<int>(tangents ? boneCount : boneCount + 1);
|
||||
_spaces.setSize(spacesCount, 0);
|
||||
float spacing = _spacing;
|
||||
if (scale || lengthSpacing) {
|
||||
if (scale || !percentSpacing) {
|
||||
if (scale) {
|
||||
_lengths.setSize(boneCount, 0);
|
||||
}
|
||||
bool lengthSpacing = data._spacingMode == SpacingMode_Length;
|
||||
|
||||
for (int i = 0, n = spacesCount - 1; i < n;) {
|
||||
Bone *boneP = _bones[i];
|
||||
@ -108,6 +108,13 @@ void PathConstraint::update() {
|
||||
_lengths[i] = 0;
|
||||
}
|
||||
_spaces[++i] = 0;
|
||||
} else if (percentSpacing) {
|
||||
if (scale) {
|
||||
float x = setupLength * bone._a, y = setupLength * bone._c;
|
||||
float length = MathUtil::sqrt(x * x + y * y);
|
||||
_lengths[i] = length;
|
||||
}
|
||||
_spaces[++i] = spacing;
|
||||
} else {
|
||||
float x = setupLength * bone._a;
|
||||
float y = setupLength * bone._c;
|
||||
@ -127,7 +134,7 @@ void PathConstraint::update() {
|
||||
|
||||
Vector<float>& positions = computeWorldPositions(*attachment, spacesCount, tangents,
|
||||
data.getPositionMode() == PositionMode_Percent,
|
||||
spacingMode == SpacingMode_Percent);
|
||||
percentSpacing);
|
||||
float boneX = positions[0];
|
||||
float boneY = positions[1];
|
||||
float offsetRotation = data.getOffsetRotation();
|
||||
@ -399,6 +406,8 @@ PathConstraint::computeWorldPositions(PathAttachment &path, int spacesCount, boo
|
||||
|
||||
if (percentPosition) {
|
||||
position *= pathLength;
|
||||
} else {
|
||||
position *= pathLength / path.getLengths()[curveCount - 1];
|
||||
}
|
||||
|
||||
if (percentSpacing) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user