SinDeg() static public method

Returns the sine in radians from a lookup table.
static public SinDeg ( float degrees ) : float
degrees float
return float
Ejemplo n.º 1
0
        public float WorldToLocalRotation(float worldRotation)
        {
            float sin = MathUtils.SinDeg(worldRotation), cos = MathUtils.CosDeg(worldRotation);

            return(MathUtils.Atan2(a * sin - c * cos, d * cos - b * sin) * MathUtils.RadDeg + rotation - shearX);
        }
Ejemplo n.º 2
0
        /// <summary>Computes the world SRT using the parent bone and the specified local SRT.</summary>
        public void UpdateWorldTransform(float x, float y, float rotation, float scaleX, float scaleY)
        {
            appliedRotation = rotation;
            appliedScaleX   = scaleX;
            appliedScaleY   = scaleY;

            float cos = MathUtils.CosDeg(rotation), sin = MathUtils.SinDeg(rotation);
            float la = cos * scaleX, lb = -sin * scaleY, lc = sin * scaleX, ld = cos * scaleY;
            Bone  parent = this.parent;

            if (parent == null)               // Root bone.
            {
                Skeleton skeleton = this.skeleton;
                if (skeleton.flipX)
                {
                    x  = -x;
                    la = -la;
                    lb = -lb;
                }
                if (skeleton.flipY != yDown)
                {
                    y  = -y;
                    lc = -lc;
                    ld = -ld;
                }
                a          = la;
                b          = lb;
                c          = lc;
                d          = ld;
                worldX     = x;
                worldY     = y;
                worldSignX = Math.Sign(scaleX);
                worldSignY = Math.Sign(scaleY);
                return;
            }

            float pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;

            worldX     = pa * x + pb * y + parent.worldX;
            worldY     = pc * x + pd * y + parent.worldY;
            worldSignX = parent.worldSignX * Math.Sign(scaleX);
            worldSignY = parent.worldSignY * Math.Sign(scaleY);

            if (data.inheritRotation && data.inheritScale)
            {
                a = pa * la + pb * lc;
                b = pa * lb + pb * ld;
                c = pc * la + pd * lc;
                d = pc * lb + pd * ld;
            }
            else
            {
                if (data.inheritRotation)                   // No scale inheritance.
                {
                    pa = 1;
                    pb = 0;
                    pc = 0;
                    pd = 1;
                    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;

                        if (!parent.data.inheritRotation)
                        {
                            break;
                        }
                        parent = parent.parent;
                    } while (parent != null);
                    a = pa * la + pb * lc;
                    b = pa * lb + pb * ld;
                    c = pc * la + pd * lc;
                    d = pc * lb + pd * ld;
                }
                else if (data.inheritScale)                     // No rotation inheritance.
                {
                    pa = 1;
                    pb = 0;
                    pc = 0;
                    pd = 1;
                    do
                    {
                        float r = parent.rotation;
                        cos = MathUtils.CosDeg(r);
                        sin = MathUtils.SinDeg(r);
                        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;
                        pa   = temp;
                        temp = pc * za + pd * zc;
                        pd   = pc * zb + pd * zd;
                        pc   = temp;

                        if (psx < 0)
                        {
                            r = -r;
                        }
                        cos  = MathUtils.CosDeg(-r);
                        sin  = MathUtils.SinDeg(-r);
                        temp = pa * cos + pb * sin;
                        pb   = pa * -sin + pb * cos;
                        pa   = temp;
                        temp = pc * cos + pd * sin;
                        pd   = pc * -sin + pd * cos;
                        pc   = temp;

                        if (!parent.data.inheritScale)
                        {
                            break;
                        }
                        parent = parent.parent;
                    } while (parent != null);
                    a = pa * la + pb * lc;
                    b = pa * lb + pb * ld;
                    c = pc * la + pd * lc;
                    d = pc * lb + pd * ld;
                }
                else
                {
                    a = la;
                    b = lb;
                    c = lc;
                    d = ld;
                }
                if (skeleton.flipX)
                {
                    a = -a;
                    b = -b;
                }
                if (skeleton.flipY != yDown)
                {
                    c = -c;
                    d = -d;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>Computes the world transform using the parent bone and the specified local transform.</summary>
        public void UpdateWorldTransform(float x, float y, float rotation, float scaleX, float scaleY, float shearX, float shearY)
        {
            ax           = x;
            ay           = y;
            arotation    = rotation;
            ascaleX      = scaleX;
            ascaleY      = scaleY;
            ashearX      = shearX;
            ashearY      = shearY;
            appliedValid = true;
            Skeleton skeleton = this.skeleton;

            Bone parent = this.parent;

            if (parent == null)               // Root bone.
            {
                float rotationY = rotation + 90 + shearY, sx = skeleton.scaleX, sy = skeleton.scaleY;
                a      = MathUtils.CosDeg(rotation + shearX) * scaleX * sx;
                b      = MathUtils.CosDeg(rotationY) * scaleY * sy;
                c      = MathUtils.SinDeg(rotation + shearX) * scaleX * sx;
                d      = MathUtils.SinDeg(rotationY) * scaleY * sy;
                worldX = x * sx + skeleton.x;
                worldY = y * sy + skeleton.y;
                return;
            }

            float pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;

            worldX = pa * x + pb * y + parent.worldX;
            worldY = pc * x + pd * y + parent.worldY;

            switch (data.transformMode)
            {
            case TransformMode.Normal: {
                float rotationY = rotation + 90 + shearY;
                float la        = MathUtils.CosDeg(rotation + shearX) * scaleX;
                float lb        = MathUtils.CosDeg(rotationY) * scaleY;
                float lc        = MathUtils.SinDeg(rotation + shearX) * scaleX;
                float ld        = MathUtils.SinDeg(rotationY) * scaleY;
                a = pa * la + pb * lc;
                b = pa * lb + pb * ld;
                c = pc * la + pd * lc;
                d = pc * lb + pd * ld;
                return;
            }

            case TransformMode.OnlyTranslation: {
                float rotationY = rotation + 90 + shearY;
                a = MathUtils.CosDeg(rotation + shearX) * scaleX;
                b = MathUtils.CosDeg(rotationY) * scaleY;
                c = MathUtils.SinDeg(rotation + shearX) * scaleX;
                d = MathUtils.SinDeg(rotationY) * scaleY;
                break;
            }

            case TransformMode.NoRotationOrReflection: {
                float s = pa * pa + pc * pc, prx;
                if (s > 0.0001f)
                {
                    s   = Math.Abs(pa * pd - pb * pc) / s;
                    pb  = pc * s;
                    pd  = pa * s;
                    prx = MathUtils.Atan2(pc, pa) * MathUtils.RadDeg;
                }
                else
                {
                    pa  = 0;
                    pc  = 0;
                    prx = 90 - MathUtils.Atan2(pd, pb) * MathUtils.RadDeg;
                }
                float rx = rotation + shearX - prx;
                float ry = rotation + shearY - prx + 90;
                float la = MathUtils.CosDeg(rx) * scaleX;
                float lb = MathUtils.CosDeg(ry) * scaleY;
                float lc = MathUtils.SinDeg(rx) * scaleX;
                float ld = MathUtils.SinDeg(ry) * scaleY;
                a = pa * la - pb * lc;
                b = pa * lb - pb * ld;
                c = pc * la + pd * lc;
                d = pc * lb + pd * ld;
                break;
            }

            case TransformMode.NoScale:
            case TransformMode.NoScaleOrReflection: {
                float cos = MathUtils.CosDeg(rotation), sin = MathUtils.SinDeg(rotation);
                float za = (pa * cos + pb * sin) / skeleton.scaleX;
                float zc = (pc * cos + pd * sin) / skeleton.scaleY;
                float s  = (float)Math.Sqrt(za * za + zc * zc);
                if (s > 0.00001f)
                {
                    s = 1 / s;
                }
                za *= s;
                zc *= s;
                s   = (float)Math.Sqrt(za * za + zc * zc);
                if (data.transformMode == TransformMode.NoScale &&
                    (pa * pd - pb * pc < 0) != (skeleton.scaleX < 0 != skeleton.scaleY < 0))
                {
                    s = -s;
                }

                float r  = MathUtils.PI / 2 + MathUtils.Atan2(zc, za);
                float zb = MathUtils.Cos(r) * s;
                float zd = MathUtils.Sin(r) * s;
                float la = MathUtils.CosDeg(shearX) * scaleX;
                float lb = MathUtils.CosDeg(90 + shearY) * scaleY;
                float lc = MathUtils.SinDeg(shearX) * scaleX;
                float ld = MathUtils.SinDeg(90 + shearY) * scaleY;
                a = za * la + zb * lc;
                b = za * lb + zb * ld;
                c = zc * la + zd * lc;
                d = zc * lb + zd * ld;
                break;
            }
            }

            a *= skeleton.scaleX;
            b *= skeleton.scaleX;
            c *= skeleton.scaleY;
            d *= skeleton.scaleY;
        }
Ejemplo n.º 4
0
        public void UpdateWorldTransform(float x, float y, float rotation, float scaleX, float scaleY, float shearX, float shearY)
        {
            ax           = x;
            ay           = y;
            arotation    = rotation;
            ascaleX      = scaleX;
            ascaleY      = scaleY;
            ashearX      = shearX;
            ashearY      = shearY;
            appliedValid = true;
            Skeleton skeleton = this.skeleton;
            Bone     bone     = parent;

            if (bone == null)
            {
                float degrees = rotation + 90f + shearY;
                float num     = MathUtils.CosDeg(rotation + shearX) * scaleX;
                float num2    = MathUtils.CosDeg(degrees) * scaleY;
                float num3    = MathUtils.SinDeg(rotation + shearX) * scaleX;
                float num4    = MathUtils.SinDeg(degrees) * scaleY;
                if (skeleton.flipX)
                {
                    x    = 0f - x;
                    num  = 0f - num;
                    num2 = 0f - num2;
                }
                if (skeleton.flipY != yDown)
                {
                    y    = 0f - y;
                    num3 = 0f - num3;
                    num4 = 0f - num4;
                }
                a      = num;
                b      = num2;
                c      = num3;
                d      = num4;
                worldX = x + skeleton.x;
                worldY = y + skeleton.y;
                return;
            }
            float num5 = bone.a;
            float num6 = bone.b;
            float num7 = bone.c;
            float num8 = bone.d;

            worldX = num5 * x + num6 * y + bone.worldX;
            worldY = num7 * x + num8 * y + bone.worldY;
            switch (data.transformMode)
            {
            case TransformMode.Normal:
            {
                float degrees2 = rotation + 90f + shearY;
                float num20    = MathUtils.CosDeg(rotation + shearX) * scaleX;
                float num21    = MathUtils.CosDeg(degrees2) * scaleY;
                float num22    = MathUtils.SinDeg(rotation + shearX) * scaleX;
                float num23    = MathUtils.SinDeg(degrees2) * scaleY;
                a = num5 * num20 + num6 * num22;
                b = num5 * num21 + num6 * num23;
                c = num7 * num20 + num8 * num22;
                d = num7 * num21 + num8 * num23;
                return;
            }

            case TransformMode.OnlyTranslation:
            {
                float degrees5 = rotation + 90f + shearY;
                a = MathUtils.CosDeg(rotation + shearX) * scaleX;
                b = MathUtils.CosDeg(degrees5) * scaleY;
                c = MathUtils.SinDeg(rotation + shearX) * scaleX;
                d = MathUtils.SinDeg(degrees5) * scaleY;
                break;
            }

            case TransformMode.NoRotationOrReflection:
            {
                float num24 = num5 * num5 + num7 * num7;
                float num25;
                if (num24 > 0.0001f)
                {
                    num24 = Math.Abs(num5 * num8 - num6 * num7) / num24;
                    num6  = num7 * num24;
                    num8  = num5 * num24;
                    num25 = MathUtils.Atan2(num7, num5) * (180f / (float)Math.PI);
                }
                else
                {
                    num5  = 0f;
                    num7  = 0f;
                    num25 = 90f - MathUtils.Atan2(num8, num6) * (180f / (float)Math.PI);
                }
                float degrees3 = rotation + shearX - num25;
                float degrees4 = rotation + shearY - num25 + 90f;
                float num26    = MathUtils.CosDeg(degrees3) * scaleX;
                float num27    = MathUtils.CosDeg(degrees4) * scaleY;
                float num28    = MathUtils.SinDeg(degrees3) * scaleX;
                float num29    = MathUtils.SinDeg(degrees4) * scaleY;
                a = num5 * num26 - num6 * num28;
                b = num5 * num27 - num6 * num29;
                c = num7 * num26 + num8 * num28;
                d = num7 * num27 + num8 * num29;
                break;
            }

            case TransformMode.NoScale:
            case TransformMode.NoScaleOrReflection:
            {
                float num9  = MathUtils.CosDeg(rotation);
                float num10 = MathUtils.SinDeg(rotation);
                float num11 = num5 * num9 + num6 * num10;
                float num12 = num7 * num9 + num8 * num10;
                float num13 = (float)Math.Sqrt(num11 * num11 + num12 * num12);
                if (num13 > 1E-05f)
                {
                    num13 = 1f / num13;
                }
                num11 *= num13;
                num12 *= num13;
                num13  = (float)Math.Sqrt(num11 * num11 + num12 * num12);
                float radians = (float)Math.PI / 2f + MathUtils.Atan2(num12, num11);
                float num14   = MathUtils.Cos(radians) * num13;
                float num15   = MathUtils.Sin(radians) * num13;
                float num16   = MathUtils.CosDeg(shearX) * scaleX;
                float num17   = MathUtils.CosDeg(90f + shearY) * scaleY;
                float num18   = MathUtils.SinDeg(shearX) * scaleX;
                float num19   = MathUtils.SinDeg(90f + shearY) * scaleY;
                if ((data.transformMode == TransformMode.NoScaleOrReflection) ? (skeleton.flipX != skeleton.flipY) : (num5 * num8 - num6 * num7 < 0f))
                {
                    num14 = 0f - num14;
                    num15 = 0f - num15;
                }
                a = num11 * num16 + num14 * num18;
                b = num11 * num17 + num14 * num19;
                c = num12 * num16 + num15 * num18;
                d = num12 * num17 + num15 * num19;
                return;
            }
            }
            if (skeleton.flipX)
            {
                a = 0f - a;
                b = 0f - b;
            }
            if (skeleton.flipY != yDown)
            {
                c = 0f - c;
                d = 0f - d;
            }
        }
Ejemplo n.º 5
0
        /// <summary>Computes the world transform using the parent bone and the specified local transform.</summary>
        public void UpdateWorldTransform(float x, float y, float rotation, float scaleX, float scaleY, float shearX, float shearY)
        {
            ax           = x;
            ay           = y;
            arotation    = rotation;
            ascaleX      = scaleX;
            ascaleY      = scaleY;
            ashearX      = shearX;
            ashearY      = shearY;
            appliedValid = true;
            Skeleton skeleton = this.skeleton;

            Bone parent = this.parent;

            if (parent == null)               // Root bone.
            {
                float rotationY = rotation + 90 + shearY;
                float la        = MathUtils.CosDeg(rotation + shearX) * scaleX;
                float lb        = MathUtils.CosDeg(rotationY) * scaleY;
                float lc        = MathUtils.SinDeg(rotation + shearX) * scaleX;
                float ld        = MathUtils.SinDeg(rotationY) * scaleY;
                if (skeleton.flipX)
                {
                    x  = -x;
                    la = -la;
                    lb = -lb;
                }
                if (skeleton.flipY != yDown)
                {
                    y  = -y;
                    lc = -lc;
                    ld = -ld;
                }
                a      = la;
                b      = lb;
                c      = lc;
                d      = ld;
                worldX = x + skeleton.x;
                worldY = y + skeleton.y;
//				worldSignX = Math.Sign(scaleX);
//				worldSignY = Math.Sign(scaleY);
                return;
            }

            float pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;

            worldX = pa * x + pb * y + parent.worldX;
            worldY = pc * x + pd * y + parent.worldY;
//			worldSignX = parent.worldSignX * Math.Sign(scaleX);
//			worldSignY = parent.worldSignY * Math.Sign(scaleY);

            switch (data.transformMode)
            {
            case TransformMode.Normal: {
                float rotationY = rotation + 90 + shearY;
                float la        = MathUtils.CosDeg(rotation + shearX) * scaleX;
                float lb        = MathUtils.CosDeg(rotationY) * scaleY;
                float lc        = MathUtils.SinDeg(rotation + shearX) * scaleX;
                float ld        = MathUtils.SinDeg(rotationY) * scaleY;
                a = pa * la + pb * lc;
                b = pa * lb + pb * ld;
                c = pc * la + pd * lc;
                d = pc * lb + pd * ld;
                return;
            }

            case TransformMode.OnlyTranslation: {
                float rotationY = rotation + 90 + shearY;
                a = MathUtils.CosDeg(rotation + shearX) * scaleX;
                b = MathUtils.CosDeg(rotationY) * scaleY;
                c = MathUtils.SinDeg(rotation + shearX) * scaleX;
                d = MathUtils.SinDeg(rotationY) * scaleY;
                break;
            }

            case TransformMode.NoRotationOrReflection: {
                float s = pa * pa + pc * pc, prx;
                if (s > 0.0001f)
                {
                    s   = Math.Abs(pa * pd - pb * pc) / s;
                    pb  = pc * s;
                    pd  = pa * s;
                    prx = MathUtils.Atan2(pc, pa) * MathUtils.RadDeg;
                }
                else
                {
                    pa  = 0;
                    pc  = 0;
                    prx = 90 - MathUtils.Atan2(pd, pb) * MathUtils.RadDeg;
                }
                float rx = rotation + shearX - prx;
                float ry = rotation + shearY - prx + 90;
                float la = MathUtils.CosDeg(rx) * scaleX;
                float lb = MathUtils.CosDeg(ry) * scaleY;
                float lc = MathUtils.SinDeg(rx) * scaleX;
                float ld = MathUtils.SinDeg(ry) * scaleY;
                a = pa * la - pb * lc;
                b = pa * lb - pb * ld;
                c = pc * la + pd * lc;
                d = pc * lb + pd * ld;
                break;
            }

            case TransformMode.NoScale:
            case TransformMode.NoScaleOrReflection: {
                float cos = MathUtils.CosDeg(rotation), sin = MathUtils.SinDeg(rotation);
                float za = pa * cos + pb * sin;
                float zc = pc * cos + pd * sin;
                float s  = (float)Math.Sqrt(za * za + zc * zc);
                if (s > 0.00001f)
                {
                    s = 1 / s;
                }
                za *= s;
                zc *= s;
                s   = (float)Math.Sqrt(za * za + zc * zc);
                float r  = MathUtils.PI / 2 + MathUtils.Atan2(zc, za);
                float zb = MathUtils.Cos(r) * s;
                float zd = MathUtils.Sin(r) * s;
                float la = MathUtils.CosDeg(shearX) * scaleX;
                float lb = MathUtils.CosDeg(90 + shearY) * scaleY;
                float lc = MathUtils.SinDeg(shearX) * scaleX;
                float ld = MathUtils.SinDeg(90 + shearY) * scaleY;
                a = za * la + zb * lc;
                b = za * lb + zb * ld;
                c = zc * la + zd * lc;
                d = zc * lb + zd * ld;
                if (data.transformMode != TransformMode.NoScaleOrReflection ? pa * pd - pb * pc < 0 : skeleton.flipX != skeleton.flipY)
                {
                    b = -b;
                    d = -d;
                }
                return;
            }
            }

            if (skeleton.flipX)
            {
                a = -a;
                b = -b;
            }
            if (skeleton.flipY != Bone.yDown)
            {
                c = -c;
                d = -d;
            }
        }
Ejemplo n.º 6
0
        static BoneMatrix GetInheritedInternal(BoneData boneData, BoneMatrix parentMatrix)
        {
            var parent = boneData.parent;

            if (parent == null)
            {
                return(new BoneMatrix(boneData));                            // isRootBone
            }
            float      pa = parentMatrix.a, pb = parentMatrix.b, pc = parentMatrix.c, pd = parentMatrix.d;
            BoneMatrix result = default(BoneMatrix);

            result.x = pa * boneData.x + pb * boneData.y + parentMatrix.x;
            result.y = pc * boneData.x + pd * boneData.y + parentMatrix.y;

            switch (boneData.transformMode)
            {
            case TransformMode.Normal: {
                float rotationY = boneData.rotation + 90 + boneData.shearY;
                float la        = MathUtils.CosDeg(boneData.rotation + boneData.shearX) * boneData.scaleX;
                float lb        = MathUtils.CosDeg(rotationY) * boneData.scaleY;
                float lc        = MathUtils.SinDeg(boneData.rotation + boneData.shearX) * boneData.scaleX;
                float ld        = MathUtils.SinDeg(rotationY) * boneData.scaleY;
                result.a = pa * la + pb * lc;
                result.b = pa * lb + pb * ld;
                result.c = pc * la + pd * lc;
                result.d = pc * lb + pd * ld;
                break;
            }

            case TransformMode.OnlyTranslation: {
                float rotationY = boneData.rotation + 90 + boneData.shearY;
                result.a = MathUtils.CosDeg(boneData.rotation + boneData.shearX) * boneData.scaleX;
                result.b = MathUtils.CosDeg(rotationY) * boneData.scaleY;
                result.c = MathUtils.SinDeg(boneData.rotation + boneData.shearX) * boneData.scaleX;
                result.d = MathUtils.SinDeg(rotationY) * boneData.scaleY;
                break;
            }

            case TransformMode.NoRotationOrReflection: {
                float s = pa * pa + pc * pc, prx;
                if (s > 0.0001f)
                {
                    s   = Math.Abs(pa * pd - pb * pc) / s;
                    pb  = pc * s;
                    pd  = pa * s;
                    prx = MathUtils.Atan2(pc, pa) * MathUtils.RadDeg;
                }
                else
                {
                    pa  = 0;
                    pc  = 0;
                    prx = 90 - MathUtils.Atan2(pd, pb) * MathUtils.RadDeg;
                }
                float rx = boneData.rotation + boneData.shearX - prx;
                float ry = boneData.rotation + boneData.shearY - prx + 90;
                float la = MathUtils.CosDeg(rx) * boneData.scaleX;
                float lb = MathUtils.CosDeg(ry) * boneData.scaleY;
                float lc = MathUtils.SinDeg(rx) * boneData.scaleX;
                float ld = MathUtils.SinDeg(ry) * boneData.scaleY;
                result.a = pa * la - pb * lc;
                result.b = pa * lb - pb * ld;
                result.c = pc * la + pd * lc;
                result.d = pc * lb + pd * ld;
                break;
            }

            case TransformMode.NoScale:
            case TransformMode.NoScaleOrReflection: {
                float cos = MathUtils.CosDeg(boneData.rotation), sin = MathUtils.SinDeg(boneData.rotation);
                float za = pa * cos + pb * sin;
                float zc = pc * cos + pd * sin;
                float s  = (float)Math.Sqrt(za * za + zc * zc);
                if (s > 0.00001f)
                {
                    s = 1 / s;
                }
                za *= s;
                zc *= s;
                s   = (float)Math.Sqrt(za * za + zc * zc);
                float r  = MathUtils.PI / 2 + MathUtils.Atan2(zc, za);
                float zb = MathUtils.Cos(r) * s;
                float zd = MathUtils.Sin(r) * s;
                float la = MathUtils.CosDeg(boneData.shearX) * boneData.scaleX;
                float lb = MathUtils.CosDeg(90 + boneData.shearY) * boneData.scaleY;
                float lc = MathUtils.SinDeg(boneData.shearX) * boneData.scaleX;
                float ld = MathUtils.SinDeg(90 + boneData.shearY) * boneData.scaleY;
                if (boneData.transformMode != TransformMode.NoScaleOrReflection ? pa * pd - pb * pc < 0 : false)
                {
                    zb = -zb;
                    zd = -zd;
                }
                result.a = za * la + zb * lc;
                result.b = za * lb + zb * ld;
                result.c = zc * la + zd * lc;
                result.d = zc * lb + zd * ld;
                break;
            }
            }

            return(result);
        }
Ejemplo n.º 7
0
        public void UpdateWorldTransform(float x, float y, float rotation, float scaleX, float scaleY, float shearX, float shearY)
        {
            float num17;

            this.ax           = x;
            this.ay           = y;
            this.arotation    = rotation;
            this.ascaleX      = scaleX;
            this.ascaleY      = scaleY;
            this.ashearX      = shearX;
            this.ashearY      = shearY;
            this.appliedValid = true;
            Spine.Skeleton skeleton = this.skeleton;
            Bone           parent   = this.parent;

            if (parent == null)
            {
                float num  = (rotation + 90f) + shearY;
                float num2 = MathUtils.CosDeg(rotation + shearX) * scaleX;
                float num3 = MathUtils.CosDeg(num) * scaleY;
                float num4 = MathUtils.SinDeg(rotation + shearX) * scaleX;
                float num5 = MathUtils.SinDeg(num) * scaleY;
                if (skeleton.flipX)
                {
                    x    = -x;
                    num2 = -num2;
                    num3 = -num3;
                }
                if (skeleton.flipY != yDown)
                {
                    y    = -y;
                    num4 = -num4;
                    num5 = -num5;
                }
                this.a      = num2;
                this.b      = num3;
                this.c      = num4;
                this.d      = num5;
                this.worldX = x + skeleton.x;
                this.worldY = y + skeleton.y;
                return;
            }
            float a = parent.a;
            float b = parent.b;
            float c = parent.c;
            float d = parent.d;

            this.worldX = ((a * x) + (b * y)) + parent.worldX;
            this.worldY = ((c * x) + (d * y)) + parent.worldY;
            switch (this.data.transformMode)
            {
            case TransformMode.Normal:
            {
                float num10 = (rotation + 90f) + shearY;
                float num11 = MathUtils.CosDeg(rotation + shearX) * scaleX;
                float num12 = MathUtils.CosDeg(num10) * scaleY;
                float num13 = MathUtils.SinDeg(rotation + shearX) * scaleX;
                float num14 = MathUtils.SinDeg(num10) * scaleY;
                this.a = (a * num11) + (b * num13);
                this.b = (a * num12) + (b * num14);
                this.c = (c * num11) + (d * num13);
                this.d = (c * num12) + (d * num14);
                return;
            }

            case TransformMode.NoRotationOrReflection:
            {
                float num16 = (a * a) + (c * c);
                if (num16 <= 0.0001f)
                {
                    a     = 0f;
                    c     = 0f;
                    num17 = 90f - (MathUtils.Atan2(d, b) * 57.29578f);
                    break;
                }
                num16 = Math.Abs((float)((a * d) - (b * c))) / num16;
                b     = c * num16;
                d     = a * num16;
                num17 = MathUtils.Atan2(c, a) * 57.29578f;
                break;
            }

            case TransformMode.NoScale:
            case TransformMode.NoScaleOrReflection:
            {
                float num24 = MathUtils.CosDeg(rotation);
                float num25 = MathUtils.SinDeg(rotation);
                float num26 = (a * num24) + (b * num25);
                float num27 = (c * num24) + (d * num25);
                float num28 = (float)Math.Sqrt((double)((num26 * num26) + (num27 * num27)));
                if (num28 > 1E-05f)
                {
                    num28 = 1f / num28;
                }
                num26 *= num28;
                num27 *= num28;
                num28  = (float)Math.Sqrt((double)((num26 * num26) + (num27 * num27)));
                float radians = 1.570796f + MathUtils.Atan2(num27, num26);
                float num30   = MathUtils.Cos(radians) * num28;
                float num31   = MathUtils.Sin(radians) * num28;
                float num32   = MathUtils.CosDeg(shearX) * scaleX;
                float num33   = MathUtils.CosDeg(90f + shearY) * scaleY;
                float num34   = MathUtils.SinDeg(shearX) * scaleX;
                float num35   = MathUtils.SinDeg(90f + shearY) * scaleY;
                if ((this.data.transformMode == TransformMode.NoScaleOrReflection) ? (skeleton.flipX != skeleton.flipY) : (((a * d) - (b * c)) < 0f))
                {
                    num30 = -num30;
                    num31 = -num31;
                }
                this.a = (num26 * num32) + (num30 * num34);
                this.b = (num26 * num33) + (num30 * num35);
                this.c = (num27 * num32) + (num31 * num34);
                this.d = (num27 * num33) + (num31 * num35);
                return;
            }

            case TransformMode.OnlyTranslation:
            {
                float num15 = (rotation + 90f) + shearY;
                this.a = MathUtils.CosDeg(rotation + shearX) * scaleX;
                this.b = MathUtils.CosDeg(num15) * scaleY;
                this.c = MathUtils.SinDeg(rotation + shearX) * scaleX;
                this.d = MathUtils.SinDeg(num15) * scaleY;
                goto Label_04CC;
            }

            default:
                goto Label_04CC;
            }
            float degrees = (rotation + shearX) - num17;
            float num19   = ((rotation + shearY) - num17) + 90f;
            float num20   = MathUtils.CosDeg(degrees) * scaleX;
            float num21   = MathUtils.CosDeg(num19) * scaleY;
            float num22   = MathUtils.SinDeg(degrees) * scaleX;
            float num23   = MathUtils.SinDeg(num19) * scaleY;

            this.a = (a * num20) - (b * num22);
            this.b = (a * num21) - (b * num23);
            this.c = (c * num20) + (d * num22);
            this.d = (c * num21) + (d * num23);
Label_04CC:
            if (skeleton.flipX)
            {
                this.a = -this.a;
                this.b = -this.b;
            }
            if (skeleton.flipY != yDown)
            {
                this.c = -this.c;
                this.d = -this.d;
            }
        }
Ejemplo n.º 8
0
        public float LocalToWorldRotation(float localRotation)
        {
            float sin = MathUtils.SinDeg(localRotation), cos = MathUtils.CosDeg(localRotation);

            return(MathUtils.Atan2(cos * c + sin * d, cos * a + sin * b) * MathUtils.RadDeg);
        }
Ejemplo n.º 9
0
        public void UpdateWorldTransform(float x, float y, float rotation, float scaleX, float scaleY, float shearX, float shearY)
        {
            this.appliedRotation = rotation;
            float degrees = rotation + 90f + shearY;
            float num     = MathUtils.CosDeg(rotation + shearX) * scaleX;
            float num2    = MathUtils.CosDeg(degrees) * scaleY;
            float num3    = MathUtils.SinDeg(rotation + shearX) * scaleX;
            float num4    = MathUtils.SinDeg(degrees) * scaleY;
            Bone  bone    = this.parent;

            if (bone == null)
            {
                Skeleton skeleton = this.skeleton;
                if (skeleton.flipX)
                {
                    x    = -x;
                    num  = -num;
                    num2 = -num2;
                }
                if (skeleton.flipY != Bone.yDown)
                {
                    y    = -y;
                    num3 = -num3;
                    num4 = -num4;
                }
                this.a          = num;
                this.b          = num2;
                this.c          = num3;
                this.d          = num4;
                this.worldX     = x;
                this.worldY     = y;
                this.worldSignX = (float)Math.Sign(scaleX);
                this.worldSignY = (float)Math.Sign(scaleY);
                return;
            }
            float num5 = bone.a;
            float num6 = bone.b;
            float num7 = bone.c;
            float num8 = bone.d;

            this.worldX     = num5 * x + num6 * y + bone.worldX;
            this.worldY     = num7 * x + num8 * y + bone.worldY;
            this.worldSignX = bone.worldSignX * (float)Math.Sign(scaleX);
            this.worldSignY = bone.worldSignY * (float)Math.Sign(scaleY);
            if (this.data.inheritRotation && this.data.inheritScale)
            {
                this.a = num5 * num + num6 * num3;
                this.b = num5 * num2 + num6 * num4;
                this.c = num7 * num + num8 * num3;
                this.d = num7 * num2 + num8 * num4;
            }
            else
            {
                if (this.data.inheritRotation)
                {
                    num5 = 1f;
                    num6 = 0f;
                    num7 = 0f;
                    num8 = 1f;
                    do
                    {
                        float num9  = MathUtils.CosDeg(bone.appliedRotation);
                        float num10 = MathUtils.SinDeg(bone.appliedRotation);
                        float num11 = num5 * num9 + num6 * num10;
                        num6  = num6 * num9 - num5 * num10;
                        num5  = num11;
                        num11 = num7 * num9 + num8 * num10;
                        num8  = num8 * num9 - num7 * num10;
                        num7  = num11;
                        if (!bone.data.inheritRotation)
                        {
                            break;
                        }
                        bone = bone.parent;
                    }while (bone != null);
                    this.a = num5 * num + num6 * num3;
                    this.b = num5 * num2 + num6 * num4;
                    this.c = num7 * num + num8 * num3;
                    this.d = num7 * num2 + num8 * num4;
                }
                else if (this.data.inheritScale)
                {
                    num5 = 1f;
                    num6 = 0f;
                    num7 = 0f;
                    num8 = 1f;
                    do
                    {
                        float num12 = MathUtils.CosDeg(bone.appliedRotation);
                        float num13 = MathUtils.SinDeg(bone.appliedRotation);
                        float num14 = bone.scaleX;
                        float num15 = bone.scaleY;
                        float num16 = num12 * num14;
                        float num17 = num13 * num15;
                        float num18 = num13 * num14;
                        float num19 = num12 * num15;
                        float num20 = num5 * num16 + num6 * num18;
                        num6  = num6 * num19 - num5 * num17;
                        num5  = num20;
                        num20 = num7 * num16 + num8 * num18;
                        num8  = num8 * num19 - num7 * num17;
                        num7  = num20;
                        if (num14 >= 0f)
                        {
                            num13 = -num13;
                        }
                        num20 = num5 * num12 + num6 * num13;
                        num6  = num6 * num12 - num5 * num13;
                        num5  = num20;
                        num20 = num7 * num12 + num8 * num13;
                        num8  = num8 * num12 - num7 * num13;
                        num7  = num20;
                        if (!bone.data.inheritScale)
                        {
                            break;
                        }
                        bone = bone.parent;
                    }while (bone != null);
                    this.a = num5 * num + num6 * num3;
                    this.b = num5 * num2 + num6 * num4;
                    this.c = num7 * num + num8 * num3;
                    this.d = num7 * num2 + num8 * num4;
                }
                else
                {
                    this.a = num;
                    this.b = num2;
                    this.c = num3;
                    this.d = num4;
                }
                if (this.skeleton.flipX)
                {
                    this.a = -this.a;
                    this.b = -this.b;
                }
                if (this.skeleton.flipY != Bone.yDown)
                {
                    this.c = -this.c;
                    this.d = -this.d;
                }
            }
        }
Ejemplo n.º 10
0
        private static BoneMatrix GetInheritedInternal(BoneData boneData, BoneMatrix parentMatrix)
        {
            float num12;

            if (boneData.parent == null)
            {
                return(new BoneMatrix(boneData));
            }
            float      a      = parentMatrix.a;
            float      b      = parentMatrix.b;
            float      c      = parentMatrix.c;
            float      d      = parentMatrix.d;
            BoneMatrix matrix = new BoneMatrix {
                x = ((a * boneData.x) + (b * boneData.y)) + parentMatrix.x,
                y = ((c * boneData.x) + (d * boneData.y)) + parentMatrix.y
            };

            switch (boneData.transformMode)
            {
            case TransformMode.Normal:
            {
                float num5 = (boneData.rotation + 90f) + boneData.shearY;
                float num6 = MathUtils.CosDeg(boneData.rotation + boneData.shearX) * boneData.scaleX;
                float num7 = MathUtils.CosDeg(num5) * boneData.scaleY;
                float num8 = MathUtils.SinDeg(boneData.rotation + boneData.shearX) * boneData.scaleX;
                float num9 = MathUtils.SinDeg(num5) * boneData.scaleY;
                matrix.a = (a * num6) + (b * num8);
                matrix.b = (a * num7) + (b * num9);
                matrix.c = (c * num6) + (d * num8);
                matrix.d = (c * num7) + (d * num9);
                return(matrix);
            }

            case TransformMode.NoRotationOrReflection:
            {
                float num11 = (a * a) + (c * c);
                if (num11 <= 0.0001f)
                {
                    a     = 0f;
                    c     = 0f;
                    num12 = 90f - (MathUtils.Atan2(d, b) * 57.29578f);
                    break;
                }
                num11 = Math.Abs((float)((a * d) - (b * c))) / num11;
                b     = c * num11;
                d     = a * num11;
                num12 = MathUtils.Atan2(c, a) * 57.29578f;
                break;
            }

            case TransformMode.NoScale:
            case TransformMode.NoScaleOrReflection:
            {
                float num19 = MathUtils.CosDeg(boneData.rotation);
                float num20 = MathUtils.SinDeg(boneData.rotation);
                float x     = (a * num19) + (b * num20);
                float y     = (c * num19) + (d * num20);
                float num23 = (float)Math.Sqrt((double)((x * x) + (y * y)));
                if (num23 > 1E-05f)
                {
                    num23 = 1f / num23;
                }
                x    *= num23;
                y    *= num23;
                num23 = (float)Math.Sqrt((double)((x * x) + (y * y)));
                float radians = 1.570796f + MathUtils.Atan2(y, x);
                float num25   = MathUtils.Cos(radians) * num23;
                float num26   = MathUtils.Sin(radians) * num23;
                float num27   = MathUtils.CosDeg(boneData.shearX) * boneData.scaleX;
                float num28   = MathUtils.CosDeg(90f + boneData.shearY) * boneData.scaleY;
                float num29   = MathUtils.SinDeg(boneData.shearX) * boneData.scaleX;
                float num30   = MathUtils.SinDeg(90f + boneData.shearY) * boneData.scaleY;
                if ((boneData.transformMode != TransformMode.NoScaleOrReflection) && (((a * d) - (b * c)) < 0f))
                {
                    num25 = -num25;
                    num26 = -num26;
                }
                matrix.a = (x * num27) + (num25 * num29);
                matrix.b = (x * num28) + (num25 * num30);
                matrix.c = (y * num27) + (num26 * num29);
                matrix.d = (y * num28) + (num26 * num30);
                return(matrix);
            }

            case (TransformMode.NoScale | TransformMode.NoRotationOrReflection):
            case 4:
            case 5:
                return(matrix);

            case TransformMode.OnlyTranslation:
            {
                float num10 = (boneData.rotation + 90f) + boneData.shearY;
                matrix.a = MathUtils.CosDeg(boneData.rotation + boneData.shearX) * boneData.scaleX;
                matrix.b = MathUtils.CosDeg(num10) * boneData.scaleY;
                matrix.c = MathUtils.SinDeg(boneData.rotation + boneData.shearX) * boneData.scaleX;
                matrix.d = MathUtils.SinDeg(num10) * boneData.scaleY;
                return(matrix);
            }

            default:
                return(matrix);
            }
            float degrees = (boneData.rotation + boneData.shearX) - num12;
            float num14   = ((boneData.rotation + boneData.shearY) - num12) + 90f;
            float num15   = MathUtils.CosDeg(degrees) * boneData.scaleX;
            float num16   = MathUtils.CosDeg(num14) * boneData.scaleY;
            float num17   = MathUtils.SinDeg(degrees) * boneData.scaleX;
            float num18   = MathUtils.SinDeg(num14) * boneData.scaleY;

            matrix.a = (a * num15) - (b * num17);
            matrix.b = (a * num16) - (b * num18);
            matrix.c = (c * num15) + (d * num17);
            matrix.d = (c * num16) + (d * num18);
            return(matrix);
        }