Пример #1
0
 public RainDrop(Vector2 velocity, Vector2 position)
 {
     _velocity    = velocity;
     _position    = position;
     _oldPosition = _position;
     _track       = new LineObject(Game1.mapLive, new LineSegmentF(_oldPosition, _position));
 }
Пример #2
0
        public static Vector2Object NearestFromRectangles <T>(Vector2 origin, LineObject ray, List <T> recs)
        {
            List <Vector2Object> candidates = new List <Vector2Object>();

            if (typeof(T) == typeof(Inpc))
            {
                foreach (Inpc rec in recs)
                {
                    if (rec.Friendly == false)
                    {
                        List <Vector2Object> vectors = LineIntersectionRectangle(rec, ray);

                        foreach (Vector2Object vec in vectors)
                        {
                            candidates.Add(new Vector2Object(rec, vec.Vector2));
                        }
                    }
                }
            }

            if (typeof(T) == typeof(IRectanglePhysics))
            {
                foreach (IRectanglePhysics rec in recs)
                {
                    List <Vector2Object> vectors = LineIntersectionRectangle(rec, ray);

                    foreach (Vector2Object vec in vectors)
                    {
                        candidates.Add(new Vector2Object(rec, vec.Vector2));
                    }
                }
            }

            return(NearestVector(origin, candidates));
        }
Пример #3
0
        public static List <Vector2Object> LineIntersectionRectangle(RectangleF rec, LineObject line)
        {
            List <Vector2Object> vectors = new List <Vector2Object>();

            Vector2 intersetionLeft;

            if (LinesIntersection(line.Line, new LineSegmentF(rec.CornerLeftTop, rec.CornerLeftBottom), out intersetionLeft))
            {
                vectors.Add(new Vector2Object(line.Object, intersetionLeft));
            }

            Vector2 intersetionRight;

            if (LinesIntersection(line.Line, new LineSegmentF(rec.CornerRightTop, rec.CornerRightBottom), out intersetionRight))
            {
                vectors.Add(new Vector2Object(line.Object, intersetionRight));
            }

            Vector2 intersetionTop;

            if (LinesIntersection(line.Line, new LineSegmentF(rec.CornerLeftTop, rec.CornerRightTop), out intersetionTop))
            {
                vectors.Add(new Vector2Object(line.Object, intersetionTop));
            }

            Vector2 intersetionBottom;

            if (LinesIntersection(line.Line, new LineSegmentF(rec.CornerRightBottom, rec.CornerLeftBottom), out intersetionBottom))
            {
                vectors.Add(new Vector2Object(line.Object, intersetionBottom));
            }

            return(vectors);
        }
Пример #4
0
        public static List <Vector2Object> LineIntersectionRectangle <T>(T rec, LineObject line)
        {
            List <Vector2Object> vectors = new List <Vector2Object>();

            if (rec is Inpc)
            {
                Vector2 intersetionLeft;
                if (LinesIntersection(line.Line, new LineSegmentF((rec as Inpc).Boundary.CornerLeftTop, (rec as Inpc).Boundary.CornerLeftBottom), out intersetionLeft))
                {
                    vectors.Add(new Vector2Object(line.Object, intersetionLeft));
                }

                Vector2 intersetionRight;
                if (LinesIntersection(line.Line, new LineSegmentF((rec as Inpc).Boundary.CornerRightTop, (rec as Inpc).Boundary.CornerRightBottom), out intersetionRight))
                {
                    vectors.Add(new Vector2Object(line.Object, intersetionRight));
                }

                Vector2 intersetionTop;
                if (LinesIntersection(line.Line, new LineSegmentF((rec as Inpc).Boundary.CornerLeftTop, (rec as Inpc).Boundary.CornerRightTop), out intersetionTop))
                {
                    vectors.Add(new Vector2Object(line.Object, intersetionTop));
                }

                Vector2 intersetionBottom;
                if (LinesIntersection(line.Line, new LineSegmentF((rec as Inpc).Boundary.CornerRightBottom, (rec as Inpc).Boundary.CornerLeftBottom), out intersetionBottom))
                {
                    vectors.Add(new Vector2Object(line.Object, intersetionBottom));
                }
            }

            if (rec is IRectanglePhysics)
            {
                Vector2 intersetionLeft;
                if (LinesIntersection(line.Line, new LineSegmentF((rec as IRectanglePhysics).Boundary.CornerLeftTop, (rec as IRectanglePhysics).Boundary.CornerLeftBottom), out intersetionLeft))
                {
                    vectors.Add(new Vector2Object(line.Object, intersetionLeft));
                }

                Vector2 intersetionRight;
                if (LinesIntersection(line.Line, new LineSegmentF((rec as IRectanglePhysics).Boundary.CornerRightTop, (rec as IRectanglePhysics).Boundary.CornerRightBottom), out intersetionRight))
                {
                    vectors.Add(new Vector2Object(line.Object, intersetionRight));
                }

                Vector2 intersetionTop;
                if (LinesIntersection(line.Line, new LineSegmentF((rec as IRectanglePhysics).Boundary.CornerLeftTop, (rec as IRectanglePhysics).Boundary.CornerRightTop), out intersetionTop))
                {
                    vectors.Add(new Vector2Object(line.Object, intersetionTop));
                }

                Vector2 intersetionBottom;
                if (LinesIntersection(line.Line, new LineSegmentF((rec as IRectanglePhysics).Boundary.CornerRightBottom, (rec as IRectanglePhysics).Boundary.CornerLeftBottom), out intersetionBottom))
                {
                    vectors.Add(new Vector2Object(line.Object, intersetionBottom));
                }
            }

            return(vectors);
        }
