Beispiel #1
0
        public static Vec2D TransformMat2(Vec2D o, Vec2D a, Mat2D m)
        {
            float x = a[0];
            float y = a[1];

            o[0] = m[0] * x + m[2] * y;
            o[1] = m[1] * x + m[3] * y;
            return(o);
        }
Beispiel #2
0
 static public void Copy(Mat2D o, Mat2D a)
 {
     o[0] = a[0];
     o[1] = a[1];
     o[2] = a[2];
     o[3] = a[3];
     o[4] = a[4];
     o[5] = a[5];
 }
Beispiel #3
0
 public Mat2D(Mat2D copy) : this()
 {
     m_Buffer[0] = copy.m_Buffer[0];
     m_Buffer[1] = copy.m_Buffer[1];
     m_Buffer[2] = copy.m_Buffer[2];
     m_Buffer[3] = copy.m_Buffer[3];
     m_Buffer[4] = copy.m_Buffer[4];
     m_Buffer[5] = copy.m_Buffer[5];
 }
Beispiel #4
0
 static public void Identity(Mat2D mat)
 {
     mat[0] = 1.0f;
     mat[1] = 0.0f;
     mat[2] = 0.0f;
     mat[3] = 1.0f;
     mat[4] = 0.0f;
     mat[5] = 0.0f;
 }
Beispiel #5
0
        static public void Scale(Mat2D o, Mat2D a, Vec2D v)
        {
            float a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], v0 = v[0], v1 = v[1];

            o[0] = a0 * v0;
            o[1] = a1 * v0;
            o[2] = a2 * v1;
            o[3] = a3 * v1;
            o[4] = a4;
            o[5] = a5;
        }
Beispiel #6
0
        static public void GetScale(Mat2D m, Vec2D s)
        {
            float x = m[0];
            float y = m[1];

            s[0] = Math.Sign(x) * (float)Math.Sqrt(x * x + y * y);

            x    = m[2];
            y    = m[3];
            s[1] = Math.Sign(y) * (float)Math.Sqrt(x * x + y * y);
        }
Beispiel #7
0
        static public void Multiply(Mat2D o, Mat2D a, Mat2D b)
        {
            float a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5],
                  b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5];

            o[0] = a0 * b0 + a2 * b1;
            o[1] = a1 * b0 + a3 * b1;
            o[2] = a0 * b2 + a2 * b3;
            o[3] = a1 * b2 + a3 * b3;
            o[4] = a0 * b4 + a2 * b5 + a4;
            o[5] = a1 * b4 + a3 * b5 + a5;
        }
Beispiel #8
0
        static public void FromRotation(Mat2D o, float rad)
        {
            float s = (float)Math.Sin(rad);
            float c = (float)Math.Cos(rad);

            o[0] = c;
            o[1] = s;
            o[2] = -s;
            o[3] = c;
            o[4] = 0;
            o[5] = 0;
        }
Beispiel #9
0
        static public void Decompose(Mat2D m, TransformComponents result)
        {
            float m0 = m[0], m1 = m[1], m2 = m[2], m3 = m[3];

            float rotation = (float)Math.Atan2(m1, m0);
            float denom    = m0 * m0 + m1 * m1;
            float scaleX   = (float)Math.Sqrt(denom);
            float scaleY   = (m0 * m3 - m2 * m1) / scaleX;
            float skewX    = (float)Math.Atan2(m0 * m2 + m1 * m3, denom);

            result[0] = m[4];
            result[1] = m[5];
            result[2] = scaleX;
            result[3] = scaleY;
            result[4] = rotation;
            result[5] = skewX;
        }
Beispiel #10
0
        static public float Decompose(Mat2D a, Vec2D s)
        {
            float a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
            float det = a0 * a3 - a2 * a1;
            float sx  = (float)Math.Sqrt(a0 * a0 + a1 * a1);
            float sy  = (float)Math.Sqrt(a2 * a2 + a3 * a3);

            if (det < 0)
            {
                sx = -sx;
            }

            s[0] = sx;
            s[1] = sy;

            return((float)Math.Atan2(a1 / sx, a0 / sx));
        }
Beispiel #11
0
        static public bool Invert(Mat2D o, Mat2D a)
        {
            float aa = a[0], ab = a[1], ac = a[2], ad = a[3], atx = a[4], aty = a[5];

            float det = aa * ad - ab * ac;

            if (det == 0.0f)
            {
                return(false);
            }
            det = 1.0f / det;

            o[0] = ad * det;
            o[1] = -ab * det;
            o[2] = -ac * det;
            o[3] = aa * det;
            o[4] = (ac * aty - ad * atx) * det;
            o[5] = (ab * atx - aa * aty) * det;
            return(true);
        }
