Change QuantizeFacing to return a facing instead of an index.

This commit is contained in:
Paul Chote
2020-05-27 22:00:49 +01:00
committed by reaperrr
parent 7c6ec577dc
commit bfb6c671fb
8 changed files with 49 additions and 13 deletions

View File

@@ -46,13 +46,23 @@ namespace OpenRA.Mods.Common
return facing + turn;
}
public static int QuantizeFacing(int facing, int numFrames)
/// <summary>
/// Calculate the frame index (between 0..numFrames) that
/// should be used for the given facing value.
/// </summary>
public static int IndexFacing(int facing, int numFrames)
{
var step = 256 / numFrames;
var a = (facing + step / 2) & 0xff;
return a / step;
}
/// <summary>Rounds the given facing value to the nearest quantized step.</summary>
public static int QuantizeFacing(int facing, int steps)
{
return IndexFacing(facing, steps) * (256 / steps);
}
/// <summary>Wraps an arbitrary integer facing value into the range 0 - 255</summary>
public static int NormalizeFacing(int f)
{