mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
C89 fixes.
This commit is contained in:
parent
94690dfd2e
commit
b327a803e0
@ -84,6 +84,8 @@
|
|||||||
<ClInclude Include="include\spine\Event.h" />
|
<ClInclude Include="include\spine\Event.h" />
|
||||||
<ClInclude Include="include\spine\EventData.h" />
|
<ClInclude Include="include\spine\EventData.h" />
|
||||||
<ClInclude Include="include\spine\extension.h" />
|
<ClInclude Include="include\spine\extension.h" />
|
||||||
|
<ClInclude Include="include\spine\IkConstraint.h" />
|
||||||
|
<ClInclude Include="include\spine\IkConstraintData.h" />
|
||||||
<ClInclude Include="include\spine\MeshAttachment.h" />
|
<ClInclude Include="include\spine\MeshAttachment.h" />
|
||||||
<ClInclude Include="include\spine\RegionAttachment.h" />
|
<ClInclude Include="include\spine\RegionAttachment.h" />
|
||||||
<ClInclude Include="include\spine\Skeleton.h" />
|
<ClInclude Include="include\spine\Skeleton.h" />
|
||||||
@ -111,6 +113,8 @@
|
|||||||
<ClCompile Include="src\spine\Event.c" />
|
<ClCompile Include="src\spine\Event.c" />
|
||||||
<ClCompile Include="src\spine\EventData.c" />
|
<ClCompile Include="src\spine\EventData.c" />
|
||||||
<ClCompile Include="src\spine\extension.c" />
|
<ClCompile Include="src\spine\extension.c" />
|
||||||
|
<ClCompile Include="src\spine\IkConstraint.c" />
|
||||||
|
<ClCompile Include="src\spine\IkConstraintData.c" />
|
||||||
<ClCompile Include="src\spine\Json.c" />
|
<ClCompile Include="src\spine\Json.c" />
|
||||||
<ClCompile Include="src\spine\MeshAttachment.c" />
|
<ClCompile Include="src\spine\MeshAttachment.c" />
|
||||||
<ClCompile Include="src\spine\RegionAttachment.c" />
|
<ClCompile Include="src\spine\RegionAttachment.c" />
|
||||||
|
|||||||
@ -90,6 +90,12 @@
|
|||||||
<ClInclude Include="include\spine\spine.h">
|
<ClInclude Include="include\spine\spine.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="include\spine\IkConstraint.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="include\spine\IkConstraintData.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="src\spine\Atlas.c">
|
<ClCompile Include="src\spine\Atlas.c">
|
||||||
@ -164,5 +170,11 @@
|
|||||||
<ClCompile Include="src\spine\SkinnedMeshAttachment.c">
|
<ClCompile Include="src\spine\SkinnedMeshAttachment.c">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\spine\IkConstraint.c">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\spine\IkConstraintData.c">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@ -752,6 +752,7 @@ static const int IKCONSTRAINT_FRAME_BEND_DIRECTION = 2;
|
|||||||
void _spIkConstraintTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time,
|
void _spIkConstraintTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time,
|
||||||
spEvent** firedEvents, int* eventsCount, float alpha) {
|
spEvent** firedEvents, int* eventsCount, float alpha) {
|
||||||
int frameIndex;
|
int frameIndex;
|
||||||
|
float prevFrameMix, frameTime, percent, mix;
|
||||||
spIkConstraint* ikConstraint;
|
spIkConstraint* ikConstraint;
|
||||||
spIkConstraintTimeline* self = (spIkConstraintTimeline*)timeline;
|
spIkConstraintTimeline* self = (spIkConstraintTimeline*)timeline;
|
||||||
|
|
||||||
@ -767,12 +768,12 @@ void _spIkConstraintTimeline_apply (const spTimeline* timeline, spSkeleton* skel
|
|||||||
|
|
||||||
/* Interpolate between the previous frame and the current frame. */
|
/* Interpolate between the previous frame and the current frame. */
|
||||||
frameIndex = binarySearch(self->frames, self->framesCount, time, 3);
|
frameIndex = binarySearch(self->frames, self->framesCount, time, 3);
|
||||||
float prevFrameMix = self->frames[frameIndex - 2];
|
prevFrameMix = self->frames[frameIndex - 2];
|
||||||
float frameTime = self->frames[frameIndex];
|
frameTime = self->frames[frameIndex];
|
||||||
float percent = 1 - (time - frameTime) / (self->frames[frameIndex + IKCONSTRAINT_PREV_FRAME_TIME] - frameTime);
|
percent = 1 - (time - frameTime) / (self->frames[frameIndex + IKCONSTRAINT_PREV_FRAME_TIME] - frameTime);
|
||||||
percent = spCurveTimeline_getCurvePercent(SUPER(self), frameIndex / 3 - 1, percent < 0 ? 0 : (percent > 1 ? 1 : percent));
|
percent = spCurveTimeline_getCurvePercent(SUPER(self), frameIndex / 3 - 1, percent < 0 ? 0 : (percent > 1 ? 1 : percent));
|
||||||
|
|
||||||
float mix = prevFrameMix + (self->frames[frameIndex + IKCONSTRAINT_FRAME_MIX] - prevFrameMix) * percent;
|
mix = prevFrameMix + (self->frames[frameIndex + IKCONSTRAINT_FRAME_MIX] - prevFrameMix) * percent;
|
||||||
ikConstraint->mix += (mix - ikConstraint->mix) * alpha;
|
ikConstraint->mix += (mix - ikConstraint->mix) * alpha;
|
||||||
ikConstraint->bendDirection = (int)self->frames[frameIndex + IKCONSTRAINT_FRAME_BEND_DIRECTION];
|
ikConstraint->bendDirection = (int)self->frames[frameIndex + IKCONSTRAINT_FRAME_BEND_DIRECTION];
|
||||||
}
|
}
|
||||||
@ -785,5 +786,5 @@ void spIkConstraintTimeline_setFrame (spIkConstraintTimeline* self, int frameInd
|
|||||||
frameIndex *= 3;
|
frameIndex *= 3;
|
||||||
self->frames[frameIndex] = time;
|
self->frames[frameIndex] = time;
|
||||||
self->frames[frameIndex + 1] = mix;
|
self->frames[frameIndex + 1] = mix;
|
||||||
self->frames[frameIndex + 2] = bendDirection;
|
self->frames[frameIndex + 2] = (float)bendDirection;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -100,13 +100,14 @@ void spBone_setToSetupPose (spBone* self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void spBone_worldToLocal (spBone* self, float worldX, float worldY, float* localX, float* localY) {
|
void spBone_worldToLocal (spBone* self, float worldX, float worldY, float* localX, float* localY) {
|
||||||
|
float invDet;
|
||||||
float dx = worldX - self->worldX, dy = worldY - self->worldY;
|
float dx = worldX - self->worldX, dy = worldY - self->worldY;
|
||||||
float m00 = self->m00, m11 = self->m11;
|
float m00 = self->m00, m11 = self->m11;
|
||||||
if (self->flipX != (self->flipY != yDown)) {
|
if (self->flipX != (self->flipY != yDown)) {
|
||||||
m00 *= -1;
|
m00 *= -1;
|
||||||
m11 *= -1;
|
m11 *= -1;
|
||||||
}
|
}
|
||||||
float invDet = 1 / (m00 * m11 - self->m01 * self->m10);
|
invDet = 1 / (m00 * m11 - self->m01 * self->m10);
|
||||||
*localX = (dx * m00 * invDet - dy * self->m01 * invDet);
|
*localX = (dx * m00 * invDet - dy * self->m01 * invDet);
|
||||||
*localY = (dy * m11 * invDet - dx * self->m10 * invDet);
|
*localY = (dy * m11 * invDet - dx * self->m10 * invDet);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -74,14 +74,15 @@ void spIkConstraint_apply1 (spBone* bone, float targetX, float targetY, float al
|
|||||||
}
|
}
|
||||||
|
|
||||||
void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float targetY, int bendDirection, float alpha) {
|
void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float targetY, int bendDirection, float alpha) {
|
||||||
|
float positionX, positionY, childX, childY, offset, len1, len2, cosDenom, cos, childAngle, adjacent, opposite, parentAngle, rotation;
|
||||||
|
spBone* parentParent;
|
||||||
float childRotation = child->rotation, parentRotation = parent->rotation;
|
float childRotation = child->rotation, parentRotation = parent->rotation;
|
||||||
if (alpha == 0) {
|
if (alpha == 0) {
|
||||||
child->rotationIK = childRotation;
|
child->rotationIK = childRotation;
|
||||||
parent->rotationIK = parentRotation;
|
parent->rotationIK = parentRotation;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
float positionX, positionY;
|
parentParent = parent->parent;
|
||||||
spBone* parentParent = parent->parent;
|
|
||||||
if (parentParent) {
|
if (parentParent) {
|
||||||
spBone_worldToLocal(parentParent, targetX, targetY, &positionX, &positionY);
|
spBone_worldToLocal(parentParent, targetX, targetY, &positionX, &positionY);
|
||||||
targetX = (positionX - parent->x) * parentParent->worldScaleX;
|
targetX = (positionX - parent->x) * parentParent->worldScaleX;
|
||||||
@ -97,24 +98,27 @@ void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float
|
|||||||
spBone_localToWorld(child->parent, child->x, child->y, &positionX, &positionY);
|
spBone_localToWorld(child->parent, child->x, child->y, &positionX, &positionY);
|
||||||
spBone_worldToLocal(parent, positionX, positionY, &positionX, &positionY);
|
spBone_worldToLocal(parent, positionX, positionY, &positionX, &positionY);
|
||||||
}
|
}
|
||||||
float childX = positionX * parent->worldScaleX, childY = positionY * parent->worldScaleY;
|
childX = positionX * parent->worldScaleX;
|
||||||
float offset = ATAN2(childY, childX);
|
childY = positionY * parent->worldScaleY;
|
||||||
float len1 = SQRT(childX * childX + childY * childY);
|
offset = ATAN2(childY, childX);
|
||||||
float len2 = child->data->length * child->worldScaleX;
|
len1 = SQRT(childX * childX + childY * childY);
|
||||||
|
len2 = child->data->length * child->worldScaleX;
|
||||||
/* Based on code by Ryan Juckett with permission: Copyright (c) 2008-2009 Ryan Juckett, http://www.ryanjuckett.com/ */
|
/* Based on code by Ryan Juckett with permission: Copyright (c) 2008-2009 Ryan Juckett, http://www.ryanjuckett.com/ */
|
||||||
float cosDenom = 2 * len1 * len2;
|
cosDenom = 2 * len1 * len2;
|
||||||
if (cosDenom < 0.0001f) {
|
if (cosDenom < 0.0001f) {
|
||||||
child->rotationIK = childRotation + (ATAN2(targetY, targetX) * RAD_DEG - parentRotation - childRotation) * alpha;
|
child->rotationIK = childRotation + (ATAN2(targetY, targetX) * RAD_DEG - parentRotation - childRotation) * alpha;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
float cos = (targetX * targetX + targetY * targetY - len1 * len1 - len2 * len2) / cosDenom;
|
cos = (targetX * targetX + targetY * targetY - len1 * len1 - len2 * len2) / cosDenom;
|
||||||
if (cos < -1)
|
if (cos < -1)
|
||||||
cos = -1;
|
cos = -1;
|
||||||
else if (cos > 1) cos = 1;
|
else if (cos > 1) /**/
|
||||||
float childAngle = ACOS(cos) * bendDirection;
|
cos = 1;
|
||||||
float adjacent = len1 + len2 * cos, opposite = len2 * SIN(childAngle);
|
childAngle = ACOS(cos) * bendDirection;
|
||||||
float parentAngle = ATAN2(targetY * adjacent - targetX * opposite, targetX * adjacent + targetY * opposite);
|
adjacent = len1 + len2 * cos;
|
||||||
float rotation = (parentAngle - offset) * RAD_DEG - parentRotation;
|
opposite = len2 * SIN(childAngle);
|
||||||
|
parentAngle = ATAN2(targetY * adjacent - targetX * opposite, targetX * adjacent + targetY * opposite);
|
||||||
|
rotation = (parentAngle - offset) * RAD_DEG - parentRotation;
|
||||||
if (rotation > 180)
|
if (rotation > 180)
|
||||||
rotation -= 360;
|
rotation -= 360;
|
||||||
else if (rotation < -180) /**/
|
else if (rotation < -180) /**/
|
||||||
|
|||||||
@ -462,6 +462,8 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
|
|||||||
skeletonData->ikConstraintsCount = ik->size;
|
skeletonData->ikConstraintsCount = ik->size;
|
||||||
skeletonData->ikConstraints = MALLOC(spIkConstraintData*, ik->size);
|
skeletonData->ikConstraints = MALLOC(spIkConstraintData*, ik->size);
|
||||||
for (ikMap = ik->child, i = 0; ikMap; ikMap = ikMap->next, ++i) {
|
for (ikMap = ik->child, i = 0; ikMap; ikMap = ikMap->next, ++i) {
|
||||||
|
const char* targetName;
|
||||||
|
|
||||||
spIkConstraintData* ikConstraintData = spIkConstraintData_create(Json_getString(ikMap, "name", 0));
|
spIkConstraintData* ikConstraintData = spIkConstraintData_create(Json_getString(ikMap, "name", 0));
|
||||||
boneMap = Json_getItem(ikMap, "bones");
|
boneMap = Json_getItem(ikMap, "bones");
|
||||||
ikConstraintData->bonesCount = boneMap->size;
|
ikConstraintData->bonesCount = boneMap->size;
|
||||||
@ -475,7 +477,7 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* targetName = Json_getString(ikMap, "target", 0);
|
targetName = Json_getString(ikMap, "target", 0);
|
||||||
ikConstraintData->target = spSkeletonData_findBone(skeletonData, targetName);
|
ikConstraintData->target = spSkeletonData_findBone(skeletonData, targetName);
|
||||||
if (!ikConstraintData->target) {
|
if (!ikConstraintData->target) {
|
||||||
spSkeletonData_dispose(skeletonData);
|
spSkeletonData_dispose(skeletonData);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user