Add depth buffer support to debug overlays.
This commit is contained in:
@@ -65,14 +65,14 @@ namespace OpenRA.Graphics
|
||||
|
||||
public void RenderDebugGeometry(WorldRenderer wr)
|
||||
{
|
||||
var offset = ScreenPosition(wr) + sprite.Offset.XY;
|
||||
Game.Renderer.WorldRgbaColorRenderer.DrawRect(offset.XY, (offset + sprite.Size).XY, 1 / wr.Viewport.Zoom, Color.Red);
|
||||
var screenOffset = ScreenPosition(wr) + sprite.Offset;
|
||||
Game.Renderer.WorldRgbaColorRenderer.DrawRect(screenOffset, screenOffset + sprite.Size, 1 / wr.Viewport.Zoom, Color.Red);
|
||||
}
|
||||
|
||||
public Rectangle ScreenBounds(WorldRenderer wr)
|
||||
{
|
||||
var offset = ScreenPosition(wr) + sprite.Offset;
|
||||
return new Rectangle((int)offset.X, (int)offset.Y, (int)sprite.Size.X, (int)sprite.Size.Y);
|
||||
var screenOffset = ScreenPosition(wr) + sprite.Offset;
|
||||
return new Rectangle((int)screenOffset.X, (int)screenOffset.Y, (int)sprite.Size.X, (int)sprite.Size.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace OpenRA.Graphics
|
||||
DrawTargetMarker(wr, color, first);
|
||||
}
|
||||
|
||||
public static void DrawTargetMarker(WorldRenderer wr, Color color, float2 location)
|
||||
public static void DrawTargetMarker(WorldRenderer wr, Color color, float3 location)
|
||||
{
|
||||
var iz = 1 / wr.Viewport.Zoom;
|
||||
var offset = new float2(iz, iz);
|
||||
|
||||
@@ -163,10 +163,6 @@ namespace OpenRA.Graphics
|
||||
foreach (var a in World.ActorsWithTrait<IRenderShroud>())
|
||||
a.Trait.RenderShroud(renderShroud, this);
|
||||
|
||||
if (devTrait.Value != null && devTrait.Value.ShowDebugGeometry)
|
||||
for (var i = 0; i < renderables.Count; i++)
|
||||
renderables[i].RenderDebugGeometry(this);
|
||||
|
||||
if (enableDepthBuffer)
|
||||
Game.Renderer.Device.DisableDepthBuffer();
|
||||
|
||||
@@ -201,9 +197,14 @@ namespace OpenRA.Graphics
|
||||
r.Render(this);
|
||||
|
||||
if (devTrait.Value != null && devTrait.Value.ShowDebugGeometry)
|
||||
{
|
||||
for (var i = 0; i < renderables.Count; i++)
|
||||
renderables[i].RenderDebugGeometry(this);
|
||||
|
||||
foreach (var g in finalOverlayRenderables.GroupBy(prs => prs.GetType()))
|
||||
foreach (var r in g)
|
||||
r.RenderDebugGeometry(this);
|
||||
}
|
||||
|
||||
Game.Renderer.Flush();
|
||||
}
|
||||
@@ -233,28 +234,34 @@ namespace OpenRA.Graphics
|
||||
return new int2((int)Math.Round(px.X), (int)Math.Round(px.Y));
|
||||
}
|
||||
|
||||
// For scaling vectors to pixel sizes in the voxel renderer
|
||||
public void ScreenVectorComponents(WVec vec, out float x, out float y, out float z)
|
||||
public float3 Screen3DPxPosition(WPos pos)
|
||||
{
|
||||
x = TileSize.Width * vec.X / 1024f;
|
||||
y = TileSize.Height * (vec.Y - vec.Z) / 1024f;
|
||||
z = TileSize.Height * vec.Z / 1024f;
|
||||
// Round to nearest pixel
|
||||
var px = Screen3DPosition(pos);
|
||||
return new float3((float)Math.Round(px.X), (float)Math.Round(px.Y), px.Z);
|
||||
}
|
||||
|
||||
// For scaling vectors to pixel sizes in the voxel renderer
|
||||
public float3 ScreenVectorComponents(WVec vec)
|
||||
{
|
||||
return new float3(
|
||||
TileSize.Width * vec.X / 1024f,
|
||||
TileSize.Height * (vec.Y - vec.Z) / 1024f,
|
||||
TileSize.Height * vec.Z / 1024f);
|
||||
}
|
||||
|
||||
// For scaling vectors to pixel sizes in the voxel renderer
|
||||
public float[] ScreenVector(WVec vec)
|
||||
{
|
||||
float x, y, z;
|
||||
ScreenVectorComponents(vec, out x, out y, out z);
|
||||
return new[] { x, y, z, 1f };
|
||||
var xyz = ScreenVectorComponents(vec);
|
||||
return new[] { xyz.X, xyz.Y, xyz.Z, 1f };
|
||||
}
|
||||
|
||||
public int2 ScreenPxOffset(WVec vec)
|
||||
{
|
||||
// Round to nearest pixel
|
||||
float x, y, z;
|
||||
ScreenVectorComponents(vec, out x, out y, out z);
|
||||
return new int2((int)Math.Round(x), (int)Math.Round(y));
|
||||
var xyz = ScreenVectorComponents(vec);
|
||||
return new int2((int)Math.Round(xyz.X), (int)Math.Round(xyz.Y));
|
||||
}
|
||||
|
||||
public float ScreenZPosition(WPos pos, int offset)
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
public void RenderDebugGeometry(WorldRenderer wr)
|
||||
{
|
||||
var size = font.Measure(text).ToFloat2();
|
||||
var offset = wr.ScreenPxPosition(pos) - 0.5f * size;
|
||||
var offset = wr.Screen3DPxPosition(pos) - 0.5f * size;
|
||||
Game.Renderer.WorldRgbaColorRenderer.DrawRect(offset, offset + size, 1 / wr.Viewport.Zoom, Color.Red);
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
{
|
||||
var groundPos = voxel.pos - new WVec(0, 0, wr.World.Map.DistanceAboveTerrain(voxel.pos).Length);
|
||||
var groundZ = wr.World.Map.Grid.TileSize.Height * (groundPos.Z - voxel.pos.Z) / 1024f;
|
||||
var pxOrigin = wr.ScreenPosition(voxel.pos);
|
||||
var pxOrigin = wr.Screen3DPosition(voxel.pos);
|
||||
var shadowOrigin = pxOrigin - groundZ * (new float2(renderProxy.ShadowDirection, 1));
|
||||
var iz = 1 / wr.Viewport.Zoom;
|
||||
|
||||
@@ -141,13 +141,12 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
var c = Color.Purple;
|
||||
var psb = renderProxy.ProjectedShadowBounds;
|
||||
|
||||
// TODO: add float3 support to WorldRgbaColorRenderer
|
||||
Game.Renderer.WorldRgbaColorRenderer.DrawPolygon(new[]
|
||||
{
|
||||
shadowOrigin + psb[1].XY,
|
||||
shadowOrigin + psb[3].XY,
|
||||
shadowOrigin + psb[0].XY,
|
||||
shadowOrigin + psb[2].XY
|
||||
shadowOrigin + psb[1],
|
||||
shadowOrigin + psb[3],
|
||||
shadowOrigin + psb[0],
|
||||
shadowOrigin + psb[2]
|
||||
}, iz, c);
|
||||
|
||||
// Draw voxel bounding box
|
||||
@@ -161,9 +160,7 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
var worldTransform = v.RotationFunc().Reverse().Aggregate(scaleTransform,
|
||||
(x, y) => OpenRA.Graphics.Util.MatrixMultiply(x, OpenRA.Graphics.Util.MakeFloatMatrix(y.AsMatrix())));
|
||||
|
||||
float sx, sy, sz;
|
||||
wr.ScreenVectorComponents(v.OffsetFunc(), out sx, out sy, out sz);
|
||||
var pxPos = pxOrigin + new float2(sx, sy);
|
||||
var pxPos = pxOrigin + wr.ScreenVectorComponents(v.OffsetFunc());
|
||||
var screenTransform = OpenRA.Graphics.Util.MatrixMultiply(cameraTransform, worldTransform);
|
||||
DrawBoundsBox(pxPos, screenTransform, bounds, iz, Color.Yellow);
|
||||
}
|
||||
@@ -172,15 +169,15 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
static readonly uint[] CornerXIndex = new uint[] { 0, 0, 0, 0, 3, 3, 3, 3 };
|
||||
static readonly uint[] CornerYIndex = new uint[] { 1, 1, 4, 4, 1, 1, 4, 4 };
|
||||
static readonly uint[] CornerZIndex = new uint[] { 2, 5, 2, 5, 2, 5, 2, 5 };
|
||||
static void DrawBoundsBox(float2 pxPos, float[] transform, float[] bounds, float width, Color c)
|
||||
static void DrawBoundsBox(float3 pxPos, float[] transform, float[] bounds, float width, Color c)
|
||||
{
|
||||
var wcr = Game.Renderer.WorldRgbaColorRenderer;
|
||||
var corners = new float2[8];
|
||||
var corners = new float3[8];
|
||||
for (var i = 0; i < 8; i++)
|
||||
{
|
||||
var vec = new float[] { bounds[CornerXIndex[i]], bounds[CornerYIndex[i]], bounds[CornerZIndex[i]], 1 };
|
||||
var screen = OpenRA.Graphics.Util.MatrixVectorMultiply(transform, vec);
|
||||
corners[i] = pxPos + new float2(screen[0], screen[1]);
|
||||
corners[i] = pxPos + new float3(screen[0], screen[1], screen[2]);
|
||||
}
|
||||
|
||||
// Front face
|
||||
@@ -221,9 +218,7 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
var worldTransform = v.RotationFunc().Reverse().Aggregate(scaleTransform,
|
||||
(x, y) => OpenRA.Graphics.Util.MatrixMultiply(x, OpenRA.Graphics.Util.MakeFloatMatrix(y.AsMatrix())));
|
||||
|
||||
float sx, sy, sz;
|
||||
wr.ScreenVectorComponents(v.OffsetFunc(), out sx, out sy, out sz);
|
||||
var pxPos = pxOrigin + new float3(sx, sy, sz);
|
||||
var pxPos = pxOrigin + wr.ScreenVectorComponents(v.OffsetFunc());
|
||||
var screenTransform = OpenRA.Graphics.Util.MatrixMultiply(cameraTransform, worldTransform);
|
||||
|
||||
for (var i = 0; i < 8; i++)
|
||||
|
||||
@@ -112,13 +112,13 @@ namespace OpenRA.Mods.Common.HitShapes
|
||||
var c = Color.Yellow;
|
||||
RangeCircleRenderable.DrawRangeCircle(wr, a, Radius, 1, c, 0, c);
|
||||
RangeCircleRenderable.DrawRangeCircle(wr, b, Radius, 1, c, 0, c);
|
||||
wcr.DrawLine(new[] { wr.ScreenPosition(a - offset1), wr.ScreenPosition(b - offset1) }, 1, c);
|
||||
wcr.DrawLine(new[] { wr.ScreenPosition(a + offset1), wr.ScreenPosition(b + offset1) }, 1, c);
|
||||
wcr.DrawLine(new[] { wr.Screen3DPosition(a - offset1), wr.Screen3DPosition(b - offset1) }, 1, c);
|
||||
wcr.DrawLine(new[] { wr.Screen3DPosition(a + offset1), wr.Screen3DPosition(b + offset1) }, 1, c);
|
||||
|
||||
RangeCircleRenderable.DrawRangeCircle(wr, aa, Radius, 1, c, 0, c);
|
||||
RangeCircleRenderable.DrawRangeCircle(wr, bb, Radius, 1, c, 0, c);
|
||||
wcr.DrawLine(new[] { wr.ScreenPosition(aa - offset2), wr.ScreenPosition(bb - offset2) }, 1, c);
|
||||
wcr.DrawLine(new[] { wr.ScreenPosition(aa + offset2), wr.ScreenPosition(bb + offset2) }, 1, c);
|
||||
wcr.DrawLine(new[] { wr.Screen3DPosition(aa - offset2), wr.Screen3DPosition(bb - offset2) }, 1, c);
|
||||
wcr.DrawLine(new[] { wr.Screen3DPosition(aa + offset2), wr.Screen3DPosition(bb + offset2) }, 1, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,16 +129,16 @@ namespace OpenRA.Mods.Common.HitShapes
|
||||
var positions = targetablePositions.SelectMany(tp => tp.TargetablePositions(actor));
|
||||
foreach (var pos in positions)
|
||||
{
|
||||
var vertsTop = combatOverlayVertsTop.Select(v => wr.ScreenPosition(pos + v.Rotate(orientation)));
|
||||
var vertsBottom = combatOverlayVertsBottom.Select(v => wr.ScreenPosition(pos + v.Rotate(orientation)));
|
||||
var vertsTop = combatOverlayVertsTop.Select(v => wr.Screen3DPosition(pos + v.Rotate(orientation)));
|
||||
var vertsBottom = combatOverlayVertsBottom.Select(v => wr.Screen3DPosition(pos + v.Rotate(orientation)));
|
||||
wcr.DrawPolygon(vertsTop.ToArray(), 1, Color.Yellow);
|
||||
wcr.DrawPolygon(vertsBottom.ToArray(), 1, Color.Yellow);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var vertsTop = combatOverlayVertsTop.Select(v => wr.ScreenPosition(actorPos + v.Rotate(orientation)));
|
||||
var vertsBottom = combatOverlayVertsBottom.Select(v => wr.ScreenPosition(actorPos + v.Rotate(orientation)));
|
||||
var vertsTop = combatOverlayVertsTop.Select(v => wr.Screen3DPosition(actorPos + v.Rotate(orientation)));
|
||||
var vertsBottom = combatOverlayVertsBottom.Select(v => wr.Screen3DPosition(actorPos + v.Rotate(orientation)));
|
||||
wcr.DrawPolygon(vertsTop.ToArray(), 1, Color.Yellow);
|
||||
wcr.DrawPolygon(vertsBottom.ToArray(), 1, Color.Yellow);
|
||||
}
|
||||
|
||||
@@ -63,8 +63,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var hc = Color.Orange;
|
||||
var height = new WVec(0, 0, blockers.Max(b => b.BlockingHeight.Length));
|
||||
var ha = wr.ScreenPosition(self.CenterPosition);
|
||||
var hb = wr.ScreenPosition(self.CenterPosition + height);
|
||||
var ha = wr.Screen3DPosition(self.CenterPosition);
|
||||
var hb = wr.Screen3DPosition(self.CenterPosition + height);
|
||||
wcr.DrawLine(ha, hb, iz, hc);
|
||||
TargetLineRenderable.DrawTargetMarker(wr, hc, ha);
|
||||
TargetLineRenderable.DrawTargetMarker(wr, hc, hb);
|
||||
@@ -89,9 +89,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var da = coords.Value.LocalToWorld(new WVec(224, 0, 0).Rotate(WRot.FromYaw(p.Yaw + p.Cone)).Rotate(bodyOrientation));
|
||||
var db = coords.Value.LocalToWorld(new WVec(224, 0, 0).Rotate(WRot.FromYaw(p.Yaw - p.Cone)).Rotate(bodyOrientation));
|
||||
|
||||
var o = wr.ScreenPosition(pos);
|
||||
var a = wr.ScreenPosition(pos + da * 224 / da.Length);
|
||||
var b = wr.ScreenPosition(pos + db * 224 / db.Length);
|
||||
var o = wr.Screen3DPosition(pos);
|
||||
var a = wr.Screen3DPosition(pos + da * 224 / da.Length);
|
||||
var b = wr.Screen3DPosition(pos + db * 224 / db.Length);
|
||||
wcr.DrawLine(o, a, iz, c);
|
||||
wcr.DrawLine(o, b, iz, c);
|
||||
}
|
||||
@@ -106,8 +106,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var muzzle = self.CenterPosition + a.MuzzleOffset(self, b);
|
||||
var dirOffset = new WVec(0, -224, 0).Rotate(a.MuzzleOrientation(self, b));
|
||||
|
||||
var sm = wr.ScreenPosition(muzzle);
|
||||
var sd = wr.ScreenPosition(muzzle + dirOffset);
|
||||
var sm = wr.Screen3DPosition(muzzle);
|
||||
var sd = wr.Screen3DPosition(muzzle + dirOffset);
|
||||
wcr.DrawLine(sm, sd, iz, c);
|
||||
TargetLineRenderable.DrawTargetMarker(wr, c, sm);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
continue;
|
||||
|
||||
var exitCellCenter = self.World.Map.CenterOfCell(exitCells[i]);
|
||||
rgbaRenderer.DrawLine(wr.ScreenPosition(spawnPos), wr.ScreenPosition(exitCellCenter), 1f, self.Owner.Color.RGB);
|
||||
rgbaRenderer.DrawLine(wr.Screen3DPosition(spawnPos), wr.Screen3DPosition(exitCellCenter), 1f, self.Owner.Color.RGB);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var corners = map.Grid.CellCorners[ramp];
|
||||
var color = corners.Select(c => colors[height + c.Z / 512]).ToArray();
|
||||
var pos = map.CenterOfCell(uv.ToCPos(map));
|
||||
var screen = corners.Select(c => wr.ScreenPxPosition(pos + c).ToFloat2()).ToArray();
|
||||
var screen = corners.Select(c => wr.Screen3DPxPosition(pos + c)).ToArray();
|
||||
var width = (uv == mouseCell ? 3 : 1) / wr.Viewport.Zoom;
|
||||
|
||||
// Colors change between points, so render separately
|
||||
@@ -85,7 +85,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
foreach (var puv in map.ProjectedCellsCovering(mouseCell))
|
||||
{
|
||||
var pos = map.CenterOfCell(((MPos)puv).ToCPos(map));
|
||||
var screen = projectedCorners.Select(c => wr.ScreenPxPosition(pos + c - new WVec(0, 0, pos.Z)).ToFloat2()).ToArray();
|
||||
var screen = projectedCorners.Select(c => wr.Screen3DPxPosition(pos + c - new WVec(0, 0, pos.Z))).ToArray();
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
var j = (i + 1) % 4;
|
||||
|
||||
@@ -73,8 +73,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
foreach (var r in i.Range)
|
||||
{
|
||||
var tl = wr.ScreenPosition(i.CenterPosition - new WVec(r.Length, r.Length, 0));
|
||||
var br = wr.ScreenPosition(i.CenterPosition + new WVec(r.Length, r.Length, 0));
|
||||
var tl = wr.Screen3DPosition(i.CenterPosition - new WVec(r.Length, r.Length, 0));
|
||||
var br = wr.Screen3DPosition(i.CenterPosition + new WVec(r.Length, r.Length, 0));
|
||||
|
||||
Game.Renderer.WorldRgbaColorRenderer.FillEllipse(tl, br, Color.FromArgb((int)alpha, i.Color));
|
||||
|
||||
alpha -= rangeStep;
|
||||
|
||||
Reference in New Issue
Block a user