Add smooth minimap to world movement

This commit is contained in:
Gustas
2025-09-11 13:21:21 +03:00
committed by Paul Chote
parent 1a8a3eca4d
commit 082f369fe3
3 changed files with 50 additions and 22 deletions

View File

@@ -250,7 +250,7 @@ namespace OpenRA.Graphics
public CPos ViewToWorld(int2 view)
{
var world = worldRenderer.Viewport.ViewToWorldPx(view);
var world = ViewToWorldPx(view);
var map = worldRenderer.World.Map;
var candidates = CandidateMouseoverCells(world).ToList();
@@ -337,6 +337,13 @@ namespace OpenRA.Graphics
allCellsDirty = true;
}
public void Center(float2 pos)
{
CenterLocation = worldRenderer.ScreenPosition(pos).Clamp(mapBounds);
cellsDirty = true;
allCellsDirty = true;
}
public void Scroll(float2 delta, bool ignoreBorders)
{
// Convert scroll delta from world-px to viewport-px

View File

@@ -384,12 +384,22 @@ namespace OpenRA.Graphics
Game.Renderer.SetPalette(palette);
}
// Conversion between world and screen coordinates
/// <summary>
/// Converts a world position to a screen position.
/// </summary>
public float2 ScreenPosition(WPos pos)
{
return new float2((float)TileSize.Width * pos.X / TileScale, (float)TileSize.Height * (pos.Y - pos.Z) / TileScale);
}
/// <summary>
/// Converts a world position to a screen position.
/// </summary>
public float2 ScreenPosition(float2 pos)
{
return new float2(TileSize.Width * pos.X / TileScale, TileSize.Height * pos.Y / TileScale);
}
public float3 Screen3DPosition(WPos pos)
{
// The projection from world coordinates to screen coordinates has