CosDeg() static public method

Returns the cosine in radians from a lookup table.
static public CosDeg ( float degrees ) : float
degrees float
return float
Exemplo n.º 1
0
        public float WorldToLocalRotation(float worldRotation)
        {
            float num  = MathUtils.SinDeg(worldRotation);
            float num2 = MathUtils.CosDeg(worldRotation);

            return(MathUtils.Atan2(a * num - c * num2, d * num2 - b * num) * (180f / (float)Math.PI));
        }
Exemplo n.º 2
0
        public float LocalToWorldRotation(float localRotation)
        {
            float num  = MathUtils.SinDeg(localRotation);
            float num2 = MathUtils.CosDeg(localRotation);

            return(MathUtils.Atan2(num2 * c + num * d, num2 * a + num * b) * (180f / (float)Math.PI));
        }
Exemplo n.º 3
0
        public float WorldToLocalRotation(float worldRotation)
        {
            float num  = MathUtils.SinDeg(worldRotation);
            float num2 = MathUtils.CosDeg(worldRotation);

            return(MathUtils.Atan2((this.a * num) - (this.c * num2), (this.d * num2) - (this.b * num)) * 57.29578f);
        }
Exemplo n.º 4
0
        public float LocalToWorldRotation(float localRotation)
        {
            float num  = MathUtils.SinDeg(localRotation);
            float num2 = MathUtils.CosDeg(localRotation);

            return(MathUtils.Atan2((num2 * this.c) + (num * this.d), (num2 * this.a) + (num * this.b)) * 57.29578f);
        }
Exemplo n.º 5
0
        public float LocalToWorldRotation(float localRotation)
        {
            localRotation -= rotation - shearX;
            float sin = MathUtils.SinDeg(localRotation), cos = MathUtils.CosDeg(localRotation);

            return(MathUtils.Atan2(cos * c + sin * d, cos * a + sin * b) * MathUtils.RadDeg);
        }
Exemplo n.º 6
0
        public void UpdateOffset()
        {
            float regionScaleX = width / regionOriginalWidth * scaleX;
            float regionScaleY = height / regionOriginalHeight * scaleY;
            float localX = -width / 2 * scaleX + regionOffsetX * regionScaleX;
            float localY = -height / 2 * scaleY + regionOffsetY * regionScaleY;
            float localX2 = localX + regionWidth * regionScaleX;
            float localY2 = localY + regionHeight * regionScaleY;
            float cos = MathUtils.CosDeg(this.rotation);
            float sin = MathUtils.SinDeg(this.rotation);
            float x = this.x, y = this.y;
            float localXCos  = localX * cos + x;
            float localXSin  = localX * sin;
            float localYCos  = localY * cos + y;
            float localYSin  = localY * sin;
            float localX2Cos = localX2 * cos + x;
            float localX2Sin = localX2 * sin;
            float localY2Cos = localY2 * cos + y;
            float localY2Sin = localY2 * sin;

            float[] offset = this.offset;
            offset[BLX] = localXCos - localYSin;
            offset[BLY] = localYCos + localXSin;
            offset[ULX] = localXCos - localY2Sin;
            offset[ULY] = localY2Cos + localXSin;
            offset[URX] = localX2Cos - localY2Sin;
            offset[URY] = localY2Cos + localX2Sin;
            offset[BRX] = localX2Cos - localYSin;
            offset[BRY] = localYCos + localX2Sin;
        }
Exemplo n.º 7
0
        public float ComputeWorldRotation(Bone bone)
        {
            float num  = MathUtils.CosDeg(rotation);
            float num2 = MathUtils.SinDeg(rotation);
            float num3 = num * bone.a + num2 * bone.b;
            float num4 = num * bone.c + num2 * bone.d;

            return(MathUtils.Atan2(num4, num3) * (180f / (float)Math.PI));
        }
