public void TestPointComplexCollision()
        {
            // true results
            bool[] trueResults = { false, true, true, false };
            // Points coordinates
            Vector2[] points =
            {
                new Vector2(3.07563f,  25.33322f),
                new Vector2(6.80563f,  18.67249f),
                new Vector2(13.35218f, 16.38881f),
                new Vector2(17.34862f, 12.54462f)
            };
            float[] pointTurn = { 234.12f, 12.234f, 11.11f, 66.66f, 111.111f };
            // Polygon points
            Vector2[] rect =
            {
                new Vector2(6.0f, 8.0f), new Vector2(4.0f, 12.0f)
            };
            Vector2[] polPoints =
            {
                new Vector2(8.0f,  6.0f), new Vector2(14.0f, 6.0f),
                new Vector2(14.0f, 2.0f), new Vector2(8.0f, 2.0f)
            };
            //Create Rectangle
            RectangleShape rectShape = new RectangleShape(rect[0], rect[1].X, rect[1].Y);
            //Create Polygon
            PolygonShape polShape = new PolygonShape(polPoints);

            //Create Complex obj
            IShape[]     shapes    = { rectShape, polShape };
            ComplexShape compShape = new ComplexShape(shapes);

            Collision.Transform compTranform =
                new Collision.Transform(new Vector2(5.0456f, 8.1234543f), 23.023f * Mathf.Deg2Rad);

            //Create points and check collisions
            for (var obj = 0; obj < trueResults.Length; obj++)
            {
                CollisionResult     result;
                PointShape          pointShape    = new PointShape(Vector2.Zero);
                Collision.Transform pointTranform =
                    new Collision.Transform(points[obj], pointTurn[obj] * Mathf.Deg2Rad);
                var    testResult = compShape.IntersectsWith(compTranform, pointShape, pointTranform, out result);
                string err        = String.Format("Point to Complex test({0}) failed for Point({1})", obj, points[obj]);
                Assert.That(trueResults[obj] == testResult, err);
            }
        }
        public void TestCircleComplexCollision()
        {
            // true results
            bool[] trueResults = { false, true, true, true };
            // Circles params: center coordiantes x,y ; radius, turn
            Vector2[][] circles =
            {
                new[] { new Vector2(-5.10756f, 25.02873f), new Vector2(3.234f,      34.098f) },
                new[] { new Vector2(4.14134f,  25.21903f), new Vector2(3.00123f,   324.081f) },
                new[] { new Vector2(10.11697f, 15.05666f), new Vector2(1.892340f,  7.00098f) },
                new[] { new Vector2(20.05097f, 18.25381f), new Vector2(4.1101f,   104.3398f) }
            };
            // Polygon points
            Vector2[] rect =
            {
                new Vector2(6.0f, 8.0f), new Vector2(4.0f, 12.0f)
            };
            Vector2[] polPoints =
            {
                new Vector2(8.0f,  6.0f), new Vector2(14.0f, 6.0f),
                new Vector2(14.0f, 2.0f), new Vector2(8.0f, 2.0f)
            };
            //Create Rectangle
            RectangleShape rectShape = new RectangleShape(rect[0], rect[1].X, rect[1].Y);
            //Create Polygon
            PolygonShape polShape = new PolygonShape(polPoints);

            //Create Complex obj
            IShape[]     shapes    = { rectShape, polShape };
            ComplexShape compShape = new ComplexShape(shapes);

            Collision.Transform compTranform =
                new Collision.Transform(new Vector2(5.0456f, 8.1234543f), 23.023f * Mathf.Deg2Rad);

            //Create circles and check collisions
            for (var obj = 0; obj < trueResults.Length; obj++)
            {
                CollisionResult     result;
                CircleShape         circleShape     = new CircleShape(Vector2.Zero, circles[obj][1].X);
                Collision.Transform circleTransform =
                    new Collision.Transform(circles[obj][0], circles[obj][1].Y * Mathf.Deg2Rad);
                var    testResult = compShape.IntersectsWith(compTranform, circleShape, circleTransform, out result);
                string err        = String.Format("Point to Complex test({0}) failed.", obj);
                Assert.That(trueResults[obj] == testResult, err);
            }
        }
