示例#1
0
        public void CubeCubeNoOverlap()
        {
            Cube cube1 = new Cube(new Float4(0), new Float4(5), Quaternion.Default);
            Cube cube2 = new Cube(new Float4(10), new Float4(5), Quaternion.Default);
            SeparatingAxisTheorem sat = new SeparatingAxisTheorem();
            var b1 = new SatBodyData();
            var b2 = new SatBodyData();

            b1.CreateFrom(cube1);
            b2.CreateFrom(cube2);
            var data = sat.Test(b1, b2);

            Assert.AreEqual(false, data.Intersecting);
        }
示例#2
0
        public void AABBAABBNoOverlap()
        {
            AABB aabb1 = new AABB(new Float4(0), new Float4(10));
            AABB aabb2 = new AABB(new Float4(10), new Float4(20));
            SeparatingAxisTheorem sat = new SeparatingAxisTheorem();
            var b1 = new SatBodyData();
            var b2 = new SatBodyData();

            b1.CreateFrom(aabb1);
            b2.CreateFrom(aabb2);
            var data = sat.Test(b1, b2);

            Assert.AreEqual(false, data.Intersecting);
        }
示例#3
0
        public void CubeCubeOverlap()
        {
            Cube aabb1 = new Cube(new Float4(0, 9, 0, 0), new Float4(5), Quaternion.Default);
            Cube aabb2 = new Cube(new Float4(0), new Float4(5), Quaternion.Default);
            SeparatingAxisTheorem sat = new SeparatingAxisTheorem();
            var b1 = new SatBodyData();
            var b2 = new SatBodyData();

            b1.CreateFrom(aabb1);
            b2.CreateFrom(aabb2);
            var data = sat.Test(b1, b2);

            Assert.AreEqual(true, data.Intersecting);
            Assert.AreEqual(1, data.Depth);
            Assert.AreEqual(new Float3(0, 1, 0), data.Normal);
        }
示例#4
0
        public void AABBAABBNegYOverlap()
        {
            AABB aabb1 = new AABB(new Float4(0, -9, 0, 0), new Float4(10, 1, 10, 10));
            AABB aabb2 = new AABB(new Float4(0), new Float4(10));
            SeparatingAxisTheorem sat = new SeparatingAxisTheorem();
            var b1 = new SatBodyData();
            var b2 = new SatBodyData();

            b1.CreateFrom(aabb1);
            b2.CreateFrom(aabb2);
            var data = sat.Test(b1, b2);

            Assert.AreEqual(true, data.Intersecting);
            Assert.AreEqual(1, data.Depth);
            Assert.AreEqual(new Float3(0, -1, 0), data.Normal);
        }
示例#5
0
        static void TestSat()
        {
            var sat = new SeparatingAxisTheorem();

            // shape1
            var shape1 = new Polygon();

            shape1.Vertices    = new Vector2[4];
            shape1.Vertices[0] = new Vector2(0.0, 0.0);
            shape1.Vertices[1] = new Vector2(10.0, 0.0);
            shape1.Vertices[2] = new Vector2(10.0, 10.0);
            shape1.Vertices[3] = new Vector2(0.0, 10.0);

            // shape2
            var shape2 = new Polygon();

            shape2.Vertices = new Vector2[4];

            // overlaps
            //shape2.Vertices[0] = new Vector2(5.0, 5.0);
            //shape2.Vertices[1] = new Vector2(20.0, 5.0);
            //shape2.Vertices[2] = new Vector2(20.0, 20.0);
            //shape2.Vertices[3] = new Vector2(5.0, 20.0);

            // do not overlaps
            //shape2.Vertices[0] = new Vector2(15.0, 5.0);
            //shape2.Vertices[1] = new Vector2(20.0, 5.0);
            //shape2.Vertices[2] = new Vector2(20.0, 20.0);
            //shape2.Vertices[3] = new Vector2(15.0, 20.0);

            // shape1 contains shape2
            shape2.Vertices[0] = new Vector2(2.0, 2.0);
            shape2.Vertices[1] = new Vector2(8.0, 2.0);
            shape2.Vertices[2] = new Vector2(8.0, 8.0);
            shape2.Vertices[3] = new Vector2(2.0, 8.0);

            // sat get axes
            //var axes1 = sat.GetAxes(shape1.Vertices);
            //var axes2 = sat.GetAxes(shape2.Vertices);
            //Console.WriteLine("axes1:");
            //foreach(var axis in axes1) Console.WriteLine(axis);
            //Console.WriteLine("axes2:");
            //foreach(var axis in axes2) Console.WriteLine(axis);

            // sat overlap
            bool overlap = sat.Overlap(shape1.Vertices, shape2.Vertices);

            Console.WriteLine("overlap: " + overlap);

            //TestSatProjectionGetOverlap();

            // sat mtv
            MinimumTranslationVector?mtv;
            bool overlapMTV = sat.MinimumTranslationVector(
                shape1.Vertices,
                shape2.Vertices,
                out mtv);

            Console.WriteLine("overlapMTV: " + overlapMTV);
            if (mtv.HasValue)
            {
                Console.WriteLine("mtv.overlap: " + mtv.Value.Overlap);
                Console.WriteLine("mtv.smallest: " + mtv.Value.Smallest);
            }

            // sat mtv with containment
            MinimumTranslationVector?mtvContainment;
            bool overlapMTVContainment = sat.MinimumTranslationVectorWithContainment(
                shape1.Vertices,
                shape2.Vertices,
                out mtvContainment);

            Console.WriteLine("overlapMTVContainment: " + overlapMTVContainment);
            if (mtv.HasValue)
            {
                Console.WriteLine("mtvContainment.overlap: " + mtvContainment.Value.Overlap);
                Console.WriteLine("mtvContainment.smallest: " + mtvContainment.Value.Smallest);
            }
        }