Add MrGameEng.AI utility-AI module; format codebase with CSharpier New MrGameEng.AI module (ResponseCurve, Consideration, UtilityAction, UtilityAi selector, Blackboard) plus CSharpier formatting applied across the whole engine. Documents the CSharpier convention in CLAUDE.md. @
This commit is contained in:
@@ -52,23 +52,35 @@ public readonly struct CameraState
|
||||
public static class CameraMath
|
||||
{
|
||||
/// <summary>Computes the full camera state for a frame.</summary>
|
||||
public static CameraState Compute(in Camera camera, int virtualWidth, int virtualHeight, ViewportMapping mapping)
|
||||
public static CameraState Compute(
|
||||
in Camera camera,
|
||||
int virtualWidth,
|
||||
int virtualHeight,
|
||||
ViewportMapping mapping
|
||||
)
|
||||
{
|
||||
var zoom = camera.Zoom <= 0f ? 1f : camera.Zoom;
|
||||
var position = ClampToBounds(camera, virtualWidth, virtualHeight, zoom);
|
||||
|
||||
var view =
|
||||
Matrix.CreateTranslation(-position.X, -position.Y, 0f) *
|
||||
Matrix.CreateRotationZ(-camera.Rotation) *
|
||||
Matrix.CreateScale(zoom, zoom, 1f) *
|
||||
Matrix.CreateTranslation(virtualWidth / 2f, virtualHeight / 2f, 0f);
|
||||
Matrix.CreateTranslation(-position.X, -position.Y, 0f)
|
||||
* Matrix.CreateRotationZ(-camera.Rotation)
|
||||
* Matrix.CreateScale(zoom, zoom, 1f)
|
||||
* Matrix.CreateTranslation(virtualWidth / 2f, virtualHeight / 2f, 0f);
|
||||
|
||||
var inverseView = Matrix.Invert(view);
|
||||
|
||||
return new CameraState
|
||||
{
|
||||
View = view,
|
||||
Projection = Matrix.CreateOrthographicOffCenter(0f, virtualWidth, virtualHeight, 0f, 0f, 1f),
|
||||
Projection = Matrix.CreateOrthographicOffCenter(
|
||||
0f,
|
||||
virtualWidth,
|
||||
virtualHeight,
|
||||
0f,
|
||||
0f,
|
||||
1f
|
||||
),
|
||||
InverseView = inverseView,
|
||||
CullRect = ComputeCullRect(inverseView, virtualWidth, virtualHeight),
|
||||
VirtualWidth = virtualWidth,
|
||||
@@ -81,14 +93,29 @@ public static class CameraMath
|
||||
/// Computes the letterbox mapping that fits the virtual resolution into a physical
|
||||
/// viewport, preserving aspect ratio and centering.
|
||||
/// </summary>
|
||||
public static ViewportMapping ComputeMapping(int screenWidth, int screenHeight, int virtualWidth, int virtualHeight)
|
||||
public static ViewportMapping ComputeMapping(
|
||||
int screenWidth,
|
||||
int screenHeight,
|
||||
int virtualWidth,
|
||||
int virtualHeight
|
||||
)
|
||||
{
|
||||
var scale = MathF.Min((float)screenWidth / virtualWidth, (float)screenHeight / virtualHeight);
|
||||
var offset = new Vector2(screenWidth - virtualWidth * scale, screenHeight - virtualHeight * scale) / 2f;
|
||||
var scale = MathF.Min(
|
||||
(float)screenWidth / virtualWidth,
|
||||
(float)screenHeight / virtualHeight
|
||||
);
|
||||
var offset =
|
||||
new Vector2(screenWidth - virtualWidth * scale, screenHeight - virtualHeight * scale)
|
||||
/ 2f;
|
||||
return new ViewportMapping(offset, scale);
|
||||
}
|
||||
|
||||
private static Vector2 ClampToBounds(in Camera camera, int virtualWidth, int virtualHeight, float zoom)
|
||||
private static Vector2 ClampToBounds(
|
||||
in Camera camera,
|
||||
int virtualWidth,
|
||||
int virtualHeight,
|
||||
float zoom
|
||||
)
|
||||
{
|
||||
if (camera.Bounds is not { } bounds)
|
||||
{
|
||||
@@ -100,7 +127,8 @@ public static class CameraMath
|
||||
var halfH = virtualHeight / (2f * zoom);
|
||||
return new Vector2(
|
||||
ClampAxis(camera.Position.X, bounds.Left + halfW, bounds.Right - halfW),
|
||||
ClampAxis(camera.Position.Y, bounds.Top + halfH, bounds.Bottom - halfH));
|
||||
ClampAxis(camera.Position.Y, bounds.Top + halfH, bounds.Bottom - halfH)
|
||||
);
|
||||
}
|
||||
|
||||
private static float ClampAxis(float value, float min, float max) =>
|
||||
|
||||
Reference in New Issue
Block a user