Ejemplo n.º 1
0
        public static void mp_grid_set_instance(GameObject go, bool empty = false)
        {
            // rasterize entire shit based on bounding box
            if (Math.Abs(go.ImageAngle) < .5f)
            {
                Microsoft.Xna.Framework.Rectangle r = go.CollisionContainer;
                int relativeX = (int)go.X - pathfindingGrid.X;
                int relativeY = (int)go.Y - pathfindingGrid.Y;

                mp_grid_set_rectangle(relativeX / pathfindingGrid.CellSizeX, relativeY / pathfindingGrid.CellSizeY, (int)ceil(r.Width / (float)pathfindingGrid.CellSizeX), (int)ceil(r.Height / (float)pathfindingGrid.CellSizeY), empty);
            }
            else
            {
                RotatedRectangle rr = go.rr;
                Vector2          p  = new Vector2();

                for (int i = 0; i < pathfindingGrid.CellsY; i++)
                {
                    for (int j = 0; j < pathfindingGrid.CellsX; j++)
                    {
                        p.X = j * pathfindingGrid.CellSizeX + pathfindingGrid.CellSizeX / 2;
                        p.Y = i * pathfindingGrid.CellSizeY + pathfindingGrid.CellSizeX / 2;

                        if (rr.Contains(p))
                        {
                            mp_grid_set_cell(j, i);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static Vector2?line_in_rectangle_rotated_any(Vector2 p1, Vector2 p2, RotatedRectangle r)
        {
            if (r != null)
            {
                Vector2?temp = Vector2.One;

                temp = line_in_line(p1, p2, r.Point1, r.Point2);
                if (temp.HasValue)
                {
                    return(temp);
                }

                temp = line_in_line(p1, p2, r.Point2, r.Point3);
                if (temp.HasValue)
                {
                    return(temp);
                }

                temp = line_in_line(p1, p2, r.Point3, r.Point4);
                if (temp.HasValue)
                {
                    return(temp);
                }

                temp = line_in_line(p1, p2, r.Point4, r.Point1);
                if (temp.HasValue)
                {
                    return(temp);
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        public static bool point_in_rectangle_rotated(Point2 point, RectangleF rectangle, double angle, Vector2 origin)
        {
            RotatedRectangle rr = rectangle_rotate(rectangle, origin, angle);

            //currentObject.rr = rr;
            return(rr.Contains(point));
        }
Ejemplo n.º 4
0
        public static Vector2?line_in_rectangle_rotated_furthest(Vector2 p1, Vector2 p2, RotatedRectangle r)
        {
            if (r != null)
            {
                Vector2?temp    = Vector2.One;
                Vector2?lastScs = null;

                temp = line_in_line(p1, p2, r.Point1, r.Point2);
                if (temp.HasValue)
                {
                    lastScs = temp;
                }

                temp = line_in_line(p1, p2, r.Point2, r.Point3);
                if (temp.HasValue)
                {
                    if (lastScs == null)
                    {
                        lastScs = temp;
                    }
                    else
                    {
                        double k = point_distance(p1, temp.Value);

                        if (k > point_distance(p1, lastScs.Value))
                        {
                            lastScs = temp;
                        }
                    }
                }

                temp = line_in_line(p1, p2, r.Point3, r.Point4);
                if (temp.HasValue)
                {
                    if (lastScs == null)
                    {
                        lastScs = temp;
                    }
                    else
                    {
                        double k = point_distance(p1, temp.Value);

                        if (k > point_distance(p1, lastScs.Value))
                        {
                            lastScs = temp;
                        }
                    }
                }

                temp = line_in_line(p1, p2, r.Point4, r.Point1);
                if (temp.HasValue)
                {
                    if (lastScs == null)
                    {
                        lastScs = temp;
                    }
                    else
                    {
                        double k = point_distance(p1, temp.Value);

                        if (k > point_distance(p1, lastScs.Value))
                        {
                            lastScs = temp;
                        }
                    }
                }

                return(lastScs);
            }

            return(null);
        }
Ejemplo n.º 5
0
        public static List <Vector2> rectangle_in_rectangle_all(RotatedRectangle r1, RotatedRectangle r2)
        {
            List <Vector2> l    = new List <Vector2>();
            Vector2?       temp = Vector2.One;


            // side 1
            temp = line_in_line(r1.Point1, r1.Point2, r2.Point1, r2.Point2);
            if (temp.HasValue)
            {
                l.Add(temp.Value);
            }

            temp = line_in_line(r1.Point1, r1.Point2, r2.Point2, r2.Point3);
            if (temp.HasValue)
            {
                l.Add(temp.Value);
            }

            temp = line_in_line(r1.Point1, r1.Point2, r2.Point3, r2.Point4);
            if (temp.HasValue)
            {
                l.Add(temp.Value);
            }

            temp = line_in_line(r1.Point1, r1.Point2, r2.Point4, r2.Point1);
            if (temp.HasValue)
            {
                l.Add(temp.Value);
            }

            // side 2
            temp = line_in_line(r1.Point2, r1.Point3, r2.Point1, r2.Point2);
            if (temp.HasValue)
            {
                l.Add(temp.Value);
            }

            temp = line_in_line(r1.Point2, r1.Point3, r2.Point2, r2.Point3);
            if (temp.HasValue)
            {
                l.Add(temp.Value);
            }

            temp = line_in_line(r1.Point2, r1.Point3, r2.Point3, r2.Point4);
            if (temp.HasValue)
            {
                l.Add(temp.Value);
            }

            temp = line_in_line(r1.Point2, r1.Point3, r2.Point4, r2.Point1);
            if (temp.HasValue)
            {
                l.Add(temp.Value);
            }

            // side 3
            temp = line_in_line(r1.Point3, r1.Point4, r2.Point1, r2.Point2);
            if (temp.HasValue)
            {
                l.Add(temp.Value);
            }

            temp = line_in_line(r1.Point3, r1.Point4, r2.Point2, r2.Point3);
            if (temp.HasValue)
            {
                l.Add(temp.Value);
            }

            temp = line_in_line(r1.Point3, r1.Point4, r2.Point3, r2.Point4);
            if (temp.HasValue)
            {
                l.Add(temp.Value);
            }

            temp = line_in_line(r1.Point3, r1.Point4, r2.Point4, r2.Point1);
            if (temp.HasValue)
            {
                l.Add(temp.Value);
            }

            // side 4
            temp = line_in_line(r1.Point4, r1.Point1, r2.Point1, r2.Point2);
            if (temp.HasValue)
            {
                l.Add(temp.Value);
            }

            temp = line_in_line(r1.Point4, r1.Point1, r2.Point2, r2.Point3);
            if (temp.HasValue)
            {
                l.Add(temp.Value);
            }

            temp = line_in_line(r1.Point4, r1.Point1, r2.Point3, r2.Point4);
            if (temp.HasValue)
            {
                l.Add(temp.Value);
            }

            temp = line_in_line(r1.Point4, r1.Point1, r2.Point4, r2.Point1);
            if (temp.HasValue)
            {
                l.Add(temp.Value);
            }

            return(l);
        }
Ejemplo n.º 6
0
        public static List <Vector2> line_in_rectangle_rotated_all(Vector2 p1, Vector2 p2, RotatedRectangle r)
        {
            if (r != null)
            {
                List <Vector2> l    = new List <Vector2>();
                Vector2?       temp = Vector2.One;

                temp = line_in_line(p1, p2, r.Point1, r.Point2);
                if (temp.HasValue)
                {
                    l.Add(temp.Value);
                }

                temp = line_in_line(p1, p2, r.Point2, r.Point3);
                if (temp.HasValue)
                {
                    l.Add(temp.Value);
                }

                temp = line_in_line(p1, p2, r.Point3, r.Point4);
                if (temp.HasValue)
                {
                    l.Add(temp.Value);
                }

                temp = line_in_line(p1, p2, r.Point4, r.Point1);
                if (temp.HasValue)
                {
                    l.Add(temp.Value);
                }

                return(l);
            }

            return(null);
        }