public LineCollider(Object owner) : base(owner, CollisionMethods.ColliderType.Line) { m_line = new LineSegment(Vector2.Zero, Vector2.Zero); }
public bool IntersectsLines(LineSegment ls1, LineSegment ls2) { Vector2 A = ls1.A_Global, B = ls1.B_Global, C = ls2.A_Global, D = ls2.B_Global; return IntersectsLines(A, B, C, D); }
public bool LineAABB(Collider line, Collider aabb) { LineSegment ls = ((LineCollider)line).Line; LineSegment ls2 = new LineSegment(Vector2.Zero, Vector2.Zero); Rectangle r = ((AABBCollider)aabb).Bounds; if (r.Contains(new Point((int)ls.A_Global.X, (int)ls.A_Global.Y)) || r.Contains(new Point((int)ls.B_Global.X, (int)ls.B_Global.Y)) || m_helper.IntersectsLines(ls.A_Global, ls.B_Global, new Vector2(r.Left, r.Top), new Vector2(r.Right, r.Top)) || m_helper.IntersectsLines(ls.A_Global, ls.B_Global, new Vector2(r.Right, r.Top), new Vector2(r.Right, r.Bottom)) || m_helper.IntersectsLines(ls.A_Global, ls.B_Global, new Vector2(r.Right, r.Bottom), new Vector2(r.Left, r.Bottom)) || m_helper.IntersectsLines(ls.A_Global, ls.B_Global, new Vector2(r.Left, r.Bottom), new Vector2(r.Left, r.Top))) return true; return false; }
public bool Contains(Circle container, LineSegment contained) { return Contains(container, contained.A_Global) && Contains(container, contained.B_Global); }
public bool IntersectsCircleLine(Circle circle, LineSegment segment) { return IntersectsCircleLine(circle.Transform.PositionGlobal, circle.Radius, segment.A_Global, segment.B_Global); }
public bool GetIntersection(Rectangle rectangle, LineSegment segment, out Vector2 intersection) { bool isIntersecting = false; Vector2 topLeft = new Vector2(rectangle.X, rectangle.Y); Vector2 topRight = new Vector2(rectangle.X + rectangle.Width, rectangle.Y); Vector2 bottomRight = new Vector2(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height); Vector2 bottomLeft = new Vector2(rectangle.X, rectangle.Y + rectangle.Height); intersection = Vector2.Zero; Vector2 newIntersection; //if (GetIntersection(new LineSegment(topRight, bottomRight), segment, out intersection) // || GetIntersection(new LineSegment(topRight, bottomRight), segment, out intersection) // || GetIntersection(new LineSegment(bottomRight, bottomLeft), segment, out intersection) // || GetIntersection(new LineSegment(topLeft, topRight), segment, out intersection)) // return true; isIntersecting = GetIntersection(new LineSegment(topLeft, topRight), segment, out intersection); if (GetIntersection(new LineSegment(topRight, bottomRight), segment, out newIntersection)) { if (!isIntersecting) intersection = newIntersection; else intersection = (intersection + newIntersection) * 0.5f; isIntersecting = true; } if (GetIntersection(new LineSegment(bottomRight, bottomLeft), segment, out newIntersection)) { if (!isIntersecting) intersection = newIntersection; else intersection = (intersection + newIntersection) * 0.5f; isIntersecting = true; } if (isIntersecting = GetIntersection(new LineSegment(bottomLeft, topLeft), segment, out newIntersection)) { if (!isIntersecting) intersection = newIntersection; else intersection = (intersection + newIntersection) * 0.5f; isIntersecting = true; } return isIntersecting; }
public Vector2 GetProjectionPoint(LineSegment screen, Vector2 projector) { return GetProjectionPoint(screen.A_Global, screen.B_Global, projector); }
public bool IsParallel(LineSegment L2) { return (IsVertical && L2.IsVertical) || Gradient == L2.Gradient; }
public bool GetIntersection(LineSegment segmentA, LineSegment segmentB, out Vector2 intersection) { intersection = Vector2.Zero; Vector2 A = segmentA.A_Global; Vector2 C = segmentB.A_Global; Vector2 I = segmentA.Difference; Vector2 J = segmentB.Difference; float m = -(-I.X * A.Y + I.X * C.Y + I.Y * A.X - I.Y * C.X) / (I.X * J.Y - I.Y * J.X); float k = -(A.X * J.Y - C.X * J.Y - J.X * A.Y + J.X * C.Y) / (I.X * J.Y - I.Y * J.X); ; if( 0 < m && m < 1 && 0 < k && k < 1) { intersection = A + k * I; return true; } return false; }
/// <summary> /// Define a straight line by using a line segment. /// </summary> /// <param name="ls">Line segment.</param> public StraightLine(LineSegment ls) : this(ls.A_Global, ls.B_Global) { }
public bool IsEqual(LineSegment L2) { return A_Global == L2.A_Global && B_Global == L2.B_Global; }
public LineCollider(Object owner) : base(owner, CollisionMethods.ColliderType.Line) { m_line = new LineSegment(Vector2.Zero, Vector2.Zero); }
public bool IntersectsCircleLine(Circle circle, LineSegment segment) { return(IntersectsCircleLine(circle.Transform.PositionGlobal, circle.Radius, segment.A_Global, segment.B_Global)); }
public Vector2 GetProjectionPoint(LineSegment screen, Vector2 projector) { return(GetProjectionPoint(screen.A_Global, screen.B_Global, projector)); }
public bool Contains(Circle container, LineSegment contained) { return(Contains(container, contained.A_Global) && Contains(container, contained.B_Global)); }
public bool IntersectsLines(LineSegment ls1, LineSegment ls2) { Vector2 A = ls1.A_Global, B = ls1.B_Global, C = ls2.A_Global, D = ls2.B_Global; return(IntersectsLines(A, B, C, D)); }