Beispiel #3
0
        public void TestComplexComplexCollision()
        {
            // Import data
            var comp    = Complexes.Comp;
            var results = CompCompTest.CompCompResults;

            for (int obj = 0; obj < results.Length; obj++)
            {
                IShape[] firstComplex  = new IShape[comp[results[obj].FirstShape].PolPoints.Length];
                IShape[] secondComplex = new IShape[comp[results[obj].SecondShape].PolPoints.Length];

                for (int pol = 0; pol < comp[results[obj].FirstShape].PolPoints.Length; pol++)
                {
                    firstComplex[pol] = new PolygonShape(comp[results[obj].FirstShape].PolPoints[pol]);
                }

                for (int pol = 0; pol < comp[results[obj].SecondShape].PolPoints.Length; pol++)
                {
                    secondComplex[pol] = new PolygonShape(comp[results[obj].SecondShape].PolPoints[pol]);
                }
                // Create complex objects
                ComplexShape firstComp  = new ComplexShape(firstComplex);
                ComplexShape secondComp = new ComplexShape(secondComplex);
                // Transform complex objects
                Collision.Transform firstCompTranform =
                    new Collision.Transform(comp[results[obj].FirstShape].Trans,
                                            comp[results[obj].FirstShape].Rotate);
                Collision.Transform secondCompTranform =
                    new Collision.Transform(comp[results[obj].SecondShape].Trans,
                                            comp[results[obj].SecondShape].Rotate);


                CollisionResult result;
                var             testResult = firstComp.IntersectsWith(firstCompTranform, secondComp, secondCompTranform,
                                                                      out result);
                string err = String.Format(
                    "Complex to Compex test({0}) failed; Complex({1}), Complex({2}) {3} {4}",
                    obj, results[obj].FirstShape, results[obj].SecondShape, comp[results[obj].FirstShape].Trans,
                    comp[results[obj].SecondShape].Rotate);

                Assert.That(results[obj].Result == testResult, err);
            }
        }
Beispiel #4
0
        public void TestComplexRectangleCollision()
        {
            // Import data
            var comp    = Complexes.Comp;
            var rect    = Rects.Rect;
            var results = CompRectTest.CompRectResults;

            for (int obj = 0; obj < results.Length; obj++)
            {
                IShape[] polygons = new IShape[comp[results[obj].FirstShape].PolPoints.Length];
                for (int pol = 0; pol < comp[results[obj].FirstShape].PolPoints.Length; pol++)
                {
                    polygons[pol] = new PolygonShape(comp[results[obj].FirstShape].PolPoints[pol]);
                }

                // Create complex objects
                ComplexShape compShape = new ComplexShape(polygons);
                // Transform complex objects
                Collision.Transform firstCompTranform =
                    new Collision.Transform(comp[results[obj].FirstShape].Trans,
                                            comp[results[obj].FirstShape].Rotate);

                // Create Rectangle object
                RectangleShape rectShape =
                    new RectangleShape(rect[results[obj].SecondShape].Center, rect[results[obj].SecondShape].Width,
                                       rect[results[obj].SecondShape].Height);
                // Transform Rectangle object
                Collision.Transform rectTransform =
                    new Collision.Transform(rect[results[obj].SecondShape].Trans,
                                            rect[results[obj].SecondShape].Rotate);


                CollisionResult result;
                var             testResult = compShape.IntersectsWith(firstCompTranform, rectShape, rectTransform,
                                                                      out result);
                string err = String.Format("Complex to Rectangle test({0}) failed; Complex({1}), Rectangle({2})",
                                           obj, results[obj].FirstShape, results[obj].SecondShape);
                Assert.That(results[obj].Result == testResult, err);
            }
        }
