C89 updates.

This commit is contained in:
NathanSweet 2016-02-16 20:39:24 +01:00
parent d7d08d263a
commit 4d3b007c99
5 changed files with 59 additions and 51 deletions

View File

@ -36,6 +36,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/spine-c/src}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/spine-c/src}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/spine-c/include}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/spine-c/include}&quot;"/>
</option> </option>
<option id="gnu.cpp.compiler.option.other.other.1185307642" name="Other flags" superClass="gnu.cpp.compiler.option.other.other" value="-c -fmessage-length=0" valueType="string"/>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.564303729" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/> <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.564303729" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool> </tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.debug.613741168" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.debug"> <tool id="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.debug.613741168" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.debug">
@ -45,7 +46,8 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/spine-c/src}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/spine-c/src}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/spine-c/include}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/spine-c/include}&quot;"/>
</option> </option>
<option id="gnu.c.compiler.option.misc.other.1829716988" name="Other flags" superClass="gnu.c.compiler.option.misc.other" value="-c -fmessage-length=0 -std=c89" valueType="string"/> <option id="gnu.c.compiler.option.misc.other.1829716988" name="Other flags" superClass="gnu.c.compiler.option.misc.other" value="-c -fmessage-length=0 -std=c89 -pedantic" valueType="string"/>
<option id="gnu.c.compiler.option.dialect.std.849400720" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" value="gnu.c.compiler.dialect.default" valueType="enumerated"/>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.603555848" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.603555848" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool> </tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.debug.1030541714" name="MinGW C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.debug"/> <tool id="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.debug.1030541714" name="MinGW C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.debug"/>

View File

@ -68,7 +68,6 @@
#define COS(A) cosf(A) #define COS(A) cosf(A)
#define SQRT(A) sqrtf(A) #define SQRT(A) sqrtf(A)
#define ACOS(A) acosf(A) #define ACOS(A) acosf(A)
#define ABS(A) fabsf(A)
#else #else
#define FMOD(A,B) (float)fmod(A, B) #define FMOD(A,B) (float)fmod(A, B)
#define ATAN2(A,B) (float)atan2(A, B) #define ATAN2(A,B) (float)atan2(A, B)
@ -76,7 +75,6 @@
#define SIN(A) (float)sin(A) #define SIN(A) (float)sin(A)
#define SQRT(A) (float)sqrt(A) #define SQRT(A) (float)sqrt(A)
#define ACOS(A) (float)acos(A) #define ACOS(A) (float)acos(A)
#define ABS(A) ((A) < 0 ? -(A) : (A))
#endif #endif
#include <stdlib.h> #include <stdlib.h>

View File

