From 1f2824e6143716ce347843d017753da3e96d3978 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 7 Aug 2016 19:28:28 +0100 Subject: [PATCH] Add WAngle.Lerp function. --- OpenRA.Game/WAngle.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/OpenRA.Game/WAngle.cs b/OpenRA.Game/WAngle.cs index be63a238b7..4260b01149 100644 --- a/OpenRA.Game/WAngle.cs +++ b/OpenRA.Game/WAngle.cs @@ -64,6 +64,20 @@ namespace OpenRA return new WAngle(Angle - 512).Tan(); } + public static WAngle Lerp(WAngle a, WAngle b, int mul, int div) + { + // Map 1024 <-> 0 wrapping into linear space + var aa = a.Angle; + var bb = b.Angle; + if (aa > bb && aa - bb > 512) + aa -= 1024; + + if (bb > aa && bb - aa > 512) + bb -= 1024; + + return new WAngle(aa + (bb - aa) * mul / div); + } + public static WAngle ArcTan(int y, int x) { return ArcTan(y, x, 1); } public static WAngle ArcTan(int y, int x, int stride) {