public bool Overlaps(Projection p) { if (p.Min < this.Min) { if (p.Max >= this.Min) { return true; } else return false; } else { if (this.Max >= p.Min) { return true; } else return false; } }
public virtual bool Intersects(Shape s) { if (s is ConcaveShape) { return((s as ConcaveShape).Intersects(this)); } if (s == this) { return(true); } int i = 0; // Using this shape... for (i = 0; i < this.TransformedVertices.Length; i++) { // The next index should be i + 1 // However, if we're on the last cycle, we have looped around. // The next index is the one we started with (0) int nextIndex = i + 1; if (i == this.TransformedVertices.Length - 1) { nextIndex = 0; } Vector2 side = this.TransformedVertices[nextIndex] - this.TransformedVertices[i]; // Find the axis perpendicular to the current side. // This is what we'll use to test the separation. Vector2 axis = new Vector2(side.Y, -side.X); Projection p1 = this.Project(axis); Projection p2 = s.Project(axis); if (!p1.Overlaps(p2)) { return(false); } } // Next shape... for (i = 0; i < s.TransformedVertices.Length; i++) { // The next index should be i + 1 // However, if we're on the last cycle, we have looped around. // The next index is the one we started with (0) int nextIndex = i + 1; if (i == s.TransformedVertices.Length - 1) { nextIndex = 0; } Vector2 side = s.TransformedVertices[nextIndex] - s.TransformedVertices[i]; // Find the axis perpendicular to the current side. // This is what we'll use to test the separation. Vector2 axis = new Vector2(side.Y, -side.X); Projection p1 = this.Project(axis); Projection p2 = s.Project(axis); if (!p1.Overlaps(p2)) { return(false); } } return(true); }