mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
A few fixes and minor improvements.
This commit is contained in:
parent
11c251615d
commit
0f723b9fa7
@ -109,22 +109,21 @@ void spBone_updateWorldTransformWith (spBone* self, float x, float y, float rota
|
||||
CONST_CAST(float, self->c) = pc * la + pd * lc;
|
||||
CONST_CAST(float, self->d) = pc * lb + pd * ld;
|
||||
} else if (self->data->inheritRotation) { /* No scale inheritance. */
|
||||
spBone* p = parent;
|
||||
pa = 1;
|
||||
pb = 0;
|
||||
pc = 0;
|
||||
pd = 1;
|
||||
while (p) {
|
||||
cosine = COS(p->appliedRotation * DEG_RAD);
|
||||
sine = SIN(p->appliedRotation * DEG_RAD);
|
||||
do {
|
||||
cosine = COS(parent->appliedRotation * DEG_RAD);
|
||||
sine = SIN(parent->appliedRotation * DEG_RAD);
|
||||
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;
|
||||
}
|
||||
parent = parent->parent;
|
||||
} while (parent);
|
||||
CONST_CAST(float, self->a) = pa * la + pb * lc;
|
||||
CONST_CAST(float, self->b) = pa * lb + pb * ld;
|
||||
CONST_CAST(float, self->c) = pc * la + pd * lc;
|
||||
@ -138,15 +137,14 @@ void spBone_updateWorldTransformWith (spBone* self, float x, float y, float rota
|
||||
CONST_CAST(float, self->d) = -self->d;
|
||||
}
|
||||
} else if (self->data->inheritScale) { /* No rotation inheritance. */
|
||||
spBone* p = parent;
|
||||
pa = 1;
|
||||
pb = 0;
|
||||
pc = 0;
|
||||
pd = 1;
|
||||
while (p) {
|
||||
do {
|
||||
float za, zb, zc, zd;
|
||||
float r = p->rotation;
|
||||
float psx = p->appliedScaleX, psy = p->appliedScaleY;
|
||||
float r = parent->rotation;
|
||||
float psx = parent->appliedScaleX, psy = parent->appliedScaleY;
|
||||
cosine = COS(r * DEG_RAD);
|
||||
sine = SIN(r * DEG_RAD);
|
||||
za = cosine * psx;
|
||||
@ -170,8 +168,8 @@ void spBone_updateWorldTransformWith (spBone* self, float x, float y, float rota
|
||||
pd = pc * -sine + pd * cosine;
|
||||
pc = temp;
|
||||
|
||||
p = p->parent;
|
||||
}
|
||||
parent = parent->parent;
|
||||
} while (parent);
|
||||
CONST_CAST(float, self->a) = pa * la + pb * lc;
|
||||
CONST_CAST(float, self->b) = pa * lb + pb * ld;
|
||||
CONST_CAST(float, self->c) = pc * la + pd * lc;
|
||||
|
||||
@ -527,8 +527,8 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
|
||||
}
|
||||
|
||||
transformConstraintData->translateMix = Json_getFloat(transformMap, "translateMix", 1);
|
||||
transformConstraintData->x = Json_getFloat(transformMap, "x", 0);
|
||||
transformConstraintData->y = Json_getFloat(transformMap, "y", 0);
|
||||
transformConstraintData->x = Json_getFloat(transformMap, "x", 0) * self->scale;
|
||||
transformConstraintData->y = Json_getFloat(transformMap, "y", 0) * self->scale;
|
||||
|
||||
skeletonData->transformConstraints[i] = transformConstraintData;
|
||||
}
|
||||
|
||||
@ -86,6 +86,11 @@ namespace Spine {
|
||||
SetToSetupPose();
|
||||
}
|
||||
|
||||
/// <summary>Same as {@link #updateWorldTransform()}. This method exists for Bone to implement {@link Updatable}.</summary>
|
||||
public void Update () {
|
||||
UpdateWorldTransform(x, y, rotation, scaleX, scaleY);
|
||||
}
|
||||
|
||||
/// <summary>Computes the world SRT using the parent bone and this bone's local SRT.</summary>
|
||||
public void UpdateWorldTransform () {
|
||||
UpdateWorldTransform(x, y, rotation, scaleX, scaleY);
|
||||
@ -135,24 +140,21 @@ namespace Spine {
|
||||
c = pc * la + pd * lc;
|
||||
d = pc * lb + pd * ld;
|
||||
} else if (data.inheritRotation) { // No scale inheritance.
|
||||
Bone p = parent;
|
||||
pa = 1;
|
||||
pb = 0;
|
||||
pc = 0;
|
||||
pd = 1;
|
||||
while (p != null) {
|
||||
cos = MathUtils.CosDeg(p.appliedRotation);
|
||||
sin = MathUtils.SinDeg(p.appliedRotation);
|
||||
float ta = pa * cos + pb * sin;
|
||||
float tb = pa * -sin + pb * cos;
|
||||
float tc = pc * cos + pd * sin;
|
||||
float td = pc * -sin + pd * cos;
|
||||
pa = ta;
|
||||
pb = tb;
|
||||
pc = tc;
|
||||
pd = td;
|
||||
p = p.parent;
|
||||
}
|
||||
do {
|
||||
cos = MathUtils.CosDeg(parent.appliedRotation);
|
||||
sin = MathUtils.SinDeg(parent.appliedRotation);
|
||||
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;
|
||||
parent = parent.parent;
|
||||
} while (parent != null);
|
||||
a = pa * la + pb * lc;
|
||||
b = pa * lb + pb * ld;
|
||||
c = pc * la + pd * lc;
|
||||
@ -166,16 +168,15 @@ namespace Spine {
|
||||
d = -d;
|
||||
}
|
||||
} else if (data.inheritScale) { // No rotation inheritance.
|
||||
Bone p = parent;
|
||||
pa = 1;
|
||||
pb = 0;
|
||||
pc = 0;
|
||||
pd = 1;
|
||||
while (p != null) {
|
||||
float r = p.rotation;
|
||||
do {
|
||||
float r = parent.rotation;
|
||||
cos = MathUtils.CosDeg(r);
|
||||
sin = MathUtils.SinDeg(r);
|
||||
float psx = p.appliedScaleX, psy = p.appliedScaleY;
|
||||
float psx = parent.appliedScaleX, psy = parent.appliedScaleY;
|
||||
float za = cos * psx, zb = -sin * psy, zc = sin * psx, zd = cos * psy;
|
||||
float temp = pa * za + pb * zc;
|
||||
pb = pa * zb + pb * zd;
|
||||
@ -194,8 +195,8 @@ namespace Spine {
|
||||
pd = pc * -sin + pd * cos;
|
||||
pc = temp;
|
||||
|
||||
p = p.parent;
|
||||
}
|
||||
parent = parent.parent;
|
||||
} while (parent != null);
|
||||
a = pa * la + pb * lc;
|
||||
b = pa * lb + pb * ld;
|
||||
c = pc * la + pd * lc;
|
||||
@ -216,10 +217,6 @@ namespace Spine {
|
||||
}
|
||||
}
|
||||
|
||||
public void Update () {
|
||||
UpdateWorldTransform(x, y, rotation, scaleX, scaleY);
|
||||
}
|
||||
|
||||
public void SetToSetupPose () {
|
||||
BoneData data = this.data;
|
||||
x = data.x;
|
||||
|
||||
@ -137,8 +137,7 @@ namespace Spine {
|
||||
if (Math.Abs(psx - psy) <= 0.0001f) {
|
||||
l2 *= psx;
|
||||
float 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;
|
||||
a2 = (float)Math.Acos(cos) * bendDir;
|
||||
float a = l1 + l2 * cos, o = l2 * MathUtils.Sin(a2);
|
||||
|
||||
@ -151,8 +151,8 @@ namespace Spine {
|
||||
transformConstraintData.bone = skeletonData.bones.Items[ReadInt(input, true)];
|
||||
transformConstraintData.target = skeletonData.bones.Items[ReadInt(input, true)];
|
||||
transformConstraintData.translateMix = ReadFloat(input);
|
||||
transformConstraintData.x = ReadFloat(input);
|
||||
transformConstraintData.y = ReadFloat(input);
|
||||
transformConstraintData.x = ReadFloat(input) * scale;
|
||||
transformConstraintData.y = ReadFloat(input) * scale;
|
||||
skeletonData.transformConstraints.Add(transformConstraintData);
|
||||
}
|
||||
|
||||
|
||||
@ -159,8 +159,8 @@ namespace Spine {
|
||||
if (transformConstraintData.target == null) throw new Exception("Target bone not found: " + targetName);
|
||||
|
||||
transformConstraintData.translateMix = GetFloat(transformMap, "translateMix", 1);
|
||||
transformConstraintData.x = GetFloat(transformMap, "x", 0);
|
||||
transformConstraintData.y = GetFloat(transformMap, "y", 0);
|
||||
transformConstraintData.x = GetFloat(transformMap, "x", 0) * scale;
|
||||
transformConstraintData.y = GetFloat(transformMap, "y", 0) * scale;
|
||||
|
||||
skeletonData.transformConstraints.Add(transformConstraintData);
|
||||
}
|
||||
|
||||
@ -54,11 +54,9 @@ namespace Spine {
|
||||
x = data.x;
|
||||
y = data.y;
|
||||
|
||||
if (skeleton != null) {
|
||||
bone = skeleton.FindBone(data.bone.name);
|
||||
target = skeleton.FindBone(data.target.name);
|
||||
}
|
||||
}
|
||||
|
||||
public void Update () {
|
||||
Apply();
|
||||
|
||||
@ -78,6 +78,11 @@ public class Bone implements Updatable {
|
||||
scaleY = bone.scaleY;
|
||||
}
|
||||
|
||||
/** Same as {@link #updateWorldTransform()}. This method exists for Bone to implement {@link Updatable}. */
|
||||
public void update () {
|
||||
updateWorldTransform(x, y, rotation, scaleX, scaleY);
|
||||
}
|
||||
|
||||
/** Computes the world SRT using the parent bone and this bone's local SRT. */
|
||||
public void updateWorldTransform () {
|
||||
updateWorldTransform(x, y, rotation, scaleX, scaleY);
|
||||
@ -127,22 +132,21 @@ public class Bone implements Updatable {
|
||||
c = pc * la + pd * lc;
|
||||
d = pc * lb + pd * ld;
|
||||
} else if (data.inheritRotation) { // No scale inheritance.
|
||||
Bone p = parent;
|
||||
pa = 1;
|
||||
pb = 0;
|
||||
pc = 0;
|
||||
pd = 1;
|
||||
while (p != null) {
|
||||
cos = MathUtils.cosDeg(p.appliedRotation);
|
||||
sin = MathUtils.sinDeg(p.appliedRotation);
|
||||
do {
|
||||
cos = MathUtils.cosDeg(parent.appliedRotation);
|
||||
sin = MathUtils.sinDeg(parent.appliedRotation);
|
||||
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;
|
||||
}
|
||||
parent = parent.parent;
|
||||
} while (parent != null);
|
||||
a = pa * la + pb * lc;
|
||||
b = pa * lb + pb * ld;
|
||||
c = pc * la + pd * lc;
|
||||
@ -156,16 +160,15 @@ public class Bone implements Updatable {
|
||||
d = -d;
|
||||
}
|
||||
} else if (data.inheritScale) { // No rotation inheritance.
|
||||
Bone p = parent;
|
||||
pa = 1;
|
||||
pb = 0;
|
||||
pc = 0;
|
||||
pd = 1;
|
||||
while (p != null) {
|
||||
float r = p.rotation;
|
||||
do {
|
||||
float r = parent.rotation;
|
||||
cos = MathUtils.cosDeg(r);
|
||||
sin = MathUtils.sinDeg(r);
|
||||
float psx = p.appliedScaleX, psy = p.appliedScaleY;
|
||||
float psx = parent.appliedScaleX, psy = parent.appliedScaleY;
|
||||
float za = cos * psx, zb = -sin * psy, zc = sin * psx, zd = cos * psy;
|
||||
float temp = pa * za + pb * zc;
|
||||
pb = pa * zb + pb * zd;
|
||||
@ -184,8 +187,8 @@ public class Bone implements Updatable {
|
||||
pd = pc * -sin + pd * cos;
|
||||
pc = temp;
|
||||
|
||||
p = p.parent;
|
||||
}
|
||||
parent = parent.parent;
|
||||
} while (parent != null);
|
||||
a = pa * la + pb * lc;
|
||||
b = pa * lb + pb * ld;
|
||||
c = pc * la + pd * lc;
|
||||
@ -206,11 +209,6 @@ public class Bone implements Updatable {
|
||||
}
|
||||
}
|
||||
|
||||
/** Same as {@link #updateWorldTransform()}. This method exists for Bone to implement {@link Updatable}. */
|
||||
public void update () {
|
||||
updateWorldTransform(x, y, rotation, scaleX, scaleY);
|
||||
}
|
||||
|
||||
public void setToSetupPose () {
|
||||
BoneData data = this.data;
|
||||
x = data.x;
|
||||
|
||||
@ -159,8 +159,8 @@ public class SkeletonJson {
|
||||
if (transformConstraintData.target == null) throw new SerializationException("Target bone not found: " + targetName);
|
||||
|
||||
transformConstraintData.translateMix = transformMap.getFloat("translateMix", 1);
|
||||
transformConstraintData.x = transformMap.getFloat("x", 0);
|
||||
transformConstraintData.y = transformMap.getFloat("y", 0);
|
||||
transformConstraintData.x = transformMap.getFloat("x", 0) * scale;
|
||||
transformConstraintData.y = transformMap.getFloat("y", 0) * scale;
|
||||
|
||||
skeletonData.transformConstraints.add(transformConstraintData);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user