Пример #1
0
        // Calculate the projection of a polygon on an axis and returns it as a [min, max] interval
        private static void projectPolygon(Vector2 axis, Polygon polygon, ref float min, ref float max)
        {
            // To project a point on an axis use the dot product
            float d = Vector2.Dot(axis, polygon.getPoints()[0]);

            min = d;
            max = d;

            for (int i = 0; i < polygon.getPoints().Count; i++)
            {
                d = Vector2.Dot(polygon.getPoints()[i], axis);

                if (d < min)
                {
                    min = d;
                }
                else
                {
                    if (d > max)
                    {
                        max = d;
                    }
                }
            }
        }
Пример #2
0
        public List <Polygon> loadPolygons(TextureItem item, string property)
        {
            List <Polygon> polygons       = new List <Polygon>();
            int            numberToLoad   = 1;
            int            numberOfLoaded = 0;
            bool           loadNext       = true;

            while (loadNext)
            {
                string tempProperty = property + numberToLoad.ToString();

                if (item.CustomProperties.ContainsKey(tempProperty))
                {
                    //Console.WriteLine(tempProperty);
                    if (item.CustomProperties[tempProperty].type == typeof(Item))
                    {
                        Console.WriteLine(tempProperty + " Loaded");
                        PathItem pathItem = (PathItem)item.CustomProperties[tempProperty].value;
                        if (pathItem != null)
                        {
                            List <Vector2> liste   = new List <Vector2>(pathItem.WorldPoints);
                            Polygon        polygon = new Polygon();

                            foreach (Vector2 point in liste)
                            {
                                polygon.getPoints().Add(point);
                            }
                            polygon.buildEdges();
                            polygons.Add(polygon);
                            numberToLoad++;
                            numberOfLoaded++;
                        }
                        else
                        {
                            loadNext = false;
                        }
                    }
                }
                else
                {
                    loadNext = false;
                }
            }

            if (numberOfLoaded == 0)
            {
                polygons = null;
                //Console.WriteLine("Did not load Polygons");
            }
            return(polygons);
        }
Пример #3
0
        public List<Polygon> loadPolygons(TextureItem item, string property)
        {
            List<Polygon> polygons = new List<Polygon>();
            int numberToLoad = 1;
            int numberOfLoaded = 0;
            bool loadNext = true;

            while (loadNext)
            {
                string tempProperty = property + numberToLoad.ToString();

                if (item.CustomProperties.ContainsKey(tempProperty))
                {
                    //Console.WriteLine(tempProperty);
                    if (item.CustomProperties[tempProperty].type == typeof(Item))
                    {
                        Console.WriteLine(tempProperty + " Loaded");
                        PathItem pathItem = (PathItem)item.CustomProperties[tempProperty].value;
                        if (pathItem != null)
                        {
                            List<Vector2> liste = new List<Vector2>(pathItem.WorldPoints);
                            Polygon polygon = new Polygon();

                            foreach (Vector2 point in liste)
                            {
                                polygon.getPoints().Add(point);
                            }
                            polygon.buildEdges();
                            polygons.Add(polygon);
                            numberToLoad++;
                            numberOfLoaded++;
                        }
                        else
                        {
                            loadNext = false;
                        }
                    }
                }
                else
                {
                    loadNext = false;
                }
            }

            if (numberOfLoaded == 0)
            {
                polygons = null;
                //Console.WriteLine("Did not load Polygons");
            }
            return polygons;
        }