Exemplo n.º 8
0
        public float ComputeWorldRotation(Bone bone)
        {
            float num  = MathUtils.CosDeg(this.rotation);
            float num2 = MathUtils.SinDeg(this.rotation);
            float x    = (num * bone.a) + (num2 * bone.b);
            float y    = (num * bone.c) + (num2 * bone.d);

            return(MathUtils.Atan2(y, x) * 57.29578f);
        }
Exemplo n.º 9
0
        public void RotateWorld(float degrees)
        {
            float a = this.a, b = this.b, c = this.c, d = this.d;
            float cos = MathUtils.CosDeg(degrees), sin = MathUtils.SinDeg(degrees);

            this.a = cos * a - sin * c;
            this.b = cos * b - sin * d;
            this.c = sin * a + cos * c;
            this.d = sin * b + cos * d;
        }
Exemplo n.º 10
0
        /// <summary>Constructor for a local bone matrix based on a bone instance's current pose.</summary>
        public BoneMatrix(Bone bone)
        {
            float rotationY = bone.rotation + 90 + bone.shearY;
            float rotationX = bone.rotation + bone.shearX;

            a = MathUtils.CosDeg(rotationX) * bone.scaleX;
            c = MathUtils.SinDeg(rotationX) * bone.scaleX;
            b = MathUtils.CosDeg(rotationY) * bone.scaleY;
            d = MathUtils.SinDeg(rotationY) * bone.scaleY;
            x = bone.x;
            y = bone.y;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Updates the world transform for each bone and applies all constraints. The root bone will be temporarily parented to the specified bone.
        /// </summary>
        public void UpdateWorldTransform(Bone parent)
        {
            // This partial update avoids computing the world transform for constrained bones when 1) the bone is not updated
            // before the constraint, 2) the constraint only needs to access the applied local transform, and 3) the constraint calls
            // updateWorldTransform.
            var updateCacheReset      = this.updateCacheReset;
            var updateCacheResetItems = updateCacheReset.Items;

            for (int i = 0, n = updateCacheReset.Count; i < n; i++)
            {
                Bone bone = updateCacheResetItems[i];
                bone.ax           = bone.x;
                bone.ay           = bone.y;
                bone.arotation    = bone.rotation;
                bone.ascaleX      = bone.scaleX;
                bone.ascaleY      = bone.scaleY;
                bone.ashearX      = bone.shearX;
                bone.ashearY      = bone.shearY;
                bone.appliedValid = true;
            }

            // Apply the parent bone transform to the root bone. The root bone
            // always inherits scale, rotation and reflection.
            Bone  rootBone = this.RootBone;
            float pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;

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

            float rotationY = rootBone.rotation + 90 + rootBone.shearY;
            float la        = MathUtils.CosDeg(rootBone.rotation + rootBone.shearX) * rootBone.scaleX;
            float lb        = MathUtils.CosDeg(rotationY) * rootBone.scaleY;
            float lc        = MathUtils.SinDeg(rootBone.rotation + rootBone.shearX) * rootBone.scaleX;
            float ld        = MathUtils.SinDeg(rotationY) * rootBone.scaleY;

            rootBone.a = (pa * la + pb * lc) * scaleX;
            rootBone.b = (pa * lb + pb * ld) * scaleX;
            rootBone.c = (pc * la + pd * lc) * scaleY;
            rootBone.d = (pc * lb + pd * ld) * scaleY;

            // Update everything except root bone.
            var updateCache      = this.updateCache;
            var updateCacheItems = updateCache.Items;

            for (int i = 0, n = updateCache.Count; i < n; i++)
            {
                var updatable = updateCacheItems[i];
                if (updatable != rootBone)
                {
                    updatable.Update();
                }
            }
        }
Exemplo n.º 12
0
        public BoneMatrix(Bone bone)
        {
            float degrees = (bone.rotation + 90f) + bone.shearY;
            float num2    = bone.rotation + bone.shearX;

            this.a = MathUtils.CosDeg(num2) * bone.scaleX;
            this.c = MathUtils.SinDeg(num2) * bone.scaleX;
            this.b = MathUtils.CosDeg(degrees) * bone.scaleY;
            this.d = MathUtils.SinDeg(degrees) * bone.scaleY;
            this.x = bone.x;
            this.y = bone.y;
        }
Exemplo n.º 13
0
        /// <summary>Constructor for a local bone matrix based on Setup Pose BoneData.</summary>
        public BoneMatrix(BoneData boneData)
        {
            float rotationY = boneData.Rotation + 90 + boneData.ShearY;
            float rotationX = boneData.Rotation + boneData.ShearX;

            a = MathUtils.CosDeg(rotationX) * boneData.ScaleX;
            c = MathUtils.SinDeg(rotationX) * boneData.ScaleX;
            b = MathUtils.CosDeg(rotationY) * boneData.ScaleY;
            d = MathUtils.SinDeg(rotationY) * boneData.ScaleY;
            x = boneData.X;
            y = boneData.Y;
        }
Exemplo n.º 14
0
        public void RotateWorld(float degrees)
        {
            float num  = this.a;
            float num2 = this.b;
            float num3 = this.c;
            float num4 = this.d;
            float num5 = MathUtils.CosDeg(degrees);
            float num6 = MathUtils.SinDeg(degrees);

            this.a = num5 * num - num6 * num3;
            this.b = num5 * num2 - num6 * num4;
            this.c = num6 * num + num5 * num3;
            this.d = num6 * num2 + num5 * num4;
        }
Exemplo n.º 15
0
        public void RotateWorld(float degrees)
        {
            float num  = a;
            float num2 = b;
            float num3 = c;
            float num4 = d;
            float num5 = MathUtils.CosDeg(degrees);
            float num6 = MathUtils.SinDeg(degrees);

            a            = num5 * num - num6 * num3;
            b            = num5 * num2 - num6 * num4;
            c            = num6 * num + num5 * num3;
            d            = num6 * num2 + num5 * num4;
            appliedValid = false;
        }
Exemplo n.º 16
0
        public void RotateWorld(float degrees)
        {
            float a    = this.a;
            float b    = this.b;
            float c    = this.c;
            float d    = this.d;
            float num5 = MathUtils.CosDeg(degrees);
            float num6 = MathUtils.SinDeg(degrees);

            this.a            = (num5 * a) - (num6 * c);
            this.b            = (num5 * b) - (num6 * d);
            this.c            = (num6 * a) + (num5 * c);
            this.d            = (num6 * b) + (num5 * d);
            this.appliedValid = false;
        }
        public void UpdateOffset()
        {
            float width   = this.width;
            float height  = this.height;
            float localX2 = width * 0.5f;
            float localY2 = height * 0.5f;
            float localX  = -localX2;
            float localY  = -localY2;

            if (regionOriginalWidth != 0)               // if (region != null)
            {
                localX  += regionOffsetX / regionOriginalWidth * width;
                localY  += regionOffsetY / regionOriginalHeight * height;
                localX2 -= (regionOriginalWidth - regionOffsetX - regionWidth) / regionOriginalWidth * width;
                localY2 -= (regionOriginalHeight - regionOffsetY - regionHeight) / regionOriginalHeight * height;
            }
            float scaleX = this.scaleX;
            float scaleY = this.scaleY;

            localX  *= scaleX;
            localY  *= scaleY;
            localX2 *= scaleX;
            localY2 *= scaleY;
            float rotation   = this.rotation;
            float cos        = MathUtils.CosDeg(rotation);
            float sin        = MathUtils.SinDeg(rotation);
            float x          = this.x;
            float y          = this.y;
            float localXCos  = localX * cos + x;
            float localXSin  = localX * sin;
            float localYCos  = localY * cos + y;
            float localYSin  = localY * sin;
            float localX2Cos = localX2 * cos + x;
            float localX2Sin = localX2 * sin;
            float localY2Cos = localY2 * cos + y;
            float localY2Sin = localY2 * sin;

            float[] offset = this.offset;
            offset[BLX] = localXCos - localYSin;
            offset[BLY] = localYCos + localXSin;
            offset[ULX] = localXCos - localY2Sin;
            offset[ULY] = localY2Cos + localXSin;
            offset[URX] = localX2Cos - localY2Sin;
            offset[URY] = localY2Cos + localX2Sin;
            offset[BRX] = localX2Cos - localYSin;
            offset[BRY] = localYCos + localX2Sin;
        }
Exemplo n.º 18
0
        /// <summary>
        /// Temporarily sets the root bone as a child of the specified bone, then updates the world transform for each bone and applies
        /// all constraints.
        /// </summary>
        public void UpdateWorldTransform(Bone parent)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent", "parent cannot be null.");
            }

            // Apply the parent bone transform to the root bone. The root bone always inherits scale, rotation and reflection.
            Bone  rootBone = this.RootBone;
            float pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;

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

            float rotationY = rootBone.rotation + 90 + rootBone.shearY;
            float la        = MathUtils.CosDeg(rootBone.rotation + rootBone.shearX) * rootBone.scaleX;
            float lb        = MathUtils.CosDeg(rotationY) * rootBone.scaleY;
            float lc        = MathUtils.SinDeg(rootBone.rotation + rootBone.shearX) * rootBone.scaleX;
            float ld        = MathUtils.SinDeg(rotationY) * rootBone.scaleY;

            rootBone.a = (pa * la + pb * lc) * scaleX;
            rootBone.b = (pa * lb + pb * ld) * scaleX;
            rootBone.c = (pc * la + pd * lc) * scaleY;
            rootBone.d = (pc * lb + pd * ld) * scaleY;

            // Update everything except root bone.
            var updateCache = this.updateCache.Items;

            for (int i = 0, n = this.updateCache.Count; i < n; i++)
            {
                var updatable = updateCache[i];
                if (updatable != rootBone)
                {
                    updatable.Update();
                }
            }
        }
