public Surface(SurfaceType type, Vector2 start, Vector2 end) { surfaceLineSegment = new LineSegment(start, end); m_type = type; construct(); }
public Surface(Tower a, Tower b, SurfaceType type, Level Parent) { tower_A = a; tower_A.AddSurface(this); tower_B = b; tower_B.AddSurface(this); m_type = type; surfaceLineSegment = new LineSegment(a.getPosition(), b.getPosition()); parent = Parent; construct(); }
/* PUBLIC STATIC */ static bool Intersects(LineSegment first, LineSegment second) { return false; }
static Vector2? IntersectionPoint(LineSegment first, LineSegment second) { return null; }
private float findIntersection(LineSegment segment) { Vector2 u = End - Start; Vector2 v = segment.End - segment.Start; Vector2 w = Start - segment.Start; Vector2 vPerp = new Vector2(-v.Y, v.X); vPerp.Normalize(); if ((Vector2.Dot(Start - segment.Start, vPerp)) > 0) { // Need to flip!! //v = segment.Start - segment.End; } float tIntersect = (v.Y * w.X - v.X * w.Y) / (v.X * u.Y - v.Y * u.X); if (tIntersect >= 0f && tIntersect <= 1f) { float sIntersect = (u.X * w.Y - u.Y * w.X) / (u.X * v.Y - u.Y * v.X); if (sIntersect > 0f && sIntersect < 1f) { return tIntersect * Length; } } return -1f; }
public bool IsColliding(LineSegment segment) { float tIntersect = findIntersection(segment); return (tIntersect >= 0f); }
public Vector2? FindIntersectionPoint(LineSegment segment) { float tIntersect = findIntersection(segment); if (tIntersect < 0) { return null; } Vector2 u = End - Start; u.Normalize(); Vector2 pIntersect = Start + tIntersect * u; return pIntersect; }
public float Chomp(LineSegment segment) { if (!IsColliding(segment)) { return 0f; } float amountToChomp = findIntersection(segment); Chomp(amountToChomp); return amountToChomp; }