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