From dc7c6d5cd66fc039c393a9abcb8f30d3bbdbde3e Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 5 Jan 2010 13:51:51 +1300 Subject: [PATCH] minimap: add support for sprite scaling to SpriteRenderer/Graphics.Util --- OpenRa.Game/Graphics/SpriteRenderer.cs | 7 ++++++- OpenRa.Game/Graphics/TerrainRenderer.cs | 2 +- OpenRa.Game/Graphics/Util.cs | 10 +++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/OpenRa.Game/Graphics/SpriteRenderer.cs b/OpenRa.Game/Graphics/SpriteRenderer.cs index 87e28c693f..3074c43a0f 100644 --- a/OpenRa.Game/Graphics/SpriteRenderer.cs +++ b/OpenRa.Game/Graphics/SpriteRenderer.cs @@ -55,12 +55,17 @@ namespace OpenRa.Game.Graphics } public void DrawSprite(Sprite s, float2 location, PaletteType palette) + { + DrawSprite(s, location, palette, s.size); + } + + public void DrawSprite(Sprite s, float2 location, PaletteType palette, float2 size) { if (s.sheet != currentSheet) Flush(); currentSheet = s.sheet; - Util.FastCreateQuad(vertices, indices, location.ToInt2(), s, (int) palette, nv, ni); + Util.FastCreateQuad(vertices, indices, location.ToInt2(), s, (int)palette, nv, ni, size); nv += 4; ni += 6; if (++sprites >= spritesPerBatch) Flush(); diff --git a/OpenRa.Game/Graphics/TerrainRenderer.cs b/OpenRa.Game/Graphics/TerrainRenderer.cs index 07d4263984..1032c3b0a0 100644 --- a/OpenRa.Game/Graphics/TerrainRenderer.cs +++ b/OpenRa.Game/Graphics/TerrainRenderer.cs @@ -34,7 +34,7 @@ namespace OpenRa.Game.Graphics for( int i = map.XOffset ; i < map.XOffset + map.Width; i++ ) { Sprite tile = tileMapping[map.MapTiles[i, j]]; - Util.FastCreateQuad(vertices, indices, Game.CellSize * new float2(i, j), tile, 0, nv, ni); + Util.FastCreateQuad(vertices, indices, Game.CellSize * new float2(i, j), tile, 0, nv, ni, tile.size); nv += 4; ni += 6; } diff --git a/OpenRa.Game/Graphics/Util.cs b/OpenRa.Game/Graphics/Util.cs index 97ad03da94..85dada816d 100644 --- a/OpenRa.Game/Graphics/Util.cs +++ b/OpenRa.Game/Graphics/Util.cs @@ -57,14 +57,14 @@ namespace OpenRa.Game.Graphics static float[] channelSelect = { 0.75f, 0.25f, -0.25f, -0.75f }; - public static void FastCreateQuad(Vertex[] vertices, ushort[] indices, float2 o, Sprite r, int palette, int nv, int ni) + public static void FastCreateQuad(Vertex[] vertices, ushort[] indices, float2 o, Sprite r, int palette, int nv, int ni, float2 size) { float2 attrib = new float2(palette / 16.0f, channelSelect[(int)r.channel]); - vertices[nv] = new Vertex(KLerp(o, r.size, 0), r.FastMapTextureCoords(0), attrib); - vertices[nv + 1] = new Vertex(KLerp(o, r.size, 1), r.FastMapTextureCoords(1), attrib); - vertices[nv + 2] = new Vertex(KLerp(o, r.size, 2), r.FastMapTextureCoords(2), attrib); - vertices[nv + 3] = new Vertex(KLerp(o, r.size, 3), r.FastMapTextureCoords(3), attrib); + vertices[nv] = new Vertex(KLerp(o, size, 0), r.FastMapTextureCoords(0), attrib); + vertices[nv + 1] = new Vertex(KLerp(o, size, 1), r.FastMapTextureCoords(1), attrib); + vertices[nv + 2] = new Vertex(KLerp(o, size, 2), r.FastMapTextureCoords(2), attrib); + vertices[nv + 3] = new Vertex(KLerp(o, size, 3), r.FastMapTextureCoords(3), attrib); indices[ni] = (ushort)(nv); indices[ni + 1] = indices[ni + 3] = (ushort)(nv + 1);