Exemplo n.º 19
0
        public void UpdateOffset()
        {
            float width        = this.width;
            float height       = this.height;
            float scaleX       = this.scaleX;
            float scaleY       = this.scaleY;
            float regionScaleX = width / regionOriginalWidth * scaleX;
            float regionScaleY = height / regionOriginalHeight * scaleY;
            float localX       = -width / 2 * scaleX + regionOffsetX * regionScaleX;
            float localY       = -height / 2 * scaleY + regionOffsetY * regionScaleY;
            float localX2      = localX + regionWidth * regionScaleX;
            float localY2      = localY + regionHeight * regionScaleY;
            float rotation     = this.rotation;
            float cos          = MathUtils.CosDeg(rotation);
            float sin          = MathUtils.SinDeg(rotation);
            float x            = this.x;
            float y            = this.y;
            float localXCos    = localX * cos + x;
            float localXSin    = localX * sin;
            float localYCos    = localY * cos + y;
            float localYSin    = localY * sin;
            float localX2Cos   = localX2 * cos + x;
            float localX2Sin   = localX2 * sin;
            float localY2Cos   = localY2 * cos + y;
            float localY2Sin   = localY2 * sin;

            float[] offset = this.offset;
            offset[X1] = localXCos - localYSin;
            offset[Y1] = localYCos + localXSin;
            offset[X2] = localXCos - localY2Sin;
            offset[Y2] = localY2Cos + localXSin;
            offset[X3] = localX2Cos - localY2Sin;
            offset[Y3] = localY2Cos + localX2Sin;
            offset[X4] = localX2Cos - localYSin;
            offset[Y4] = localYCos + localX2Sin;
        }
