diff --git a/OpenRA.FileFormats/Primitives/int2.cs b/OpenRA.FileFormats/Primitives/int2.cs index 715c5a3cbf..ebaddde75f 100644 --- a/OpenRA.FileFormats/Primitives/int2.cs +++ b/OpenRA.FileFormats/Primitives/int2.cs @@ -78,5 +78,8 @@ namespace OpenRA return new int2(Math.Min(r.Right, Math.Max(X, r.Left)), Math.Min(r.Bottom, Math.Max(Y, r.Top))); } + + public static int Dot(int2 a, int2 b) { return a.X * b.X + a.Y * b.Y; } + } } diff --git a/OpenRA.Game/Traits/Util.cs b/OpenRA.Game/Traits/Util.cs index 41b02315b1..42d7aea876 100755 --- a/OpenRA.Game/Traits/Util.cs +++ b/OpenRA.Game/Traits/Util.cs @@ -31,21 +31,20 @@ namespace OpenRA.Traits return ( facing - rot ) & 0xFF; } - static float2[] fvecs = Graphics.Util.MakeArray( 32, - i => -float2.FromAngle( i / 16.0f * (float)Math.PI ) * new float2( 1f, 1.3f ) ); + static int2[] fvecs = Graphics.Util.MakeArray( 32, + i => (-1024*float2.FromAngle( i / 16.0f * (float)Math.PI ) * new float2( 1f, 1.3f )).ToInt2() ); - public static int GetFacing( int2 dd, int currentFacing ) + public static int GetFacing( int2 d, int currentFacing ) { - var d = dd.ToFloat2(); - if (float2.WithinEpsilon(d, float2.Zero, 0.001f)) + if (d == int2.Zero) return currentFacing; int highest = -1; - float highestDot = -1.0f; + int highestDot = -1; for( int i = 0 ; i < fvecs.Length ; i++ ) { - float dot = float2.Dot( fvecs[ i ], d ); + int dot = int2.Dot( fvecs[ i ], d ); if( dot > highestDot ) { highestDot = dot;