/// <summary> /// Construct /// </summary> /// <param name="body"></param> /// <param name="distanceFromBody"></param> /// <param name="maxDistanceBetweenEachNode"></param> /// <returns></returns> private static List<Node> Construct(RectangleBody body, int distanceFromBody, int maxDistanceBetweenEachNode) { List<Node> result = new List<Node>(); Vector2 bodyPosition = body.GetPosition(); Vector2 bodySize = body.GetSize(); // Top-left corner Vector2 northWestUnit = new Vector2(-1f, -1f); northWestUnit.Normalize(); Vector2 topLeftNodePosition = bodyPosition - (bodySize / 2) + distanceFromBody * northWestUnit; result.Add(new Node(topLeftNodePosition)); // Top-right corner Vector2 northEastUnit = new Vector2(1f, -1f); northEastUnit.Normalize(); Vector2 topRightNodePosition = bodyPosition + new Vector2(bodySize.X, -bodySize.Y) / 2 + distanceFromBody * northEastUnit; result.Add(new Node(topRightNodePosition)); // Bottom-right corner Vector2 southEastUnit = new Vector2(1f, 1f); southEastUnit.Normalize(); Vector2 bottomRightNodePosition = bodyPosition + (bodySize / 2) + distanceFromBody * southEastUnit; result.Add(new Node(bottomRightNodePosition)); // Bottom-left corner Vector2 southWestUnit = new Vector2(-1f, 1f); southWestUnit.Normalize(); Vector2 bottomLeftNodePosition = bodyPosition + new Vector2(-bodySize.X, bodySize.Y) / 2 + distanceFromBody * southWestUnit; result.Add(new Node(bottomLeftNodePosition)); // Top-left corner to top-right corner result.AddRange(FillLine(topLeftNodePosition, topRightNodePosition, maxDistanceBetweenEachNode, false)); // Top-right corner to bottom-right corner result.AddRange(FillLine(topRightNodePosition, bottomRightNodePosition, maxDistanceBetweenEachNode, false)); // Bottom-right corner to bottom-left corner result.AddRange(FillLine(bottomRightNodePosition, bottomLeftNodePosition, maxDistanceBetweenEachNode, false)); // Bottom-left corner to top-left corner result.AddRange(FillLine(bottomLeftNodePosition, topLeftNodePosition, maxDistanceBetweenEachNode, false)); return result; }
protected abstract bool DetectCollision(RectangleBody rectangleBody);
/// <summary> /// Detect collision with a rectangle body /// </summary> /// <param name="rectangleBody"></param> /// <returns></returns> protected override bool DetectCollision(RectangleBody rectangleBody) { return false; }
/// <summary> /// Detect a collision with a rectangle body /// </summary> /// <param name="rectangleBody"></param> /// <returns></returns> protected override bool DetectCollision(RectangleBody rectangleBody) { return (rectangleBody.GetClosestPointOnPerimeter(this.Position) - this.Position).LengthSquared() < this.Radius * this.Radius; }