Rename WorldRenderer.Position -> ProjectedPosition.
This commit is contained in:
@@ -45,7 +45,7 @@ namespace OpenRA.Graphics
|
|||||||
// Viewport geometry (world-px)
|
// Viewport geometry (world-px)
|
||||||
public int2 CenterLocation { get; private set; }
|
public int2 CenterLocation { get; private set; }
|
||||||
|
|
||||||
public WPos CenterPosition { get { return worldRenderer.Position(CenterLocation); } }
|
public WPos CenterPosition { get { return worldRenderer.ProjectedPosition(CenterLocation); } }
|
||||||
|
|
||||||
public int2 TopLeft { get { return CenterLocation - viewportSize / 2; } }
|
public int2 TopLeft { get { return CenterLocation - viewportSize / 2; } }
|
||||||
public int2 BottomRight { get { return CenterLocation + viewportSize / 2; } }
|
public int2 BottomRight { get { return CenterLocation + viewportSize / 2; } }
|
||||||
@@ -158,14 +158,14 @@ namespace OpenRA.Graphics
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Something is very wrong, but lets return something that isn't completely bogus and hope the caller can recover
|
// Something is very wrong, but lets return something that isn't completely bogus and hope the caller can recover
|
||||||
return worldRenderer.World.Map.CellContaining(worldRenderer.Position(ViewToWorldPx(view)));
|
return worldRenderer.World.Map.CellContaining(worldRenderer.ProjectedPosition(ViewToWorldPx(view)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Returns an unfiltered list of all cells that could potentially contain the mouse cursor</summary>
|
/// <summary> Returns an unfiltered list of all cells that could potentially contain the mouse cursor</summary>
|
||||||
IEnumerable<MPos> CandidateMouseoverCells(int2 world)
|
IEnumerable<MPos> CandidateMouseoverCells(int2 world)
|
||||||
{
|
{
|
||||||
var map = worldRenderer.World.Map;
|
var map = worldRenderer.World.Map;
|
||||||
var minPos = worldRenderer.Position(world);
|
var minPos = worldRenderer.ProjectedPosition(world);
|
||||||
|
|
||||||
// Find all the cells that could potentially have been clicked
|
// Find all the cells that could potentially have been clicked
|
||||||
var a = map.CellContaining(minPos - new WVec(1024, 0, 0)).ToMPos(map.TileShape);
|
var a = map.CellContaining(minPos - new WVec(1024, 0, 0)).ToMPos(map.TileShape);
|
||||||
@@ -230,8 +230,8 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
// Calculate the viewport corners in "projected wpos" (at ground level), and
|
// Calculate the viewport corners in "projected wpos" (at ground level), and
|
||||||
// this to an equivalent projected cell for the two corners
|
// this to an equivalent projected cell for the two corners
|
||||||
var tl = map.CellContaining(worldRenderer.Position(TopLeft)).ToMPos(map);
|
var tl = map.CellContaining(worldRenderer.ProjectedPosition(TopLeft)).ToMPos(map);
|
||||||
var br = map.CellContaining(worldRenderer.Position(BottomRight)).ToMPos(map);
|
var br = map.CellContaining(worldRenderer.ProjectedPosition(BottomRight)).ToMPos(map);
|
||||||
|
|
||||||
// Diamond tile shapes don't have straight edges, and so we need
|
// Diamond tile shapes don't have straight edges, and so we need
|
||||||
// an additional cell margin to include the cells that are half
|
// an additional cell margin to include the cells that are half
|
||||||
|
|||||||
@@ -264,7 +264,11 @@ namespace OpenRA.Graphics
|
|||||||
return pos.Y + pos.Z + offset;
|
return pos.Y + pos.Z + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WPos Position(int2 screenPx)
|
/// <summary>
|
||||||
|
/// Returns a position in the world that is projected to the given screen position.
|
||||||
|
/// There are many possible world positions, and the returned value chooses the value with no elevation.
|
||||||
|
/// </summary>
|
||||||
|
public WPos ProjectedPosition(int2 screenPx)
|
||||||
{
|
{
|
||||||
var ts = Game.ModData.Manifest.TileSize;
|
var ts = Game.ModData.Manifest.TileSize;
|
||||||
return new WPos(1024 * screenPx.X / ts.Width, 1024 * screenPx.Y / ts.Height, 0);
|
return new WPos(1024 * screenPx.X / ts.Width, 1024 * screenPx.Y / ts.Height, 0);
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var bounds = self.Bounds;
|
var bounds = self.Bounds;
|
||||||
bounds.Offset(pos.X, pos.Y);
|
bounds.Offset(pos.X, pos.Y);
|
||||||
var spaceBuffer = (int)(10 / wr.Viewport.Zoom);
|
var spaceBuffer = (int)(10 / wr.Viewport.Zoom);
|
||||||
var effectPos = wr.Position(new int2(pos.X, bounds.Y - spaceBuffer));
|
var effectPos = wr.ProjectedPosition(new int2(pos.X, bounds.Y - spaceBuffer));
|
||||||
|
|
||||||
yield return new TextRenderable(font, effectPos, 0, color, name);
|
yield return new TextRenderable(font, effectPos, 0, color, name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
pxPos += info.Offset;
|
pxPos += info.Offset;
|
||||||
|
|
||||||
// HACK: Because WorldRenderer.Position() does not care about terrain height at the location
|
// HACK: Because WorldRenderer.Position() does not care about terrain height at the location
|
||||||
var renderPos = wr.Position(pxPos);
|
var renderPos = wr.ProjectedPosition(pxPos);
|
||||||
renderPos = new WPos(renderPos.X, renderPos.Y + self.CenterPosition.Z, self.CenterPosition.Z);
|
renderPos = new WPos(renderPos.X, renderPos.Y + self.CenterPosition.Z, self.CenterPosition.Z);
|
||||||
|
|
||||||
anim.Tick();
|
anim.Tick();
|
||||||
|
|||||||
@@ -237,8 +237,8 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
// Draw viewport rect
|
// Draw viewport rect
|
||||||
if (hasRadar)
|
if (hasRadar)
|
||||||
{
|
{
|
||||||
var tl = CellToMinimapPixel(world.Map.CellContaining(worldRenderer.Position(worldRenderer.Viewport.TopLeft)));
|
var tl = CellToMinimapPixel(world.Map.CellContaining(worldRenderer.ProjectedPosition(worldRenderer.Viewport.TopLeft)));
|
||||||
var br = CellToMinimapPixel(world.Map.CellContaining(worldRenderer.Position(worldRenderer.Viewport.BottomRight)));
|
var br = CellToMinimapPixel(world.Map.CellContaining(worldRenderer.ProjectedPosition(worldRenderer.Viewport.BottomRight)));
|
||||||
|
|
||||||
Game.Renderer.EnableScissor(mapRect);
|
Game.Renderer.EnableScissor(mapRect);
|
||||||
DrawRadarPings();
|
DrawRadarPings();
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ namespace OpenRA.Mods.RA.Graphics
|
|||||||
var step = steps.Where(t => (to - (z + new float2(t[0], t[1]))).LengthSquared < (to - z).LengthSquared)
|
var step = steps.Where(t => (to - (z + new float2(t[0], t[1]))).LengthSquared < (to - z).LengthSquared)
|
||||||
.MinBy(t => Math.Abs(float2.Dot(z + new float2(t[0], t[1]), q) + c));
|
.MinBy(t => Math.Abs(float2.Dot(z + new float2(t[0], t[1]), q) + c));
|
||||||
|
|
||||||
var pos = wr.Position((z + new float2(step[2], step[3])).ToInt2());
|
var pos = wr.ProjectedPosition((z + new float2(step[2], step[3])).ToInt2());
|
||||||
rs.Add(new SpriteRenderable(s.GetSprite(step[4]), pos, WVec.Zero, 0, pal, 1f, true).PrepareRender(wr));
|
rs.Add(new SpriteRenderable(s.GetSprite(step[4]), pos, WVec.Zero, 0, pal, 1f, true).PrepareRender(wr));
|
||||||
|
|
||||||
z += new float2(step[0], step[1]);
|
z += new float2(step[0], step[1]);
|
||||||
|
|||||||
Reference in New Issue
Block a user