Added Camera2D::ScaledViewportOversized

This commit is contained in:
2025-01-18 00:53:59 -05:00
parent fd2391e03b
commit 4ec166c1d9
3 changed files with 58 additions and 0 deletions

View File

@@ -30,6 +30,8 @@ namespace CaveGame::Client
AABB2D Viewport() const;
/// Returns the bounds of the screen-viewport, in gameworld-coordinates, with scaling by the camera's zoom.
AABB2D ScaledViewport() const;
AABB2D ScaledViewportOversized(float oversize) const;
/// Returns the target coordinates of this camera. The camera will move over time to reach this point.
Vector2 Target() const;
/// Sets the target coordinates of this camera. The camera will move over time to reach this point.

View File

@@ -157,4 +157,10 @@ namespace CaveGame::Client
void Camera2D::MoveSpeed(float value) {
speed = value;
}
AABB2D Camera2D::ScaledViewportOversized(float oversize) const {
return AABB2D(
position - ScaledHalfSizeOffset() - Vector2(oversize),
position + ScaledHalfSizeOffset() + Vector2(oversize*2));
}
}

View File

@@ -164,3 +164,53 @@ Vector2 CaveGame::Core::Solver::SolveAABB(const AABB2D& a, const AABB2D& b)
Vector2 sizeB = Vector2{b.Width(), b.Height()} / 2.f;
return SolveAABB(posA, sizeA, posB, sizeB);
}
bool CaveGame::Core::Solver::AABB2DvsPoint(const Vector2 &pos, const Vector2 &size, const Vector2 &point) {
float absDistanceX = J3ML::Math::Abs(pos.x - point.x);
float absDistanceY = J3ML::Math::Abs(pos.y - point.y);
float sumWidth = size.x;
float sumHeight = size.y;
if (absDistanceY >= sumHeight || absDistanceX >= sumWidth)
return false;
return true;
}
bool CaveGame::Core::Solver::AABB2DvsPoint(const AABB2D &box, const Vector2 &point) {
Vector2 pos = box.minPoint + Vector2(box.Width()/2.f, box.Height()/2.f);
Vector2 size = Vector2{box.Width(), box.Height()} / 2.f;
return AABB2DvsPoint(pos, size, point);
}
Vector2 CaveGame::Core::Solver::SolveAABBvsPoint(const Vector2 &pos, const Vector2 &size, const Vector2 &point) {
float distanceX = pos.x - point.x;
float distanceY = pos.y - point.y;
float absDistanceX = J3ML::Math::Abs(distanceX);
float absDistanceY = J3ML::Math::Abs(distanceY);
float sumWidth = size.x;
float sumHeight = size.y;
float sx = sumWidth - absDistanceX;
float sy = sumHeight - absDistanceY;
if (sx > sy)
{
if (sy > 0)
sx = 0;
} else {
if (sx > 0)
sy = 0;
}
if (distanceX < 0)
{
sx = -sx;
}
if (distanceY < 0)
sy = -sy;
return {sx, sy};
}