Esempio n. 1
0
        public void TestLerpCollinearVectors()
        {
            {
                Vector2 p = new Vector2(1.0f, 0f);
                Vector2 q = new Vector2(-1.0f, 0f);

                //middle of interpolation will be (0,0)
                Vector2 yVector = new Vector2(0, 0);

                Vector2 result = Vector2.Lerp(p, q, 0.5f);
                Assert.IsTrue(NativeExtensions.TestVectorsAreEqual(result, yVector), "Lerp Collinear Vector2 fails, result is :" + result.ToString());
            }
            {
                Vec2 p = new Vec2(1.0f, 0f);
                Vec2 q = new Vec2(-1.0f, 0f);

                //middle of interpolation will be (0,0)
                Vec2 yVector = new Vec2(0, 0);

                Vec2 result = Vec2.CreateLerp(p, q, 0.5f);
                Assert.IsTrue(NativeExtensions.TestVectorsAreEqual(result, yVector), "Lerp Collinear Vec2 fails, result is :" + result.ToString());
            }
        }
Esempio n. 2
0
        public void TestLerp()
        {
            {
                //native
                Vec2 vec2p   = new Vec2(1f, 1f);
                Vec2 vec2q   = new Vec2(10.0f, 10.0f);
                Vec2 vec2Mid = Vec2.CreateLerp(vec2p, vec2q, 0.5f);
                //managed
                Vector2 vector2p   = new Vector2(vec2p.x, vec2p.y);
                Vector2 vector2q   = new Vector2(vec2q.x, vec2q.y);
                Vector2 vector2Mid = Vector2.Lerp(vector2p, vector2q, 0.5f);

                Assert.IsTrue(vec2Mid == vector2Mid, " Lerp tests fails for native and managed vector2 1");
            }

            {
                //native
                Vec2 vec2p     = new Vec2(1f, 1f);
                Vec2 vec2q     = new Vec2(10.0f, 10.0f);
                Vec2 vec2Start = Vec2.CreateLerp(vec2p, vec2q, 0.0f);
                //managed
                Vector2 vector2p     = new Vector2(vec2p.x, vec2p.y);
                Vector2 vector2q     = new Vector2(vec2q.x, vec2q.y);
                Vector2 vector2Start = Vector2.Lerp(vector2p, vector2q, 0f);

                Assert.IsTrue(vec2Start == vector2Start, " Lerp tests fails 2a");
                Assert.IsTrue(MathHelpers.Approximately(vec2Start.x, vec2p.x) && MathHelpers.Approximately(vec2Start.y, vec2p.y), " Lerp tests fails 2b");
                Assert.IsTrue(vector2Start == vector2p, " Lerp tests fails 2c");
            }
            {
                //native
                Vec2 vec2p   = new Vec2(1f, 1f);
                Vec2 vec2q   = new Vec2(10.0f, 10.0f);
                Vec2 vec2End = Vec2.CreateLerp(vec2p, vec2q, 1.0f);
                //managed
                Vector2 vector2p   = new Vector2(vec2p.x, vec2p.y);
                Vector2 vector2q   = new Vector2(vec2q.x, vec2q.y);
                Vector2 vector2End = Vector2.Lerp(vector2p, vector2q, 1.0f);

                Assert.IsTrue(vec2End == vector2End, " Lerp tests fails for native and managed vector2 3a");
                Assert.IsTrue(MathHelpers.Approximately(vec2End.x, vec2q.x) && MathHelpers.Approximately(vec2End.y, vec2q.y), " Lerp tests fails for native and managed vector2 3b");
                Assert.IsTrue(vector2End == vector2q, " Lerp tests fails for native and managed vector2 3c");
            }

            {
                //test clamping
                //managed
                Vector2 vector2p   = new Vector2(1f, 1f);
                Vector2 vector2q   = new Vector2(10f, 10f);
                Vector2 vector2End = Vector2.Lerp(vector2p, vector2q, 1.1f);

                Assert.IsTrue(vector2End == vector2q, " Lerp tests fails for managed vector2 3d");
            }

            {
                //test clamping
                //managed
                Vector2 vector2p   = new Vector2(1f, 1f);
                Vector2 vector2q   = new Vector2(10f, 10f);
                Vector2 vector2End = Vector2.Lerp(vector2p, vector2q, -0.1f);

                Assert.IsTrue(vector2End == vector2p, " Lerp tests fails for managed vector2 3e");
            }
        }