Esempio n. 1
0
        public void BarycentricByRefTest()
        {
            Quaternion value1         = Utilities.GenerateQuaternion();
            Quaternion value1Expected = value1;
            Quaternion value2         = Utilities.GenerateQuaternion();
            Quaternion value2Expected = value2;
            Quaternion value3         = Utilities.GenerateQuaternion();
            Quaternion value3Expected = value3;
            float      amount1        = Utilities.GenerateFloat();
            float      amount2        = Utilities.GenerateFloat();
            Quaternion result;

            Quaternion resultExpected = Utilities.ConvertFrom(Microsoft.DirectX.Quaternion.BaryCentric(
                                                                  Utilities.ConvertToMdx(value1),
                                                                  Utilities.ConvertToMdx(value2),
                                                                  Utilities.ConvertToMdx(value3),
                                                                  amount1,
                                                                  amount2));

            Quaternion.Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out result);
            Utilities.AreEqual(value1Expected, value1);
            Utilities.AreEqual(value2Expected, value2);
            Utilities.AreEqual(value3Expected, value3);
            Utilities.AreEqual(resultExpected, result);
        }
Esempio n. 2
0
        public void SquadByRefTest()
        {
            Quaternion value1         = Utilities.GenerateQuaternion();
            Quaternion value1Expected = value1;
            Quaternion value2         = Utilities.GenerateQuaternion();
            Quaternion value2Expected = value2;
            Quaternion value3         = Utilities.GenerateQuaternion();
            Quaternion value3Expected = value3;
            Quaternion value4         = Utilities.GenerateQuaternion();
            Quaternion value4Expected = value4;
            float      amount         = Utilities.GenerateFloat();
            Quaternion result;

            Quaternion resultExpected = Utilities.ConvertFrom(Microsoft.DirectX.Quaternion.Squad(
                                                                  Utilities.ConvertToMdx(value1),
                                                                  Utilities.ConvertToMdx(value2),
                                                                  Utilities.ConvertToMdx(value3),
                                                                  Utilities.ConvertToMdx(value4),
                                                                  amount));

            Quaternion.Squad(ref value1, ref value2, ref value3, ref value4, amount, out result);
            Utilities.AreEqual(value1Expected, value1);
            Utilities.AreEqual(value2Expected, value2);
            Utilities.AreEqual(value3Expected, value3);
            Utilities.AreEqual(value4Expected, value4);
            Utilities.AreEqual(resultExpected, result);
        }
Esempio n. 3
0
        public void QuaternionConstructorTest3()
        {
            float      value  = Utilities.GenerateFloat();
            Quaternion target = new Quaternion(value);

            Utilities.AreEqual(value, target.X, 0f);
            Utilities.AreEqual(value, target.Y, 0f);
            Utilities.AreEqual(value, target.Z, 0f);
            Utilities.AreEqual(value, target.W, 0f);
        }
Esempio n. 4
0
        public void QuaternionConstructorTest5()
        {
            Vector3    value  = Utilities.GenerateVector3();
            float      w      = Utilities.GenerateFloat();
            Quaternion target = new Quaternion(value, w);

            Utilities.AreEqual(value.X, target.X, 0f);
            Utilities.AreEqual(value.Y, target.Y, 0f);
            Utilities.AreEqual(value.Z, target.Z, 0f);
            Utilities.AreEqual(w, target.W, 0f);
        }
Esempio n. 5
0
        public void QuaternionConstructorTest1()
        {
            float      x      = Utilities.GenerateFloat();
            float      y      = Utilities.GenerateFloat();
            float      z      = Utilities.GenerateFloat();
            float      w      = Utilities.GenerateFloat();
            Quaternion target = new Quaternion(x, y, z, w);

            Utilities.AreEqual(x, target.X, 0f);
            Utilities.AreEqual(y, target.Y, 0f);
            Utilities.AreEqual(z, target.Z, 0f);
            Utilities.AreEqual(w, target.W, 0f);
        }
Esempio n. 6
0
        public void RotationAxisTest()
        {
            Vector3 axis  = Utilities.GenerateVector3();
            float   angle = Utilities.GenerateFloat();

            Quaternion expected = Utilities.ConvertFrom(Microsoft.DirectX.Quaternion.RotationAxis(
                                                            Utilities.ConvertToMdx(axis),
                                                            angle));

            Quaternion actual;

            actual = Quaternion.RotationAxis(axis, angle);
            Utilities.AreEqual(expected, actual);
        }