Beispiel #12
0
        public void TransformDeformVertices(Nima.Math2D.Mat2D wt)
        {
            if (m_AnimationDeformedVertices == null)
            {
                return;
            }

            float[] fv = m_AnimationDeformedVertices;

            int vidx = 0;

            for (int j = 0; j < m_VertexCount; j++)
            {
                float x = fv[vidx];
                float y = fv[vidx + 1];

                fv[vidx]     = wt[0] * x + wt[2] * y + wt[4];
                fv[vidx + 1] = wt[1] * x + wt[3] * y + wt[5];

                vidx += 2;
            }
        }
Beispiel #13
0
        static public void Compose(Mat2D m, TransformComponents result)
        {
            float r = result[4];

            if (r != 0.0)
            {
                Mat2D.FromRotation(m, r);
            }
            else
            {
                Mat2D.Identity(m);
            }
            m[4] = result[0];
            m[5] = result[1];
            Mat2D.Scale(m, m, result.Scale);

            float sk = result[5];

            if (sk != 0.0)
            {
                m[2] = m[0] * sk + m[2];
                m[3] = m[1] * sk + m[3];
            }
        }
Beispiel #14
0
    public void Start()
    {
        m_Actor = gameObject.GetComponent <Nima.Unity.ActorBaseComponent>();
        if (m_Actor != null)
        {
            // Get a game object from the actor, use this to mount items or query for other components.
            // GameObject headColliderGameObject = m_Actor.GetActorGameObject("HeadCollider");
            // if(headColliderGameObject != null)
            // {
            //  Collider2D collider = headColliderGameObject.GetComponent<Collider2D>();
            //  if(collider != null)
            //  {
            //      // Set it to a trigger, or do something else with it...
            //      // collider.isTrigger = true;
            //  }
            // }
            if (m_Actor.ActorInstance != null)
            {
                m_Idle       = m_Actor.ActorInstance.GetAnimation("Idle");
                m_Aim        = m_Actor.ActorInstance.GetAnimation("Aim2");
                m_Walk       = m_Actor.ActorInstance.GetAnimationInstance("Walk");
                m_Run        = m_Actor.ActorInstance.GetAnimation("Run");
                m_WalkToIdle = m_Actor.ActorInstance.GetAnimation("WalkToIdle");

                // We made walk an animation instance so it has it's own sense of time which lets it do things like track events.
                m_Walk.AnimationEvent += delegate(object animationInstance, Nima.Animation.AnimationEventArgs args)
                {
                    // Event triggered from animation.
                };
                Nima.ActorNode characterNode = m_Actor.ActorInstance.GetNode("Character");
                if (characterNode != null)
                {
                    m_GroundSpeedProperty = characterNode.GetCustomFloatProperty("GroundSpeed");
                    m_IsRunningProperty   = characterNode.GetCustomBooleanProperty("IsRunning");
                }
                // Calculate aim slices.
                if (m_Aim != null)
                {
                    Nima.ActorNode muzzle = m_Actor.ActorInstance.GetNode("Muzzle");
                    if (muzzle != null)
                    {
                        for (int i = 0; i < AimSliceCount; i++)
                        {
                            float position = i / (float)(AimSliceCount - 1) * m_Aim.Duration;
                            m_Aim.Apply(position, m_Actor.ActorInstance, 1.0f);
                            m_Actor.ActorInstance.Advance(0.0f);
                            Nima.Math2D.Mat2D worldTransform = muzzle.WorldTransform;

                            AimSlice slice = m_AimLookup[i];

                            // Extract forward vector and position.
                            slice.dir = new Nima.Math2D.Vec2D();
                            Nima.Math2D.Vec2D.Normalize(slice.dir, new Nima.Math2D.Vec2D(worldTransform[0], worldTransform[1]));
                            slice.point = new Nima.Math2D.Vec2D(worldTransform[4] * Nima.Unity.ActorAsset.NimaToUnityScale,
                                                                worldTransform[5] * Nima.Unity.ActorAsset.NimaToUnityScale);
                            m_AimLookup[i] = slice;
                        }
                    }
                    if (m_Walk != null)
                    {
                        m_Walk.Time = 0.0f;
                        m_Walk.Apply(1.0f);

                        for (int i = 0; i < AimSliceCount; i++)
                        {
                            float position = i / (float)(AimSliceCount - 1) * m_Aim.Duration;
                            m_Aim.Apply(position, m_Actor.ActorInstance, 1.0f);
                            m_Actor.ActorInstance.Advance(0.0f);
                            Nima.Math2D.Mat2D worldTransform = muzzle.WorldTransform;

                            AimSlice slice = m_AimWalkingLookup[i];

                            // Extract forward vector and position.
                            slice.dir = new Nima.Math2D.Vec2D();
                            Nima.Math2D.Vec2D.Normalize(slice.dir, new Nima.Math2D.Vec2D(worldTransform[0], worldTransform[1]));
                            slice.point = new Nima.Math2D.Vec2D(worldTransform[4] * Nima.Unity.ActorAsset.NimaToUnityScale,
                                                                worldTransform[5] * Nima.Unity.ActorAsset.NimaToUnityScale);
                            m_AimWalkingLookup[i] = slice;
                        }
                    }
                }
            }
        }
        m_IdleTime = 0.0f;
    }