Пример #5
0
        public static List <Vector2Object> LineVsMap(MapTreeHolder map, LineObject segment)
        {
            List <Vector2Object> temp = new List <Vector2Object>();

            temp.AddRange(linevsRecs(LineBoundaryVsMap(map, segment), segment));

            return(temp);
        }
Пример #6
0
 public ProjectileBase(Vector2 velocity, Vector2 position, object from, short damage)
 {
     _wet         = false;
     _position    = position;
     _oldPosition = position;
     _track       = new LineObject(from, new LineSegmentF(_position, _position));
     _velocity    = velocity;
     _from        = from;
     _damage      = damage;
 }
Пример #7
0
        public static List <Vector2Object> linevsRecs(List <RectangleF> rectangles, LineObject segment)
        {
            List <Vector2Object> Points = new List <Vector2Object>();

            foreach (RectangleF rec in rectangles)
            {
                if (LineIntersectionRectangle(rec, segment).Count > 0)
                {
                    Points.AddRange(LineIntersectionRectangle(rec, segment));
                }
            }

            return(Points);
        }
Пример #8
0
        public static Vector2Object IntersectionLineWithOthers(LineObject L, List <LineSegmentF> segments, object target)
        {
            List <Vector2Object> intersections = new List <Vector2Object>();
            Vector2 intersection = new Vector2();

            foreach (LineSegmentF line in segments)
            {
                if (LinesIntersection(L.Line, line, out intersection) == true)
                {
                    intersections.Add(new Vector2Object(target, intersection));
                }
            }

            return(NearestVector(L.Line.Start, intersections));
        }
Пример #9
0
        //Test
        public static List <Vector2Object> LineVsMapRecReturn(MapTreeHolder map, LineObject segment)
        {
            List <Vector2Object> vectors = new List <Vector2Object>();

            for (int Y = (int)(Math.Max(0, (segment.Line.LineBoundingBox().Position.Y / 1024f) - 1)); Y < (int)Math.Ceiling(Math.Min((segment.Line.LineBoundingBox().CornerRightTop.Y / 1024f) + 1, map.Trees.GetLength(1))); Y++)
            {
                for (int X = (int)(Math.Max(0, (segment.Line.LineBoundingBox().Position.X / 1024f) - 1)); X < (int)Math.Ceiling(Math.Min((segment.Line.LineBoundingBox().CornerRightTop.X / 1024f) + 1, map.Trees.GetLength(0))); X++)
                {
                    if (LineIntersectionRectangle(map.Trees[X, Y].Boundary, segment).Count > 0 || RectangleVsVector2(map.Trees[X, Y].Boundary, segment.Line.End))
                    {
                        vectors.AddRange(map.Trees[X, Y].FindIntersectLine(segment.Line));
                    }
                }
            }

            return(vectors);
        }
Пример #10
0
        public static List <RectangleF> LineBoundaryVsMap(MapTreeHolder map, LineObject segment)
        {
            List <RectangleF> rectangles = new List <RectangleF>();

            for (int Y = (int)(Math.Max(0, (segment.Line.LineBoundingBox().Position.Y / 1024f) - 1)); Y < (int)Math.Ceiling(Math.Min((segment.Line.LineBoundingBox().CornerRightTop.Y / 1024f) + 1, map.Trees.GetLength(1))); Y++)
            {
                for (int X = (int)(Math.Max(0, (segment.Line.LineBoundingBox().Position.X / 1024f) - 1)); X < (int)Math.Ceiling(Math.Min((segment.Line.LineBoundingBox().CornerRightTop.X / 1024f) + 1, map.Trees.GetLength(0))); X++)
                {
                    if (RectangleFVsRectangleF(map.Trees[X, Y].Boundary, segment.Line.LineBoundingBox()) == true)
                    {
                        rectangles.AddRange(map.Trees[X, Y].FindIntersectRec(segment.Line.LineBoundingBox()));
                    }
                }
            }

            return(rectangles);
        }