//edited public static bool LineIntersectLinearSpellEx(this Spell spell, Vector2 a, Vector2 b, out Vector2 intersection) { var myBoundingRadius = ObjectManager.Player.BoundingRadius; var spellDir = spell.direction; var pSpellDir = spell.direction.LSPerpendicular(); var spellRadius = spell.radius; var spellPos = spell.currentSpellPosition - spellDir * myBoundingRadius; //leave some space at back of spell var endPos = spell.GetSpellEndPosition() + spellDir * myBoundingRadius; //leave some space at the front of spell var startRightPos = spellPos + pSpellDir * (spellRadius + myBoundingRadius); var startLeftPos = spellPos - pSpellDir * (spellRadius + myBoundingRadius); var endRightPos = endPos + pSpellDir * (spellRadius + myBoundingRadius); var endLeftPos = endPos - pSpellDir * (spellRadius + myBoundingRadius); List<Geometry.IntersectionResult> intersects = new List<Geometry.IntersectionResult>(); Vector2 heroPos = ObjectManager.Player.ServerPosition.LSTo2D(); intersects.Add(a.LSIntersection(b, startRightPos, startLeftPos)); intersects.Add(a.LSIntersection(b, endRightPos, endLeftPos)); intersects.Add(a.LSIntersection(b, startRightPos, endRightPos)); intersects.Add(a.LSIntersection(b, startLeftPos, endLeftPos)); var sortedIntersects = intersects.Where(i => i.Intersects).OrderBy(i => i.Point.LSDistance(heroPos)); //Get first intersection if (sortedIntersects.Count() > 0) { intersection = sortedIntersects.First().Point; return true; } intersection = Vector2.Zero; return false; }
public static bool CheckLineIntersection(Vector2 a, Vector2 b, Vector2 c, Vector2 d) { return a.LSIntersection(b, c, d).Intersects; }