- ConvexHulls consist of Segments and SegmentPoints which keep references to each other
- LightSources fetch a list of non-backfacing ConvexHull segments within their range, and sort the points counter-clockwise (TODO: calculate triangles from the points) - fixed incorrectly working CircleIntersectsRectangle method
This commit is contained in:
@@ -276,15 +276,16 @@ namespace Barotrauma
|
||||
public static bool CircleIntersectsRectangle(Vector2 circlePos, float radius, Rectangle rect)
|
||||
{
|
||||
float xDist = Math.Abs(circlePos.X - rect.Center.X);
|
||||
float yDist = Math.Abs(circlePos.Y - rect.Center.Y);
|
||||
|
||||
int halfWidth = rect.Width / 2;
|
||||
int halfHeight = rect.Height / 2;
|
||||
|
||||
if (xDist > (halfWidth + radius)) { return false; }
|
||||
if (xDist <= (halfWidth)) { return true; }
|
||||
if (yDist > (halfHeight + radius)) { return false; }
|
||||
|
||||
float yDist = Math.Abs(circlePos.Y - rect.Center.Y);
|
||||
int halfHeight = rect.Height / 2;
|
||||
|
||||
if (yDist > (halfHeight + radius)) { return false; }
|
||||
if (xDist <= (halfWidth)) { return true; }
|
||||
if (yDist <= (halfHeight)) { return true; }
|
||||
|
||||
float distSqX = xDist - halfWidth;
|
||||
@@ -475,4 +476,18 @@ namespace Barotrauma
|
||||
return Math.Sign(d2 - d1);
|
||||
}
|
||||
}
|
||||
|
||||
class CompareSegmentPointCCW : IComparer<Lights.SegmentPoint>
|
||||
{
|
||||
private Vector2 center;
|
||||
|
||||
public CompareSegmentPointCCW(Vector2 center)
|
||||
{
|
||||
this.center = center;
|
||||
}
|
||||
public int Compare(Lights.SegmentPoint a, Lights.SegmentPoint b)
|
||||
{
|
||||
return CompareCCW.Compare(a.WorldPos, b.WorldPos, center);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user