@ -64,7 +64,7 @@ void spBone_updateWorldTransformWith (spBone* self, float x, float y, float rota
float cosine = COS(radians); float cosine = COS(radians);
float sine = SIN(radians); float sine = SIN(radians);
float la = cosine * scaleX, lb = -sine * scaleY, lc = sine * scaleX, ld = cosine * scaleY; float la = cosine * scaleX, lb = -sine * scaleY, lc = sine * scaleX, ld = cosine * scaleY;
float pa, pb, pc, pd; float pa, pb, pc, pd, temp;
spBone* parent = self->parent; spBone* parent = self->parent;
CONST_CAST(float, self->appliedRotation) = rotation; CONST_CAST(float, self->appliedRotation) = rotation;
@ -117,14 +117,12 @@ void spBone_updateWorldTransformWith (spBone* self, float x, float y, float rota
while (p) { while (p) {
cosine = COS(p->appliedRotation * DEG_RAD); cosine = COS(p->appliedRotation * DEG_RAD);
sine = SIN(p->appliedRotation * DEG_RAD); sine = SIN(p->appliedRotation * DEG_RAD);
float a = pa * cosine + pb * sine; temp = pa * cosine + pb * sine;
float b = pa * -sine + pb * cosine; pb = pa * -sine + pb * cosine;
float c = pc * cosine + pd * sine; pa = temp;
float d = pc * -sine + pd * cosine; temp = pc * cosine + pd * sine;
pa = a; pd = pc * -sine + pd * cosine;
pb = b; pc = temp;
pc = c;
pd = d;
p = p->parent; p = p->parent;
} }
CONST_CAST(float, self->a) = pa * la + pb * lc; CONST_CAST(float, self->a) = pa * la + pb * lc;
@ -146,12 +144,16 @@ void spBone_updateWorldTransformWith (spBone* self, float x, float y, float rota
pc = 0; pc = 0;
pd = 1; pd = 1;
while (p) { while (p) {
float za, zb, zc, zd;
float r = p->rotation; float r = p->rotation;
float psx = p->appliedScaleX, psy = p->appliedScaleY;
cosine = COS(r * DEG_RAD); cosine = COS(r * DEG_RAD);
sine = SIN(r * DEG_RAD); sine = SIN(r * DEG_RAD);
float psx = p->appliedScaleX, psy = p->appliedScaleY; za = cosine * psx;
float za = cosine * psx, zb = -sine * psy, zc = sine * psx, zd = cosine * psy; zb = -sine * psy;
float temp = pa * za + pb * zc; zc = sine * psx;
zd = cosine * psy;
temp = pa * za + pb * zc;
pb = pa * zb + pb * zd; pb = pa * zb + pb * zd;
pa = temp; pa = temp;
temp = pc * za + pd * zc; temp = pc * za + pd * zc;

View File

@ -78,9 +78,11 @@ void spIkConstraint_apply1 (spBone* bone, float targetX, float targetY, float al
} }
void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float targetY, int bendDir, float alpha) { void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float targetY, int bendDir, float alpha) {
if (alpha == 0) return;
float px = parent->x, py = parent->y, psx = parent->scaleX, psy = parent->scaleY, csx = child->scaleX, cy = child->y; float px = parent->x, py = parent->y, psx = parent->scaleX, psy = parent->scaleY, csx = child->scaleX, cy = child->y;
int offset1, offset2, sign2; int offset1, offset2, sign2;
spBone* pp = parent->parent;
float tx, ty, dx, dy, l1, l2, a1, a2, psd, r;
if (alpha == 0) return;
if (psx < 0) { if (psx < 0) {
psx = -psx; psx = -psx;
offset1 = 180; offset1 = 180;
@ -98,8 +100,6 @@ void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float
offset2 = 180; offset2 = 180;
} else } else
offset2 = 0; offset2 = 0;
spBone* pp = parent->parent;
float tx, ty, dx, dy;
if (!pp) { if (!pp) {
tx = targetX - px; tx = targetX - px;
ty = targetY - py; ty = targetY - py;
@ -115,27 +115,37 @@ void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float
dx = (x * d - y * b) * invDet - px; dx = (x * d - y * b) * invDet - px;
dy = (y * a - x * c) * invDet - py; dy = (y * a - x * c) * invDet - py;
} }
float l1 = SQRT(dx * dx + dy * dy), l2 = child->data->length * csx, a1, a2; l1 = SQRT(dx * dx + dy * dy);
if (ABS(psx - psy) <= 0.0001f) { l2 = child->data->length * csx;
psd = psx - psy;
if (psd < 0 ? -psd : psd <= 0.0001f) {
float cos, a, o;
l2 *= psx; l2 *= psx;
float cos = (tx * tx + ty * ty - l1 * l1 - l2 * l2) / (2 * l1 * l2); cos = (tx * tx + ty * ty - l1 * l1 - l2 * l2) / (2 * l1 * l2);
if (cos < -1) cos = -1; if (cos < -1) cos = -1;
else if (cos > 1) cos = 1; else if (cos > 1) cos = 1;
a2 = ACOS(cos) * bendDir; a2 = ACOS(cos) * bendDir;
float a = l1 + l2 * cos, o = l2 * SIN(a2); a = l1 + l2 * cos;
o = l2 * SIN(a2);
a1 = ATAN2(ty * a - tx * o, tx * a + ty * o); a1 = ATAN2(ty * a - tx * o, tx * a + ty * o);
} else { } else {
cy = 0;
float a = psx * l2, b = psy * l2, ta = ATAN2(ty, tx); float a = psx * l2, b = psy * l2, ta = ATAN2(ty, tx);
float aa = a * a, bb = b * b, ll = l1 * l1, dd = tx * tx + ty * ty; float aa = a * a, bb = b * b, ll = l1 * l1, dd = tx * tx + ty * ty;
float c0 = bb * ll + aa * dd - aa * bb, c1 = -2 * bb * l1, c2 = bb - aa; float c0 = bb * ll + aa * dd - aa * bb, c1 = -2 * bb * l1, c2 = bb - aa;
float d = c1 * c1 - 4 * c2 * c0; float d = c1 * c1 - 4 * c2 * c0;
float minAngle = 0, minDist = 999999999, minX = 0, minY = 0;
float maxAngle = 0, maxDist = 0, maxX = 0, maxY = 0;
float x = l1 + a, dist = x * x, angle, y;
cy = 0;
if (d >= 0) { if (d >= 0) {
float q = SQRT(d); float q = SQRT(d), r0, r1, ar0, ar1;;
if (c1 < 0) q = -q; if (c1 < 0) q = -q;
q = -(c1 + q) / 2; q = -(c1 + q) / 2;
float r0 = q / c2, r1 = c0 / q; r0 = q / c2;
float r = ABS(r0) < ABS(r1) ? r0 : r1; r1 = c0 / q;
ar0 = r0 < 0 ? -r0 : r0;
ar1 = r1 < 0 ? -r1 : r1;
r = ar0 < ar1 ? r0 : r1;
if (r * r <= dd) { if (r * r <= dd) {
float y1 = SQRT(dd - r * r) * bendDir; float y1 = SQRT(dd - r * r) * bendDir;
a1 = ta - ATAN2(y1, r); a1 = ta - ATAN2(y1, r);
@ -143,9 +153,6 @@ void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float
goto outer; goto outer;
} }
} }
float minAngle = 0, minDist = 999999999, minX = 0, minY = 0;
float maxAngle = 0, maxDist = 0, maxX = 0, maxY = 0;
float x = l1 + a, dist = x * x;
if (dist > maxDist) { if (dist > maxDist) {
maxAngle = 0; maxAngle = 0;
maxDist = dist; maxDist = dist;
@ -158,9 +165,9 @@ void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float
minDist = dist; minDist = dist;
minX = x; minX = x;
} }
float angle = ACOS(-a * l1 / (aa - bb)); angle = ACOS(-a * l1 / (aa - bb));
x = a * COS(angle) + l1; x = a * COS(angle) + l1;
float y = b * SIN(angle); y = b * SIN(angle);
dist = x * x + y * y; dist = x * x + y * y;
if (dist < minDist) { if (dist < minDist) {
minAngle = angle; minAngle = angle;
@ -182,16 +189,17 @@ void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float
a2 = maxAngle * bendDir; a2 = maxAngle * bendDir;
} }
} }
outer: {} outer: {
float offset = ATAN2(cy, child->x) * sign2; float offset = ATAN2(cy, child->x) * sign2;
a1 = (a1 - offset) * RAD_DEG + offset1; a1 = (a1 - offset) * RAD_DEG + offset1;
a2 = (a2 + offset) * RAD_DEG * sign2 + offset2; a2 = (a2 + offset) * RAD_DEG * sign2 + offset2;
if (a1 > 180) a1 -= 360; if (a1 > 180) a1 -= 360;
else if (a1 < -180) a1 += 360; else if (a1 < -180) a1 += 360;
if (a2 > 180) a2 -= 360; if (a2 > 180) a2 -= 360;
else if (a2 < -180) a2 += 360; else if (a2 < -180) a2 += 360;
float rotation = parent->rotation; r = parent->rotation;
spBone_updateWorldTransformWith(parent, parent->x, parent->y, rotation + (a1 - rotation) * alpha, parent->scaleX, parent->scaleY); spBone_updateWorldTransformWith(parent, parent->x, parent->y, r + (a1 - r) * alpha, parent->scaleX, parent->scaleY);
rotation = child->rotation; r = child->rotation;
spBone_updateWorldTransformWith(child, child->x, cy, rotation + (a2 - rotation) * alpha, child->scaleX, child->scaleY); spBone_updateWorldTransformWith(child, child->x, cy, r + (a2 - r) * alpha, child->scaleX, child->scaleY);
}
} }

View File

@ -135,14 +135,12 @@ public class Bone implements Updatable {
while (p != null) { while (p != null) {
cos = MathUtils.cosDeg(p.appliedRotation); cos = MathUtils.cosDeg(p.appliedRotation);
sin = MathUtils.sinDeg(p.appliedRotation); sin = MathUtils.sinDeg(p.appliedRotation);
float a = pa * cos + pb * sin; float temp = pa * cos + pb * sin;
float b = pa * -sin + pb * cos; pb = pa * -sin + pb * cos;
float c = pc * cos + pd * sin; pa = temp;
float d = pc * -sin + pd * cos; temp = pc * cos + pd * sin;
pa = a; pd = pc * -sin + pd * cos;
pb = b; pc = temp;
pc = c;
pd = d;
p = p.parent; p = p.parent;
} }
a = pa * la + pb * lc; a = pa * la + pb * lc;