Exemplo n.º 20
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.
            {
                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;
                }
                if (yDown)
                {
                    pb = -pb;
                    pd = -pd;
                }
                a = pa * la + pb * lc;
                b = pa * lb + pb * ld;
                c = pc * la + pd * lc;
                d = pc * lb + pd * ld;
                if (skeleton.flipX)
                {
                    a = -a;
                    b = -b;
                }
                if (skeleton.flipY)
                {
                    c = -c;
                    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;
                    cos = MathUtils.CosDeg(r);
                    sin = MathUtils.SinDeg(r);
                    float psx = p.appliedScaleX, psy = p.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;

                    p = p.parent;
                }
                if (yDown)
                {
                    pb = -pb;
                    pd = -pd;
                }
                a = pa * la + pb * lc;
                b = pa * lb + pb * ld;
                c = pc * la + pd * lc;
                d = pc * lb + pd * ld;
                if (skeleton.flipX)
                {
                    a = -a;
                    b = -b;
                }
                if (skeleton.flipY)
                {
                    c = -c;
                    d = -d;
                }
            }
            else
            {
                a = la;
                b = lb;
                c = lc;
                d = ld;
            }
        }
Exemplo n.º 21
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;
                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;
                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;
                if (data.transformMode != TransformMode.NoScaleOrReflection
                        ? pa * pd - pb * pc < 0
                        : skeleton.flipX != skeleton.flipY)
                {
                    zb = -zb;
                    zd = -zd;
                }

                a = za * la + zb * lc;
                b = za * lb + zb * ld;
                c = zc * la + zd * lc;
                d = zc * lb + zd * ld;
                return;
            }
            }

            if (skeleton.flipX)
            {
                a = -a;
                b = -b;
            }

            if (skeleton.flipY != Bone.yDown)
            {
                c = -c;
                d = -d;
            }
        }