Beispiel #5
0
        public void TestComplexPolygonCollision()
        {
            // Import data
            var comp    = Complexes.Comp;
            var poly    = Polygons.Poly;
            var results = CompPolyTest.CompPolyResults;

            for (int obj = 0; obj < results.Length; obj++)
            {
                IShape[] polygons = new IShape[comp[results[obj].FirstShape].PolPoints.Length];

                for (int pol = 0; pol < comp[results[obj].FirstShape].PolPoints.Length; pol++)
                {
                    polygons[pol] = new PolygonShape(comp[results[obj].FirstShape].PolPoints[pol]);
                }

                // Create complex objects
                ComplexShape compShape = new ComplexShape(polygons);
                // Transform complex objects
                Collision.Transform firstCompTranform =
                    new Collision.Transform(comp[results[obj].FirstShape].Trans,
                                            comp[results[obj].FirstShape].Rotate);

                // Create polygon objects
                PolygonShape polShape = new PolygonShape(poly[results[obj].SecondShape].Points);
                // Transform polygon object
                Collision.Transform polTransform =
                    new Collision.Transform(poly[results[obj].SecondShape].Trans,
                                            poly[results[obj].SecondShape].Rotate);


                CollisionResult result;
                var             testResult = compShape.IntersectsWith(firstCompTranform, polShape, polTransform,
                                                                      out result);
                string err = String.Format("Complex to Polygon test({0}) failed; Complex({1}), Polygon({2})",
                                           obj, results[obj].FirstShape, results[obj].SecondShape);
                Assert.That(results[obj].Result == testResult, err);
            }
        }
Beispiel #6
0
        public void TestComplexCircleCollision()
        {
            // Import data
            var comp    = Complexes.Comp;
            var circle  = Circles.Circle;
            var results = CompCircleTest.CompCircleResults;

            for (int obj = 0; obj < results.Length; obj++)
            {
                IShape[] polygons = new IShape[comp[results[obj].FirstShape].PolPoints.Length];

                for (int pol = 0; pol < comp[results[obj].FirstShape].PolPoints.Length; pol++)
                {
                    polygons[pol] = new PolygonShape(comp[results[obj].FirstShape].PolPoints[pol]);
                }

                // Create complex objects
                ComplexShape compShape = new ComplexShape(polygons);
                // Transform complex objects
                Collision.Transform firstCompTranform =
                    new Collision.Transform(comp[results[obj].FirstShape].Trans,
                                            comp[results[obj].FirstShape].Rotate);
                // Create Circle object
                CircleShape circleShape = new CircleShape(circle[results[obj].SecondShape].Center,
                                                          circle[results[obj].SecondShape].Radius);
                // Transform Circle objext
                Collision.Transform circleShapeTransform =
                    new Collision.Transform(circle[results[obj].SecondShape].Trans,
                                            circle[results[obj].SecondShape].Rotate);

                CollisionResult result;
                var             testResult = compShape.IntersectsWith(firstCompTranform, circleShape, circleShapeTransform,
                                                                      out result);
                string err = String.Format("Complex to Circle test({0}) failed; Complex({1}), Circle({2}), res:{3}",
                                           obj, results[obj].FirstShape, results[obj].SecondShape, result);
                Assert.That(results[obj].Result == testResult, err);
            }
        }
        public void TestComplexComplexCollision()
        {
            // Polygon points
            Vector2[] rect =
            {
                new Vector2(6.0f, 8.0f), new Vector2(4.0f, 12.0f)
            };
            Vector2[] polPoints =
            {
                new Vector2(8.0f,  6.0f), new Vector2(14.0f, 6.0f),
                new Vector2(14.0f, 2.0f), new Vector2(8.0f, 2.0f)
            };
            //Create Rectangles
            RectangleShape firstRectShape  = new RectangleShape(rect[0], rect[1].X, rect[1].Y);
            RectangleShape secondRectShape = new RectangleShape(rect[0], rect[1].X, rect[1].Y);
            //Create Polygons
            PolygonShape firstPolShape  = new PolygonShape(polPoints);
            PolygonShape secondPolShape = new PolygonShape(polPoints);

            //Create Complex obj
            IShape[]     firstComplex    = { firstRectShape, firstPolShape };
            IShape[]     secondComplex   = { secondRectShape, secondPolShape };
            ComplexShape firstCompShape  = new ComplexShape(firstComplex);
            ComplexShape secondCompShape = new ComplexShape(secondComplex);

            Collision.Transform firstCompTranform =
                new Collision.Transform(new Vector2(5.0456f, 8.1234543f), 23.023f * Mathf.Deg2Rad);
            Collision.Transform secondCompTranform =
                new Collision.Transform(new Vector2(5.0456f, 8.1234543f), 66.6666f * Mathf.Deg2Rad);

            CollisionResult result;
            var             testResult = firstCompShape.IntersectsWith(firstCompTranform, secondCompShape, secondCompTranform,
                                                                       out result);
            string err = "Complex to Complex test failed.";

            Assert.That(testResult, err);
        }