Esempio n. 7
0
        public void op_MultiplyTest()
        {
            float      scale = Utilities.GenerateFloat();
            Quaternion value = Utilities.GenerateQuaternion();

            Quaternion expected = Utilities.ConvertFrom(Microsoft.Xna.Framework.Quaternion.Multiply(
                                                            Utilities.ConvertToXna(value),
                                                            scale));

            Quaternion actual;

            actual = (scale * value);
            Utilities.AreEqual(expected, actual);
        }
Esempio n. 8
0
        public void RotationYawPitchRollByRefTest()
        {
            float      yaw   = Utilities.GenerateFloat();
            float      pitch = Utilities.GenerateFloat();
            float      roll  = Utilities.GenerateFloat();
            Quaternion result;

            Quaternion resultExpected = Utilities.ConvertFrom(Microsoft.Xna.Framework.Quaternion.CreateFromYawPitchRoll(
                                                                  yaw,
                                                                  pitch,
                                                                  roll));

            Quaternion.RotationYawPitchRoll(yaw, pitch, roll, out result);
            Utilities.AreEqual(resultExpected, result);
        }
Esempio n. 9
0
        public void RotationAxisByRefTest()
        {
            Vector3    axis         = Utilities.GenerateVector3();
            Vector3    axisExpected = axis;
            float      angle        = Utilities.GenerateFloat();
            Quaternion result;

            Quaternion resultExpected = Utilities.ConvertFrom(Microsoft.DirectX.Quaternion.RotationAxis(
                                                                  Utilities.ConvertToMdx(axis),
                                                                  angle));

            Quaternion.RotationAxis(ref axis, angle, out result);
            Utilities.AreEqual(axisExpected, axis);
            Utilities.AreEqual(resultExpected, result);
        }
Esempio n. 10
0
        public void MultiplyScaleByRefTest()
        {
            Quaternion value         = Utilities.GenerateQuaternion();
            Quaternion valueExpected = value;
            float      scale         = Utilities.GenerateFloat();
            Quaternion result;

            Quaternion resultExpected = Utilities.ConvertFrom(Microsoft.Xna.Framework.Quaternion.Multiply(
                                                                  Utilities.ConvertToXna(value),
                                                                  scale));

            Quaternion.Multiply(ref value, scale, out result);
            Utilities.AreEqual(valueExpected, value);
            Utilities.AreEqual(resultExpected, result);
        }
Esempio n. 11
0
        public void SlerpTest()
        {
            Quaternion start  = Utilities.GenerateQuaternion();
            Quaternion end    = Utilities.GenerateQuaternion();
            float      amount = Utilities.GenerateFloat();

            Quaternion expected = Utilities.ConvertFrom(Microsoft.Xna.Framework.Quaternion.Slerp(
                                                            Utilities.ConvertToXna(start),
                                                            Utilities.ConvertToXna(end),
                                                            amount));

            Quaternion actual;

            actual = Quaternion.Slerp(start, end, amount);
            Utilities.AreEqual(expected, actual);
        }
Esempio n. 12
0
        public void RotationYawPitchRollTest()
        {
            float yaw   = Utilities.GenerateFloat();
            float pitch = Utilities.GenerateFloat();
            float roll  = Utilities.GenerateFloat();

            Quaternion expected = Utilities.ConvertFrom(Microsoft.Xna.Framework.Quaternion.CreateFromYawPitchRoll(
                                                            yaw,
                                                            pitch,
                                                            roll));

            Quaternion actual;

            actual = Quaternion.RotationYawPitchRoll(yaw, pitch, roll);
            Utilities.AreEqual(expected, actual);
        }
Esempio n. 13
0
        public void QuaternionConstructorTest2()
        {
            float[] values =
            {
                Utilities.GenerateFloat(),
                Utilities.GenerateFloat(),
                Utilities.GenerateFloat(),
                Utilities.GenerateFloat()
            };
            Quaternion target = new Quaternion(values);

            Utilities.AreEqual(values[0], target.X, 0f);
            Utilities.AreEqual(values[1], target.Y, 0f);
            Utilities.AreEqual(values[2], target.Z, 0f);
            Utilities.AreEqual(values[3], target.W, 0f);
        }
