public static Vector2 CollisionVector(Circle circle, AABB aabb) { Vector2 nearestVector = NearestVectorBetweenCircleAndAABB(aabb, circle); if (NearestVectorIntersects(nearestVector, circle)) { return nearestVector; } return NULL_VECTOR; }
private void DrawBrick(AABB brick) { Rectangle destRect = new Rectangle( (int)(brick.Position.X - brick.HalfExtent.X), (int)(brick.Position.Y - brick.HalfExtent.Y), (int)brick.HalfExtent.X * 2, (int)brick.HalfExtent.Y * 2); float opacity = (float)1.0f; if (_collisionPaused) opacity = 0.2f; _spriteBatch.Begin(); _spriteBatch.Draw(_brickTexture, destRect, brick.Color * opacity); _spriteBatch.End(); }
protected override void LoadContent() { _ballTexture = Game.Content.Load<Texture2D>("Images/Ball"); _brickTexture = Game.Content.Load<Texture2D>("Images/BrickTemplate"); _vectorTexture = Game.Content.Load<Texture2D>("Images/DirectionVector"); _brickDatas = Game.Content.Load<BrickData[]>("XMLFile1"); foreach (var brickData in _brickDatas) { var brick = new AABB(brickData.Position.X, brickData.Position.Y, brickData.Size.X, brickData.Size.Y); brick.Color = brickData.Color; _levelBricks.Add(brick); } base.LoadContent(); }
public static Vector2 NearestVectorBetweenCircleAndAABB(AABB aabb, Circle circle) { Vector2 v = circle.Position - aabb.Position; Vector2 vClamped = Vector2.Clamp(v, -aabb.HalfExtent, aabb.HalfExtent); return v - vClamped; }