public bool Intersects(BoundingRect rect) { Vector2 circleDistance = Vector2.Zero; Vector2 rectSize = rect.Max - rect.Min; circleDistance.X = Math.Abs(center.X - (rect.Min.X + rectSize.X/2)); circleDistance.Y = Math.Abs(center.Y - (rect.Min.Y + rectSize.Y / 2)); if (circleDistance.X > rectSize.X / 2 + radius) return false; if (circleDistance.Y > rectSize.Y / 2 + radius) return false; if (circleDistance.X <= rectSize.X / 2) return true; if (circleDistance.Y <= rectSize.Y / 2) return true; float deltaX = circleDistance.X - rectSize.X / 2; float deltaY = circleDistance.Y - rectSize.Y / 2; float cornerDistanceSquared = deltaX * deltaX + deltaY * deltaY; return cornerDistanceSquared <= radius * radius; }
public bool Intersects(BoundingRect rect) { return false; }
public ConvexHull(Game game, Vector2[] points, Color color, Vector2 position) { this.game = game; this.position = position; int vertexCount = points.Length; vertices = new VertexPositionColor[vertexCount + 1]; Vector2 center = Vector2.Zero; bool zeroPoint = false; for (int i = 0; i < vertexCount; i++) { vertices[i] = new VertexPositionColor(new Vector3(points[i], 0), color); center += points[i]; if (!zeroPoint && points[i] == Vector2.Zero) { zeroPoint = true; } } center /= points.Length; vertices[vertexCount] = new VertexPositionColor(new Vector3(center, 0), color); primitiveCount = points.Length; indices = new short[primitiveCount * 3]; for (int i = 0; i < primitiveCount; i++) { indices[3 * i] = (short)i; indices[3 * i + 1] = (short)((i + 1) % vertexCount); indices[3 * i + 2] = (short)vertexCount; } backFacing = new bool[vertexCount]; sphereBox = points.Length != 4 || !zeroPoint; if (sphereBox) { boundingSphere = new BoundingCircle(); float boundingRadius = 0; foreach (Vector2 point in points) { if ((center - point).Length() > boundingRadius) { boundingRadius = (center - point).Length(); } } boundingSphere.Center = center + position; boundingSphere.Radius = boundingRadius; } else { boundingBox = new BoundingRect(); List<Vector2> realPoints = new List<Vector2>(); foreach (Vector2 point in points) { realPoints.Add(point + position); } boundingBox.CreateFromPoints(realPoints); } }