From 021e1116b850f638012866c0f0d71f492eb6c7a3 Mon Sep 17 00:00:00 2001 From: Sascha Biedermann Date: Tue, 19 Mar 2013 18:41:36 +0100 Subject: [PATCH 1/2] added moving average to contrails to smooth them when aircraft are circling --- OpenRA.Game/PPos.cs | 2 ++ OpenRA.Mods.RA/Effects/Contrail.cs | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/OpenRA.Game/PPos.cs b/OpenRA.Game/PPos.cs index 05f757eb6e..3ce73312dc 100644 --- a/OpenRA.Game/PPos.cs +++ b/OpenRA.Game/PPos.cs @@ -29,6 +29,8 @@ namespace OpenRA public static explicit operator PVecInt(PPos a) { return new PVecInt(a.X, a.Y); } public static explicit operator PVecFloat(PPos a) { return new PVecFloat(a.X, a.Y); } + public static PPos operator /(PPos a, int b) { return new PPos(a.X / b , a.Y / b); } + public static PPos operator +(PPos a, PPos b) { return new PPos(a.X + b.X, a.Y + b.Y); } public static PPos operator +(PPos a, PVecInt b) { return new PPos(a.X + b.X, a.Y + b.Y); } public static PVecInt operator -(PPos a, PPos b) { return new PVecInt(a.X - b.X, a.Y - b.Y); } public static PPos operator -(PPos a, PVecInt b) { return new PPos(a.X - b.X, a.Y - b.Y); } diff --git a/OpenRA.Mods.RA/Effects/Contrail.cs b/OpenRA.Mods.RA/Effects/Contrail.cs index 1fa6602b5c..1db4bf1bb4 100755 --- a/OpenRA.Mods.RA/Effects/Contrail.cs +++ b/OpenRA.Mods.RA/Effects/Contrail.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA { public readonly int[] ContrailOffset = {0, 0}; - public readonly int TrailLength = 20; + public readonly int TrailLength = 25; public readonly Color Color = Color.White; public readonly bool UsePlayerColor = true; @@ -86,10 +86,12 @@ namespace OpenRA.Mods.RA Color trailStart = Color; Color trailEnd = Color.FromArgb(trailStart.A - 255 / TrailLength, trailStart.R, trailStart.G, trailStart.B); - for (int i = positions.Count - 1 - StartSkip; i >= 1; --i) + for (int i = positions.Count - 1 - StartSkip; i >= 4; --i) { - var conPos = positions[i]; - var nextPos = positions[i - 1]; + var conPos = positions[i] + positions[i-1] + positions[i-2] + positions[i-3]; + conPos /= 4; + var nextPos = positions[i-1] + positions[i-2] + positions[i-3] + positions[i-4]; + nextPos /= 4; if (self.World.RenderedShroud.IsVisible(conPos.ToCPos()) || self.World.RenderedShroud.IsVisible(nextPos.ToCPos())) From e562f8d2cc674a8619a4012e501bea94d66065dc Mon Sep 17 00:00:00 2001 From: Sascha Biedermann Date: Tue, 19 Mar 2013 19:58:30 +0100 Subject: [PATCH 2/2] refactored Average method in PPos --- OpenRA.Game/PPos.cs | 21 +++++++++++++++++++-- OpenRA.Mods.RA/Effects/Contrail.cs | 6 ++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/OpenRA.Game/PPos.cs b/OpenRA.Game/PPos.cs index 3ce73312dc..77df86eb58 100644 --- a/OpenRA.Game/PPos.cs +++ b/OpenRA.Game/PPos.cs @@ -29,8 +29,6 @@ namespace OpenRA public static explicit operator PVecInt(PPos a) { return new PVecInt(a.X, a.Y); } public static explicit operator PVecFloat(PPos a) { return new PVecFloat(a.X, a.Y); } - public static PPos operator /(PPos a, int b) { return new PPos(a.X / b , a.Y / b); } - public static PPos operator +(PPos a, PPos b) { return new PPos(a.X + b.X, a.Y + b.Y); } public static PPos operator +(PPos a, PVecInt b) { return new PPos(a.X + b.X, a.Y + b.Y); } public static PVecInt operator -(PPos a, PPos b) { return new PVecInt(a.X - b.X, a.Y - b.Y); } public static PPos operator -(PPos a, PVecInt b) { return new PPos(a.X - b.X, a.Y - b.Y); } @@ -46,6 +44,25 @@ namespace OpenRA return a + ((PVecInt)(b - a) * mul / div); } + public static PPos Average(params PPos[] list) + { + if (list == null || list.Length == 0) + throw new ArgumentException("PPos: Cannot calculate average of empty list."); + + var x = 0; + var y = 0; + foreach(var pos in list) + { + x += pos.X; + y += pos.Y; + } + + x /= list.Length; + y /= list.Length; + + return new PPos(x,y); + } + public float2 ToFloat2() { return new float2(X, Y); } public int2 ToInt2() { return new int2(X, Y); } public CPos ToCPos() { return new CPos((int)(1f / Game.CellSize * X), (int)(1f / Game.CellSize * Y)); } diff --git a/OpenRA.Mods.RA/Effects/Contrail.cs b/OpenRA.Mods.RA/Effects/Contrail.cs index 1db4bf1bb4..95de6f5b33 100755 --- a/OpenRA.Mods.RA/Effects/Contrail.cs +++ b/OpenRA.Mods.RA/Effects/Contrail.cs @@ -88,10 +88,8 @@ namespace OpenRA.Mods.RA for (int i = positions.Count - 1 - StartSkip; i >= 4; --i) { - var conPos = positions[i] + positions[i-1] + positions[i-2] + positions[i-3]; - conPos /= 4; - var nextPos = positions[i-1] + positions[i-2] + positions[i-3] + positions[i-4]; - nextPos /= 4; + var conPos = PPos.Average(positions[i], positions[i-1], positions[i-2], positions[i-3]); + var nextPos = PPos.Average(positions[i-1], positions[i-2], positions[i-3], positions[i-4]); if (self.World.RenderedShroud.IsVisible(conPos.ToCPos()) || self.World.RenderedShroud.IsVisible(nextPos.ToCPos()))