Exemplo n.º 22
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);
        }
Exemplo n.º 23
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 * sx;
                c      = MathUtils.SinDeg(rotation + shearX) * scaleX * sy;
                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;
                return;
            }

            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;
        }
Exemplo n.º 24
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);
        }
Exemplo n.º 25
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;
                }
            }
        }
Exemplo n.º 26
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;
            }
        }
Exemplo n.º 27
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;
            }
        }
Exemplo n.º 28
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);
        }
Exemplo n.º 29
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)
        {
            appliedRotation = rotation;

            float rotationY = rotation + 90 + shearY;
            float la = MathUtils.CosDeg(rotation + shearX) * scaleX, lb = MathUtils.CosDeg(rotationY) * scaleY;
            float lc = MathUtils.SinDeg(rotation + shearX) * scaleX, ld = MathUtils.SinDeg(rotationY) * 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
                    {
                        float cos = MathUtils.CosDeg(parent.appliedRotation), sin = MathUtils.SinDeg(parent.appliedRotation);
                        float temp = pa * cos + pb * sin;
                        pb   = pb * cos - pa * sin;
                        pa   = temp;
                        temp = pc * cos + pd * sin;
                        pd   = pd * cos - pc * sin;
                        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 cos = MathUtils.CosDeg(parent.appliedRotation), sin = MathUtils.SinDeg(parent.appliedRotation);
                        float psx = parent.scaleX, psy = parent.scaleY;
                        float za = cos * psx, zb = sin * psy, zc = sin * psx, zd = cos * psy;
                        float temp = pa * za + pb * zc;
                        pb   = pb * zd - pa * zb;
                        pa   = temp;
                        temp = pc * za + pd * zc;
                        pd   = pd * zd - pc * zb;
                        pc   = temp;

                        if (psx >= 0)
                        {
                            sin = -sin;
                        }
                        temp = pa * cos + pb * sin;
                        pb   = pb * cos - pa * sin;
                        pa   = temp;
                        temp = pc * cos + pd * sin;
                        pd   = pd * cos - pc * sin;
                        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;
                }
            }
        }