Beispiel #8
0
        public void MyTest()
        {
            // first shape Polygons points
            Vector2 trans1 = new Vector2(4700f, 2307f);
            float   turn1  = 0.672428f;

            Vector2[] fp1 =
            {
                new Vector2(350.5f, -115f), new Vector2(226.5f,  -120f), new Vector2(125.5f,  -119f),
                new Vector2(-73.5f, -102f), new Vector2(-353.5f,  -18f), new Vector2(-259.5f,  121f),
                new Vector2(277.5f,   73f), new Vector2(351.5f, 6f)
            };

            Vector2[] fp2 =
            {
                new Vector2(346.5f, 54f), new Vector2(351.5f, 6f), new Vector2(277.5f, 73f)
            };

            Vector2[] fp3 =
            {
                new Vector2(-328.5f, 114f), new Vector2(-259.5f, 121f), new Vector2(-353.5f, -18f)
            };

            Vector2[] fp4 =
            {
                new Vector2(-353.5f, -44f), new Vector2(-353.5f, -18f), new Vector2(-73.5f, -102f),
                new Vector2(-225.5f, -76f)
            };

            // second shape Polygons points
            Vector2 trans2 = new Vector2(3604f, 1915f);
            float   turn2  = 3.365334f;

            Vector2[] sp1 =
            {
                new Vector2(921f,  37f), new Vector2(878f,      -125f), new Vector2(771f, -126f),
                new Vector2(33f,  -56f), new Vector2(-526f,      101f), new Vector2(51f,   127f),
                new Vector2(510f, 101f), new Vector2(748.6665f, 69.6665f)
            };

            Vector2[] sp2 =
            {
                new Vector2(-920f,  40f), new Vector2(-746f, 73.6665f), new Vector2(-526f, 101f),
                new Vector2(33f,   -56f), new Vector2(-826f,    -127f), new Vector2(-900f, -79f)
            };

            Vector2[] sp3 =
            {
                new Vector2(304.6665f, 119f), new Vector2(510f, 101f), new Vector2(51f, 127f)
            };

            Vector2[] sp4 =
            {
                new Vector2(-526f, 101f), new Vector2(-289f, 119f), new Vector2(51f, 127f)
            };


            //Create first polygons
            PolygonShape fpol1 = new PolygonShape(fp1);
            PolygonShape fpol2 = new PolygonShape(fp2);
            PolygonShape fpol3 = new PolygonShape(fp3);
            PolygonShape fpol4 = new PolygonShape(fp4);

            //Create second polygons
            PolygonShape spol1 = new PolygonShape(sp1);
            PolygonShape spol2 = new PolygonShape(sp2);
            PolygonShape spol3 = new PolygonShape(sp3);
            PolygonShape spol4 = new PolygonShape(sp4);


            // Create complex arrays
            IShape[] firstComplex = { fpol1, fpol2, fpol3, fpol4 };
//            IShape[] secondComplex = {spol1, spol2, spol3, spol4};
            IShape[]     secondComplex  = { spol1, spol2 };
            ComplexShape firstCompShape = new ComplexShape(firstComplex);

            Collision.Transform firstCompTranform = new Collision.Transform(trans1, turn1);

            ComplexShape secondCompShape = new ComplexShape(secondComplex);

            Collision.Transform secondCompTranform = new Collision.Transform(trans2, turn2);

            // Circles
            Vector2[] circles =
            {
                new Vector2(4200f, 1880f), new Vector2(4260f, 1910f), new Vector2(4310f, 1930f),
                new Vector2(4370f, 1960f), new Vector2(4430f, 1990f), new Vector2(4500f, 2010f),
                new Vector2(4550f, 2040f), new Vector2(4610f, 2060f), new Vector2(4660f, 2090f),
                new Vector2(4710f, 2050f), new Vector2(4650f, 2020f), new Vector2(4600f, 1980f),
                new Vector2(4540f, 1960f), new Vector2(4460f, 1940f), new Vector2(4400f, 1910f),
                new Vector2(4350f, 1880f), new Vector2(4290f, 1870f), new Vector2(4240f, 1830f),
                new Vector2(4160f, 1970f), new Vector2(4220f, 1990f), new Vector2(4280f, 2010f),
                new Vector2(4330f, 2030f), new Vector2(4390f, 2050f), new Vector2(4450f, 2080f),
                new Vector2(4470f, 2120f), new Vector2(4520f, 2130f), new Vector2(4530f, 2110f),
                new Vector2(4400f, 2180f), new Vector2(4480f, 2080f), new Vector2(4520f, 2090f),
                new Vector2(4210f, 1710f), new Vector2(4310f, 1770f), new Vector2(4410f, 1820f),
                new Vector2(4510f, 1860f), new Vector2(4600f, 1900f), new Vector2(4660f, 1920f),
                new Vector2(4750f, 1960f), new Vector2(4830f, 2000f), new Vector2(4290f, 1640f),
                new Vector2(4400f, 1700f), new Vector2(4490f, 1750f), new Vector2(4600f, 1790f),
                new Vector2(4680f, 1840f), new Vector2(4810f, 1890f), new Vector2(4900f, 1950f)
            };


            CollisionResult result;
            var             testResult = firstCompShape.IntersectsWith(firstCompTranform, secondCompShape, secondCompTranform,
                                                                       out result);

//            Console.WriteLine("Test is: {0}", testResult);
            Assert.That(testResult, "Complex to Complex test failed.(Block_8 + block_3)");

            //Circles to Complexes tests
            var results = MyCompCirce.MyCompCirceResults;
            //Radius for circles
            float radius = 50.0f;


            for (int obj = 0; obj < results.Length; obj++)
            {
                CircleShape         circleShape    = new CircleShape(Vector2.Zero, radius);
                Collision.Transform circleTranform = new Collision.Transform(circles[obj], 0);
                //First complex text
                var firstResult = firstCompShape.IntersectsWith(firstCompTranform, circleShape, circleTranform,
                                                                out result);
                Assert.That(results[obj].FirstResult == firstResult, "Circle: {0} to Complex: 0 test failed.",
                            obj);
                //second complex text
                var secondResult = secondCompShape.IntersectsWith(secondCompTranform, circleShape, circleTranform,
                                                                  out result);
                Assert.That(results[obj].SecondResult == secondResult, "Circle: {0} to Complex: 1 test failed.",
                            obj);
            }
        }