mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 15:24:55 +08:00
C89 updates.
This commit is contained in:
parent
d7d08d263a
commit
4d3b007c99
@ -36,6 +36,7 @@
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/spine-c/src}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/spine-c/include}""/>
|
||||
</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"/>
|
||||
</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">
|
||||
@ -45,7 +46,8 @@
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/spine-c/src}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/spine-c/include}""/>
|
||||
</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"/>
|
||||
</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"/>
|
||||
|
||||
@ -68,7 +68,6 @@
|
||||
#define COS(A) cosf(A)
|
||||
#define SQRT(A) sqrtf(A)
|
||||
#define ACOS(A) acosf(A)
|
||||
#define ABS(A) fabsf(A)
|
||||
#else
|
||||
#define FMOD(A,B) (float)fmod(A, B)
|
||||
#define ATAN2(A,B) (float)atan2(A, B)
|
||||
@ -76,7 +75,6 @@
|
||||
#define SIN(A) (float)sin(A)
|
||||
#define SQRT(A) (float)sqrt(A)
|
||||
#define ACOS(A) (float)acos(A)
|
||||
#define ABS(A) ((A) < 0 ? -(A) : (A))
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
@ -64,7 +64,7 @@ void spBone_updateWorldTransformWith (spBone* self, float x, float y, float rota
|
||||
float cosine = COS(radians);
|
||||
float sine = SIN(radians);
|
||||
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;
|
||||
|
||||
CONST_CAST(float, self->appliedRotation) = rotation;
|
||||
@ -117,14 +117,12 @@ void spBone_updateWorldTransformWith (spBone* self, float x, float y, float rota
|
||||
while (p) {
|
||||
cosine = COS(p->appliedRotation * DEG_RAD);
|
||||
sine = SIN(p->appliedRotation * DEG_RAD);
|
||||
float a = pa * cosine + pb * sine;
|
||||
float b = pa * -sine + pb * cosine;
|
||||
float c = pc * cosine + pd * sine;
|
||||
float d = pc * -sine + pd * cosine;
|
||||
pa = a;
|
||||
pb = b;
|
||||
pc = c;
|
||||
pd = d;
|
||||
temp = pa * cosine + pb * sine;
|
||||
pb = pa * -sine + pb * cosine;
|
||||
pa = temp;
|
||||
temp = pc * cosine + pd * sine;
|
||||
pd = pc * -sine + pd * cosine;
|
||||
pc = temp;
|
||||
p = p->parent;
|
||||
}
|
||||
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;
|
||||
pd = 1;
|
||||
while (p) {
|
||||
float za, zb, zc, zd;
|
||||
float r = p->rotation;
|
||||
float psx = p->appliedScaleX, psy = p->appliedScaleY;
|
||||
cosine = COS(r * DEG_RAD);
|
||||
sine = SIN(r * DEG_RAD);
|
||||
float psx = p->appliedScaleX, psy = p->appliedScaleY;
|
||||
float za = cosine * psx, zb = -sine * psy, zc = sine * psx, zd = cosine * psy;
|
||||
float temp = pa * za + pb * zc;
|
||||
za = cosine * psx;
|
||||
zb = -sine * psy;
|
||||
zc = sine * psx;
|
||||
zd = cosine * psy;
|
||||
temp = pa * za + pb * zc;
|
||||
pb = pa * zb + pb * zd;
|
||||
pa = temp;
|
||||
temp = pc * za + pd * zc;
|
||||
|
||||
@ -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) {
|
||||
if (alpha == 0) return;
|
||||
float px = parent->x, py = parent->y, psx = parent->scaleX, psy = parent->scaleY, csx = child->scaleX, cy = child->y;
|
||||
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) {
|
||||
psx = -psx;
|
||||
offset1 = 180;
|
||||
@ -98,8 +100,6 @@ void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float
|
||||
offset2 = 180;
|
||||
} else
|
||||
offset2 = 0;
|
||||
spBone* pp = parent->parent;
|
||||
float tx, ty, dx, dy;
|
||||
if (!pp) {
|
||||
tx = targetX - px;
|
||||
ty = targetY - py;
|
||||
@ -115,27 +115,37 @@ void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float
|
||||
dx = (x * d - y * b) * invDet - px;
|
||||
dy = (y * a - x * c) * invDet - py;
|
||||
}
|
||||
float l1 = SQRT(dx * dx + dy * dy), l2 = child->data->length * csx, a1, a2;
|
||||
if (ABS(psx - psy) <= 0.0001f) {
|
||||
l1 = SQRT(dx * dx + dy * dy);
|
||||
l2 = child->data->length * csx;
|
||||
psd = psx - psy;
|
||||
if (psd < 0 ? -psd : psd <= 0.0001f) {
|
||||
float cos, a, o;
|
||||
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;
|
||||
else if (cos > 1) cos = 1;
|
||||
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);
|
||||
} else {
|
||||
cy = 0;
|
||||
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 c0 = bb * ll + aa * dd - aa * bb, c1 = -2 * bb * l1, c2 = bb - aa;
|
||||
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) {
|
||||
float q = SQRT(d);
|
||||
float q = SQRT(d), r0, r1, ar0, ar1;;
|
||||
if (c1 < 0) q = -q;
|
||||
q = -(c1 + q) / 2;
|
||||
float r0 = q / c2, r1 = c0 / q;
|
||||
float r = ABS(r0) < ABS(r1) ? r0 : r1;
|
||||
r0 = q / c2;
|
||||
r1 = c0 / q;
|
||||
ar0 = r0 < 0 ? -r0 : r0;
|
||||
ar1 = r1 < 0 ? -r1 : r1;
|
||||
r = ar0 < ar1 ? r0 : r1;
|
||||
if (r * r <= dd) {
|
||||
float y1 = SQRT(dd - r * r) * bendDir;
|
||||
a1 = ta - ATAN2(y1, r);
|
||||
@ -143,9 +153,6 @@ void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float
|
||||
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) {
|
||||
maxAngle = 0;
|
||||
maxDist = dist;
|
||||
@ -158,9 +165,9 @@ void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float
|
||||
minDist = dist;
|
||||
minX = x;
|
||||
}
|
||||
float angle = ACOS(-a * l1 / (aa - bb));
|
||||
angle = ACOS(-a * l1 / (aa - bb));
|
||||
x = a * COS(angle) + l1;
|
||||
float y = b * SIN(angle);
|
||||
y = b * SIN(angle);
|
||||
dist = x * x + y * y;
|
||||
if (dist < minDist) {
|
||||
minAngle = angle;
|
||||
@ -182,16 +189,17 @@ void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float
|
||||
a2 = maxAngle * bendDir;
|
||||
}
|
||||
}
|
||||
outer: {}
|
||||
float offset = ATAN2(cy, child->x) * sign2;
|
||||
a1 = (a1 - offset) * RAD_DEG + offset1;
|
||||
a2 = (a2 + offset) * RAD_DEG * sign2 + offset2;
|
||||
if (a1 > 180) a1 -= 360;
|
||||
else if (a1 < -180) a1 += 360;
|
||||
if (a2 > 180) a2 -= 360;
|
||||
else if (a2 < -180) a2 += 360;
|
||||
float rotation = parent->rotation;
|
||||
spBone_updateWorldTransformWith(parent, parent->x, parent->y, rotation + (a1 - rotation) * alpha, parent->scaleX, parent->scaleY);
|
||||
rotation = child->rotation;
|
||||
spBone_updateWorldTransformWith(child, child->x, cy, rotation + (a2 - rotation) * alpha, child->scaleX, child->scaleY);
|
||||
outer: {
|
||||
float offset = ATAN2(cy, child->x) * sign2;
|
||||
a1 = (a1 - offset) * RAD_DEG + offset1;
|
||||
a2 = (a2 + offset) * RAD_DEG * sign2 + offset2;
|
||||
if (a1 > 180) a1 -= 360;
|
||||
else if (a1 < -180) a1 += 360;
|
||||
if (a2 > 180) a2 -= 360;
|
||||
else if (a2 < -180) a2 += 360;
|
||||
r = parent->rotation;
|
||||
spBone_updateWorldTransformWith(parent, parent->x, parent->y, r + (a1 - r) * alpha, parent->scaleX, parent->scaleY);
|
||||
r = child->rotation;
|
||||
spBone_updateWorldTransformWith(child, child->x, cy, r + (a2 - r) * alpha, child->scaleX, child->scaleY);
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,14 +135,12 @@ public class Bone implements Updatable {
|
||||
while (p != null) {
|
||||
cos = MathUtils.cosDeg(p.appliedRotation);
|
||||
sin = MathUtils.sinDeg(p.appliedRotation);
|
||||
float a = pa * cos + pb * sin;
|
||||
float b = pa * -sin + pb * cos;
|
||||
float c = pc * cos + pd * sin;
|
||||
float d = pc * -sin + pd * cos;
|
||||
pa = a;
|
||||
pb = b;
|
||||
pc = c;
|
||||
pd = d;
|
||||
float temp = pa * cos + pb * sin;
|
||||
pb = pa * -sin + pb * cos;
|
||||
pa = temp;
|
||||
temp = pc * cos + pd * sin;
|
||||
pd = pc * -sin + pd * cos;
|
||||
pc = temp;
|
||||
p = p.parent;
|
||||
}
|
||||
a = pa * la + pb * lc;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user