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->c) = pc * la + pd * lc;
|
||||||
CONST_CAST(float, self->d) = pc * lb + pd * ld;
|
CONST_CAST(float, self->d) = pc * lb + pd * ld;
|
||||||
} else if (self->data->inheritRotation) { /* No scale inheritance. */
|
} else if (self->data->inheritRotation) { /* No scale inheritance. */
|
||||||
spBone* p = parent;
|
|
||||||
pa = 1;
|
pa = 1;
|
||||||
pb = 0;
|
pb = 0;
|
||||||
pc = 0;
|
pc = 0;
|
||||||
pd = 1;
|
pd = 1;
|
||||||
while (p) {
|
do {
|
||||||
cosine = COS(p->appliedRotation * DEG_RAD);
|
cosine = COS(parent->appliedRotation * DEG_RAD);
|
||||||
sine = SIN(p->appliedRotation * DEG_RAD);
|
sine = SIN(parent->appliedRotation * DEG_RAD);
|
||||||
temp = pa * cosine + pb * sine;
|
temp = pa * cosine + pb * sine;
|
||||||
pb = pa * -sine + pb * cosine;
|
pb = pa * -sine + pb * cosine;
|
||||||
pa = temp;
|
pa = temp;
|
||||||
temp = pc * cosine + pd * sine;
|
temp = pc * cosine + pd * sine;
|
||||||
pd = pc * -sine + pd * cosine;
|
pd = pc * -sine + pd * cosine;
|
||||||
pc = temp;
|
pc = temp;
|
||||||
p = p->parent;
|
parent = parent->parent;
|
||||||
}
|
} while (parent);
|
||||||
CONST_CAST(float, self->a) = pa * la + pb * lc;
|
CONST_CAST(float, self->a) = pa * la + pb * lc;
|
||||||
CONST_CAST(float, self->b) = pa * lb + pb * ld;
|
CONST_CAST(float, self->b) = pa * lb + pb * ld;
|
||||||
CONST_CAST(float, self->c) = pc * la + pd * lc;
|
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;
|
CONST_CAST(float, self->d) = -self->d;
|
||||||
}
|
}
|
||||||
} else if (self->data->inheritScale) { /* No rotation inheritance. */
|
} else if (self->data->inheritScale) { /* No rotation inheritance. */
|
||||||
spBone* p = parent;
|
|
||||||
pa = 1;
|
pa = 1;
|
||||||
pb = 0;
|
pb = 0;
|
||||||
pc = 0;
|
pc = 0;
|
||||||
pd = 1;
|
pd = 1;
|
||||||
while (p) {
|
do {
|
||||||
float za, zb, zc, zd;
|
float za, zb, zc, zd;
|
||||||
float r = p->rotation;
|
float r = parent->rotation;
|
||||||
float psx = p->appliedScaleX, psy = p->appliedScaleY;
|
float psx = parent->appliedScaleX, psy = parent->appliedScaleY;
|
||||||
cosine = COS(r * DEG_RAD);
|
cosine = COS(r * DEG_RAD);
|
||||||
sine = SIN(r * DEG_RAD);
|
sine = SIN(r * DEG_RAD);
|
||||||
za = cosine * psx;
|
za = cosine * psx;
|
||||||
@ -170,8 +168,8 @@ void spBone_updateWorldTransformWith (spBone* self, float x, float y, float rota
|
|||||||
pd = pc * -sine + pd * cosine;
|
pd = pc * -sine + pd * cosine;
|
||||||
pc = temp;
|
pc = temp;
|
||||||
|
|
||||||
p = p->parent;
|
parent = parent->parent;
|
||||||
}
|
} while (parent);
|
||||||
CONST_CAST(float, self->a) = pa * la + pb * lc;
|
CONST_CAST(float, self->a) = pa * la + pb * lc;
|
||||||
CONST_CAST(float, self->b) = pa * lb + pb * ld;
|
CONST_CAST(float, self->b) = pa * lb + pb * ld;
|
||||||
CONST_CAST(float, self->c) = pc * la + pd * lc;
|
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->translateMix = Json_getFloat(transformMap, "translateMix", 1);
|
||||||
transformConstraintData->x = Json_getFloat(transformMap, "x", 0);
|
transformConstraintData->x = Json_getFloat(transformMap, "x", 0) * self->scale;
|
||||||
transformConstraintData->y = Json_getFloat(transformMap, "y", 0);
|
transformConstraintData->y = Json_getFloat(transformMap, "y", 0) * self->scale;
|
||||||
|
|
||||||
skeletonData->transformConstraints[i] = transformConstraintData;
|
skeletonData->transformConstraints[i] = transformConstraintData;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,6 +86,11 @@ namespace Spine {
|
|||||||
SetToSetupPose();
|
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>
|
/// <summary>Computes the world SRT using the parent bone and this bone's local SRT.</summary>
|
||||||
public void UpdateWorldTransform () {
|
public void UpdateWorldTransform () {
|
||||||
UpdateWorldTransform(x, y, rotation, scaleX, scaleY);
|
UpdateWorldTransform(x, y, rotation, scaleX, scaleY);
|
||||||
@ -135,24 +140,21 @@ namespace Spine {
|
|||||||
c = pc * la + pd * lc;
|
c = pc * la + pd * lc;
|
||||||
d = pc * lb + pd * ld;
|
d = pc * lb + pd * ld;
|
||||||
} else if (data.inheritRotation) { // No scale inheritance.
|
} else if (data.inheritRotation) { // No scale inheritance.
|
||||||
Bone p = parent;
|
|
||||||
pa = 1;
|
pa = 1;
|
||||||
pb = 0;
|
pb = 0;
|
||||||
pc = 0;
|
pc = 0;
|
||||||
pd = 1;
|
pd = 1;
|
||||||
while (p != null) {
|
do {
|
||||||
cos = MathUtils.CosDeg(p.appliedRotation);
|
cos = MathUtils.CosDeg(parent.appliedRotation);
|
||||||
sin = MathUtils.SinDeg(p.appliedRotation);
|
sin = MathUtils.SinDeg(parent.appliedRotation);
|
||||||
float ta = pa * cos + pb * sin;
|
float temp = pa * cos + pb * sin;
|
||||||
float tb = pa * -sin + pb * cos;
|
pb = pa * -sin + pb * cos;
|
||||||
float tc = pc * cos + pd * sin;
|
pa = temp;
|
||||||
float td = pc * -sin + pd * cos;
|
temp = pc * cos + pd * sin;
|
||||||
pa = ta;
|
pd = pc * -sin + pd * cos;
|
||||||
pb = tb;
|
pc = temp;
|
||||||
pc = tc;
|
parent = parent.parent;
|
||||||
pd = td;
|
} while (parent != null);
|
||||||
p = p.parent;
|
|
||||||
}
|
|
||||||
a = pa * la + pb * lc;
|
a = pa * la + pb * lc;
|
||||||
b = pa * lb + pb * ld;
|
b = pa * lb + pb * ld;
|
||||||
c = pc * la + pd * lc;
|
c = pc * la + pd * lc;
|
||||||
@ -166,16 +168,15 @@ namespace Spine {
|
|||||||
d = -d;
|
d = -d;
|
||||||
}
|
}
|
||||||
} else if (data.inheritScale) { // No rotation inheritance.
|
} else if (data.inheritScale) { // No rotation inheritance.
|
||||||
Bone p = parent;
|
|
||||||
pa = 1;
|
pa = 1;
|
||||||
pb = 0;
|
pb = 0;
|
||||||
pc = 0;
|
pc = 0;
|
||||||
pd = 1;
|
pd = 1;
|
||||||
while (p != null) {
|
do {
|
||||||
float r = p.rotation;
|
float r = parent.rotation;
|
||||||
cos = MathUtils.CosDeg(r);
|
cos = MathUtils.CosDeg(r);
|
||||||
sin = MathUtils.SinDeg(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 za = cos * psx, zb = -sin * psy, zc = sin * psx, zd = cos * psy;
|
||||||
float temp = pa * za + pb * zc;
|
float temp = pa * za + pb * zc;
|
||||||
pb = pa * zb + pb * zd;
|
pb = pa * zb + pb * zd;
|
||||||
@ -194,8 +195,8 @@ namespace Spine {
|
|||||||
pd = pc * -sin + pd * cos;
|
pd = pc * -sin + pd * cos;
|
||||||
pc = temp;
|
pc = temp;
|
||||||
|
|
||||||
p = p.parent;
|
parent = parent.parent;
|
||||||
}
|
} while (parent != null);
|
||||||
a = pa * la + pb * lc;
|
a = pa * la + pb * lc;
|
||||||
b = pa * lb + pb * ld;
|
b = pa * lb + pb * ld;
|
||||||
c = pc * la + pd * lc;
|
c = pc * la + pd * lc;
|
||||||
@ -216,10 +217,6 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update () {
|
|
||||||
UpdateWorldTransform(x, y, rotation, scaleX, scaleY);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetToSetupPose () {
|
public void SetToSetupPose () {
|
||||||
BoneData data = this.data;
|
BoneData data = this.data;
|
||||||
x = data.x;
|
x = data.x;
|
||||||
|
|||||||
@ -137,8 +137,7 @@ namespace Spine {
|
|||||||
if (Math.Abs(psx - psy) <= 0.0001f) {
|
if (Math.Abs(psx - psy) <= 0.0001f) {
|
||||||
l2 *= psx;
|
l2 *= psx;
|
||||||
float cos = (tx * tx + ty * ty - l1 * l1 - l2 * l2) / (2 * l1 * l2);
|
float cos = (tx * tx + ty * ty - l1 * l1 - l2 * l2) / (2 * l1 * l2);
|
||||||
if (cos < -1)
|
if (cos < -1) cos = -1;
|
||||||
cos = -1;
|
|
||||||
else if (cos > 1) cos = 1;
|
else if (cos > 1) cos = 1;
|
||||||
a2 = (float)Math.Acos(cos) * bendDir;
|
a2 = (float)Math.Acos(cos) * bendDir;
|
||||||
float a = l1 + l2 * cos, o = l2 * MathUtils.Sin(a2);
|
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.bone = skeletonData.bones.Items[ReadInt(input, true)];
|
||||||
transformConstraintData.target = skeletonData.bones.Items[ReadInt(input, true)];
|
transformConstraintData.target = skeletonData.bones.Items[ReadInt(input, true)];
|
||||||
transformConstraintData.translateMix = ReadFloat(input);
|
transformConstraintData.translateMix = ReadFloat(input);
|
||||||
transformConstraintData.x = ReadFloat(input);
|
transformConstraintData.x = ReadFloat(input) * scale;
|
||||||
transformConstraintData.y = ReadFloat(input);
|
transformConstraintData.y = ReadFloat(input) * scale;
|
||||||
skeletonData.transformConstraints.Add(transformConstraintData);
|
skeletonData.transformConstraints.Add(transformConstraintData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -159,8 +159,8 @@ namespace Spine {
|
|||||||
if (transformConstraintData.target == null) throw new Exception("Target bone not found: " + targetName);
|
if (transformConstraintData.target == null) throw new Exception("Target bone not found: " + targetName);
|
||||||
|
|
||||||
transformConstraintData.translateMix = GetFloat(transformMap, "translateMix", 1);
|
transformConstraintData.translateMix = GetFloat(transformMap, "translateMix", 1);
|
||||||
transformConstraintData.x = GetFloat(transformMap, "x", 0);
|
transformConstraintData.x = GetFloat(transformMap, "x", 0) * scale;
|
||||||
transformConstraintData.y = GetFloat(transformMap, "y", 0);
|
transformConstraintData.y = GetFloat(transformMap, "y", 0) * scale;
|
||||||
|
|
||||||
skeletonData.transformConstraints.Add(transformConstraintData);
|
skeletonData.transformConstraints.Add(transformConstraintData);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,11 +54,9 @@ namespace Spine {
|
|||||||
x = data.x;
|
x = data.x;
|
||||||
y = data.y;
|
y = data.y;
|
||||||
|
|
||||||
if (skeleton != null) {
|
|
||||||
bone = skeleton.FindBone(data.bone.name);
|
bone = skeleton.FindBone(data.bone.name);
|
||||||
target = skeleton.FindBone(data.target.name);
|
target = skeleton.FindBone(data.target.name);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void Update () {
|
public void Update () {
|
||||||
Apply();
|
Apply();
|
||||||
|
|||||||
@ -78,6 +78,11 @@ public class Bone implements Updatable {
|
|||||||
scaleY = bone.scaleY;
|
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. */
|
/** Computes the world SRT using the parent bone and this bone's local SRT. */
|
||||||
public void updateWorldTransform () {
|
public void updateWorldTransform () {
|
||||||
updateWorldTransform(x, y, rotation, scaleX, scaleY);
|
updateWorldTransform(x, y, rotation, scaleX, scaleY);
|
||||||
@ -127,22 +132,21 @@ public class Bone implements Updatable {
|
|||||||
c = pc * la + pd * lc;
|
c = pc * la + pd * lc;
|
||||||
d = pc * lb + pd * ld;
|
d = pc * lb + pd * ld;
|
||||||
} else if (data.inheritRotation) { // No scale inheritance.
|
} else if (data.inheritRotation) { // No scale inheritance.
|
||||||
Bone p = parent;
|
|
||||||
pa = 1;
|
pa = 1;
|
||||||
pb = 0;
|
pb = 0;
|
||||||
pc = 0;
|
pc = 0;
|
||||||
pd = 1;
|
pd = 1;
|
||||||
while (p != null) {
|
do {
|
||||||
cos = MathUtils.cosDeg(p.appliedRotation);
|
cos = MathUtils.cosDeg(parent.appliedRotation);
|
||||||
sin = MathUtils.sinDeg(p.appliedRotation);
|
sin = MathUtils.sinDeg(parent.appliedRotation);
|
||||||
float temp = pa * cos + pb * sin;
|
float temp = pa * cos + pb * sin;
|
||||||
pb = pa * -sin + pb * cos;
|
pb = pa * -sin + pb * cos;
|
||||||
pa = temp;
|
pa = temp;
|
||||||
temp = pc * cos + pd * sin;
|
temp = pc * cos + pd * sin;
|
||||||
pd = pc * -sin + pd * cos;
|
pd = pc * -sin + pd * cos;
|
||||||
pc = temp;
|
pc = temp;
|
||||||
p = p.parent;
|
parent = parent.parent;
|
||||||
}
|
} while (parent != null);
|
||||||
a = pa * la + pb * lc;
|
a = pa * la + pb * lc;
|
||||||
b = pa * lb + pb * ld;
|
b = pa * lb + pb * ld;
|
||||||
c = pc * la + pd * lc;
|
c = pc * la + pd * lc;
|
||||||
@ -156,16 +160,15 @@ public class Bone implements Updatable {
|
|||||||
d = -d;
|
d = -d;
|
||||||
}
|
}
|
||||||
} else if (data.inheritScale) { // No rotation inheritance.
|
} else if (data.inheritScale) { // No rotation inheritance.
|
||||||
Bone p = parent;
|
|
||||||
pa = 1;
|
pa = 1;
|
||||||
pb = 0;
|
pb = 0;
|
||||||
pc = 0;
|
pc = 0;
|
||||||
pd = 1;
|
pd = 1;
|
||||||
while (p != null) {
|
do {
|
||||||
float r = p.rotation;
|
float r = parent.rotation;
|
||||||
cos = MathUtils.cosDeg(r);
|
cos = MathUtils.cosDeg(r);
|
||||||
sin = MathUtils.sinDeg(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 za = cos * psx, zb = -sin * psy, zc = sin * psx, zd = cos * psy;
|
||||||
float temp = pa * za + pb * zc;
|
float temp = pa * za + pb * zc;
|
||||||
pb = pa * zb + pb * zd;
|
pb = pa * zb + pb * zd;
|
||||||
@ -184,8 +187,8 @@ public class Bone implements Updatable {
|
|||||||
pd = pc * -sin + pd * cos;
|
pd = pc * -sin + pd * cos;
|
||||||
pc = temp;
|
pc = temp;
|
||||||
|
|
||||||
p = p.parent;
|
parent = parent.parent;
|
||||||
}
|
} while (parent != null);
|
||||||
a = pa * la + pb * lc;
|
a = pa * la + pb * lc;
|
||||||
b = pa * lb + pb * ld;
|
b = pa * lb + pb * ld;
|
||||||
c = pc * la + pd * lc;
|
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 () {
|
public void setToSetupPose () {
|
||||||
BoneData data = this.data;
|
BoneData data = this.data;
|
||||||
x = data.x;
|
x = data.x;
|
||||||
|
|||||||
@ -159,8 +159,8 @@ public class SkeletonJson {
|
|||||||
if (transformConstraintData.target == null) throw new SerializationException("Target bone not found: " + targetName);
|
if (transformConstraintData.target == null) throw new SerializationException("Target bone not found: " + targetName);
|
||||||
|
|
||||||
transformConstraintData.translateMix = transformMap.getFloat("translateMix", 1);
|
transformConstraintData.translateMix = transformMap.getFloat("translateMix", 1);
|
||||||
transformConstraintData.x = transformMap.getFloat("x", 0);
|
transformConstraintData.x = transformMap.getFloat("x", 0) * scale;
|
||||||
transformConstraintData.y = transformMap.getFloat("y", 0);
|
transformConstraintData.y = transformMap.getFloat("y", 0) * scale;
|
||||||
|
|
||||||
skeletonData.transformConstraints.add(transformConstraintData);
|
skeletonData.transformConstraints.add(transformConstraintData);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user