C89 fixes.

This commit is contained in:
NathanSweet 2014-08-31 16:21:52 +02:00
parent 94690dfd2e
commit b327a803e0
6 changed files with 44 additions and 20 deletions

View File

@ -84,6 +84,8 @@
<ClInclude Include="include\spine\Event.h" />
<ClInclude Include="include\spine\EventData.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\RegionAttachment.h" />
<ClInclude Include="include\spine\Skeleton.h" />
@ -111,6 +113,8 @@
<ClCompile Include="src\spine\Event.c" />
<ClCompile Include="src\spine\EventData.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\MeshAttachment.c" />
<ClCompile Include="src\spine\RegionAttachment.c" />

View File

@ -90,6 +90,12 @@
<ClInclude Include="include\spine\spine.h">
<Filter>Header Files</Filter>
</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>
<ClCompile Include="src\spine\Atlas.c">
@ -164,5 +170,11 @@
<ClCompile Include="src\spine\SkinnedMeshAttachment.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\spine\IkConstraint.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\spine\IkConstraintData.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -752,6 +752,7 @@ static const int IKCONSTRAINT_FRAME_BEND_DIRECTION = 2;
void _spIkConstraintTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time,
spEvent** firedEvents, int* eventsCount, float alpha) {
int frameIndex;
float prevFrameMix, frameTime, percent, mix;
spIkConstraint* ikConstraint;
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. */
frameIndex = binarySearch(self->frames, self->framesCount, time, 3);
float prevFrameMix = self->frames[frameIndex - 2];
float frameTime = self->frames[frameIndex];
float percent = 1 - (time - frameTime) / (self->frames[frameIndex + IKCONSTRAINT_PREV_FRAME_TIME] - frameTime);
prevFrameMix = self->frames[frameIndex - 2];
frameTime = self->frames[frameIndex];
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));
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->bendDirection = (int)self->frames[frameIndex + IKCONSTRAINT_FRAME_BEND_DIRECTION];
}
@ -785,5 +786,5 @@ void spIkConstraintTimeline_setFrame (spIkConstraintTimeline* self, int frameInd
frameIndex *= 3;
self->frames[frameIndex] = time;
self->frames[frameIndex + 1] = mix;
self->frames[frameIndex + 2] = bendDirection;
self->frames[frameIndex + 2] = (float)bendDirection;
}

View File

@ -100,13 +100,14 @@ void spBone_setToSetupPose (spBone* self) {
}
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 m00 = self->m00, m11 = self->m11;
if (self->flipX != (self->flipY != yDown)) {
m00 *= -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);
*localY = (dy * m11 * invDet - dx * self->m10 * invDet);
}

View File

@ -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) {
float positionX, positionY, childX, childY, offset, len1, len2, cosDenom, cos, childAngle, adjacent, opposite, parentAngle, rotation;
spBone* parentParent;
float childRotation = child->rotation, parentRotation = parent->rotation;
if (alpha == 0) {
child->rotationIK = childRotation;
parent->rotationIK = parentRotation;
return;
}
float positionX, positionY;
spBone* parentParent = parent->parent;
parentParent = parent->parent;
if (parentParent) {
spBone_worldToLocal(parentParent, targetX, targetY, &positionX, &positionY);
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_worldToLocal(parent, positionX, positionY, &positionX, &positionY);
}
float childX = positionX * parent->worldScaleX, childY = positionY * parent->worldScaleY;
float offset = ATAN2(childY, childX);
float len1 = SQRT(childX * childX + childY * childY);
float len2 = child->data->length * child->worldScaleX;
childX = positionX * parent->worldScaleX;
childY = positionY * parent->worldScaleY;
offset = ATAN2(childY, childX);
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/ */
float cosDenom = 2 * len1 * len2;
cosDenom = 2 * len1 * len2;
if (cosDenom < 0.0001f) {
child->rotationIK = childRotation + (ATAN2(targetY, targetX) * RAD_DEG - parentRotation - childRotation) * alpha;
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)
cos = -1;
else if (cos > 1) cos = 1;
float childAngle = ACOS(cos) * bendDirection;
float adjacent = len1 + len2 * cos, opposite = len2 * SIN(childAngle);
float parentAngle = ATAN2(targetY * adjacent - targetX * opposite, targetX * adjacent + targetY * opposite);
float rotation = (parentAngle - offset) * RAD_DEG - parentRotation;
else if (cos > 1) /**/
cos = 1;
childAngle = ACOS(cos) * bendDirection;
adjacent = len1 + len2 * cos;
opposite = len2 * SIN(childAngle);
parentAngle = ATAN2(targetY * adjacent - targetX * opposite, targetX * adjacent + targetY * opposite);
rotation = (parentAngle - offset) * RAD_DEG - parentRotation;
if (rotation > 180)
rotation -= 360;
else if (rotation < -180) /**/

View File

@ -462,6 +462,8 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
skeletonData->ikConstraintsCount = ik->size;
skeletonData->ikConstraints = MALLOC(spIkConstraintData*, ik->size);
for (ikMap = ik->child, i = 0; ikMap; ikMap = ikMap->next, ++i) {
const char* targetName;
spIkConstraintData* ikConstraintData = spIkConstraintData_create(Json_getString(ikMap, "name", 0));
boneMap = Json_getItem(ikMap, "bones");
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);
if (!ikConstraintData->target) {
spSkeletonData_dispose(skeletonData);