Esempio n. 14
0
        public void SlerpByRefTest()
        {
            Quaternion start         = Utilities.GenerateQuaternion();
            Quaternion startExpected = start;
            Quaternion end           = Utilities.GenerateQuaternion();
            Quaternion endExpected   = end;
            float      amount        = Utilities.GenerateFloat();
            Quaternion result;

            Quaternion resultExpected = Utilities.ConvertFrom(Microsoft.Xna.Framework.Quaternion.Slerp(
                                                                  Utilities.ConvertToXna(start),
                                                                  Utilities.ConvertToXna(end),
                                                                  amount));

            Quaternion.Slerp(ref start, ref end, amount, out result);
            Utilities.AreEqual(startExpected, start);
            Utilities.AreEqual(endExpected, end);
            Utilities.AreEqual(resultExpected, result);
        }
Esempio n. 15
0
        public void BarycentricTest()
        {
            Quaternion value1  = Utilities.GenerateQuaternion();
            Quaternion value2  = Utilities.GenerateQuaternion();
            Quaternion value3  = Utilities.GenerateQuaternion();
            float      amount1 = Utilities.GenerateFloat();
            float      amount2 = Utilities.GenerateFloat();

            Quaternion expected = Utilities.ConvertFrom(Microsoft.DirectX.Quaternion.BaryCentric(
                                                            Utilities.ConvertToMdx(value1),
                                                            Utilities.ConvertToMdx(value2),
                                                            Utilities.ConvertToMdx(value3),
                                                            amount1,
                                                            amount2));

            Quaternion actual;

            actual = Quaternion.Barycentric(value1, value2, value3, amount1, amount2);
            Utilities.AreEqual(expected, actual);
        }
Esempio n. 16
0
        public void SquadTest()
        {
            Quaternion value1 = Utilities.GenerateQuaternion();
            Quaternion value2 = Utilities.GenerateQuaternion();
            Quaternion value3 = Utilities.GenerateQuaternion();
            Quaternion value4 = Utilities.GenerateQuaternion();
            float      amount = Utilities.GenerateFloat();

            Quaternion expected = Utilities.ConvertFrom(Microsoft.DirectX.Quaternion.Squad(
                                                            Utilities.ConvertToMdx(value1),
                                                            Utilities.ConvertToMdx(value2),
                                                            Utilities.ConvertToMdx(value3),
                                                            Utilities.ConvertToMdx(value4),
                                                            amount));

            Quaternion actual;

            actual = Quaternion.Squad(value1, value2, value3, value4, amount);
            Utilities.AreEqual(expected, actual);
        }
Esempio n. 17
0
        public void GjkBatteryTest()
        {
            Gjk gjk = new Gjk();

            const int iterations = 10000;

            //Point to point test
            for (int i = 0; i < iterations; ++i)
            {
                gjk.Reset();

                Vector3 point1   = Utilities.GenerateVector3();
                Vector3 point2   = Utilities.GenerateVector3();
                float   expected = Vector3.Distance(point1, point2);

                float actual = gjk.GetMinimumDistance(v =>
                {
                    return(point1 - point2);
                });

                Utilities.AreEqual(expected, actual);
            }

            //Sphere to sphere test
            for (int i = 0; i < iterations; ++i)
            {
                gjk.Reset();

                BoundingSphere shape1   = new BoundingSphere(Utilities.GenerateVector3(), Utilities.GenerateFloat());
                BoundingSphere shape2   = new BoundingSphere(Utilities.GenerateVector3(), Utilities.GenerateFloat());
                float          expected = Collision.DistanceSphereSphere(ref shape1, ref shape2);

                if (Collision.SphereIntersectsSphere(ref shape1, ref shape2))
                {
                    i--;
                    continue;
                }

                float actual = gjk.GetMinimumDistance(v =>
                {
                    Vector3 a = shape1.SupportMapping(v);
                    Vector3 b = shape2.SupportMapping(-v);

                    return(a - b);
                });

                Utilities.AreEqual(expected, actual);
            }

            //Box to box test
            for (int i = 0; i < iterations; ++i)
            {
                gjk.Reset();

                BoundingBox shape1   = new BoundingBox(Utilities.GenerateVector3(), Utilities.GenerateVector3());
                BoundingBox shape2   = new BoundingBox(Utilities.GenerateVector3(), Utilities.GenerateVector3());
                float       expected = Collision.DistanceBoxBox(ref shape1, ref shape2);

                if (Collision.BoxIntersectsBox(ref shape1, ref shape2))
                {
                    i--;
                    continue;
                }

                float actual = gjk.GetMinimumDistance(v =>
                {
                    Vector3 a = shape1.SupportMapping(v);
                    Vector3 b = shape2.SupportMapping(-v);

                    return(a - b);
                });

                Utilities.AreEqual(expected, actual);
            }
        }