Add WorldCenter property to CameraState for effective camera positioning
CI / build-test (push) Successful in 1m19s
CI / build-test (push) Successful in 1m19s
Enhanced the CameraState struct with a new WorldCenter property that calculates the effective position of the camera after bounds-clamping. This property is intended to be used for zoom-to-cursor functionality, ensuring that the repositioning aligns with what is rendered. Added unit tests to verify that WorldCenter reflects the unclamped camera position and correctly accounts for bounds clamping, distinguishing it from the raw camera position. Tests: WorldCenter_EqualsUnclampedCameraPosition, WorldCenter_ReflectsBoundsClamp_UnlikeRawPosition.
This commit is contained in:
@@ -83,6 +83,29 @@ public class CameraMathTests
|
||||
AssertVector(new Vector2(0f, 200f), state.ScreenToWorld(Vector2.Zero));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WorldCenter_EqualsUnclampedCameraPosition()
|
||||
{
|
||||
var camera = new Camera(new Vector2(640f, 360f), zoom: 2f);
|
||||
|
||||
var state = CameraMath.Compute(camera, 1280, 720, ViewportMapping.Identity);
|
||||
|
||||
AssertVector(camera.Position, state.WorldCenter);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WorldCenter_ReflectsBoundsClamp_UnlikeRawPosition()
|
||||
{
|
||||
var bounds = new RectF(0f, 0f, 2000f, 1000f);
|
||||
var camera = new Camera(new Vector2(-500f, 500f), bounds: bounds);
|
||||
|
||||
var state = CameraMath.Compute(camera, 800, 600, ViewportMapping.Identity);
|
||||
|
||||
// Raw position is (-500, 500); only X clamps (to half-width 400 from the left world edge),
|
||||
// Y (500) is already inside [300, 700]. The effective centre the view is built around is (400, 500).
|
||||
AssertVector(new Vector2(400f, 500f), state.WorldCenter);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Mapping_CentersVirtualResolutionInWiderWindow()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user