Пример #1
0
        public static bool Intersects(Vector2 A1, Vector2 A2, Vector2 B1, Vector2 B2, ref IntersectionResult Result)
        {
            Vector2 B         = A2 - A1;
            Vector2 D         = B2 - B1;
            float   bDotDPerp = B.X * D.Y - B.Y * D.X;

            // if b dot d == 0, it means the lines are parallel so have infinite intersection points
            if (bDotDPerp == 0)
            {
                return(false);
            }

            Vector2 C = B1 - A1;
            float   T = (C.X * D.Y - C.Y * D.X) / bDotDPerp;

            if (T < 0 || T > 1)
            {
                return(false);
            }

            float U = (C.X * B.Y - C.Y * B.X) / bDotDPerp;

            if (U < 0 || U > 1)
            {
                return(false);
            }

            Vector2 Dir    = Vector2.Normalize(A2 - A1);
            Vector2 Normal = Vector2.Zero;
            Vector2 Ref    = Vector2.Reflect(Dir, Normal);

            Result = new IntersectionResult(Dir, A1 + T * B, Normal, Ref);
            return(true);
        }
Пример #2
0
        public static bool Intersects(Vector2 Start, Vector2 End, Rectangle Rect, out IntersectionResult Result)
        {
            IntersectionResult ResA = new IntersectionResult();
            IntersectionResult ResB = new IntersectionResult();

            ref IntersectionResult CurRes = ref ResA;
Пример #3
0
 public RaycastResult(IntersectionResult Intersection, GameUnit Unit)
 {
     this.Intersection = Intersection;
     this.Unit         = Unit;
 }