Remove fp from facing calculation.

This commit is contained in:
Paul Chote
2011-01-27 12:00:40 +13:00
parent ad0e0a18bd
commit 9db41f5638
2 changed files with 9 additions and 7 deletions

View File

@@ -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; }
}
}

View File

@@ -31,21 +31,20 @@ namespace OpenRA.Traits
return ( facing - rot ) & 0xFF;
}
static float2[] fvecs = Graphics.Util.MakeArray<float2>( 32,
i => -float2.FromAngle( i / 16.0f * (float)Math.PI ) * new float2( 1f, 1.3f ) );
static int2[] fvecs = Graphics.Util.MakeArray<int2>( 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;