Merge pull request #10521 from pchote/facing-cleanup
Remove Util.GetFacing.
This commit is contained in:
@@ -915,7 +915,11 @@ namespace OpenRA
|
||||
|
||||
public int FacingBetween(CPos cell, CPos towards, int fallbackfacing)
|
||||
{
|
||||
return Traits.Util.GetFacing(CenterOfCell(towards) - CenterOfCell(cell), fallbackfacing);
|
||||
var delta = CenterOfCell(towards) - CenterOfCell(cell);
|
||||
if (delta.HorizontalLengthSquared == 0)
|
||||
return fallbackfacing;
|
||||
|
||||
return delta.Yaw.Facing;
|
||||
}
|
||||
|
||||
public void Resize(int width, int height) // editor magic.
|
||||
|
||||
@@ -31,18 +31,6 @@ namespace OpenRA.Traits
|
||||
return (facing - rot) & 0xFF;
|
||||
}
|
||||
|
||||
public static int GetFacing(WVec d, int currentFacing)
|
||||
{
|
||||
if (d.LengthSquared == 0)
|
||||
return currentFacing;
|
||||
|
||||
// OpenRA defines north as -y, so invert
|
||||
var angle = WAngle.ArcTan(-d.Y, d.X, 4).Angle;
|
||||
|
||||
// Convert back to a facing
|
||||
return (angle / 4 - 0x40) & 0xFF;
|
||||
}
|
||||
|
||||
public static int GetNearestFacing(int facing, int desiredFacing)
|
||||
{
|
||||
var turn = desiredFacing - facing;
|
||||
|
||||
@@ -41,6 +41,8 @@ namespace OpenRA
|
||||
public bool Equals(WAngle other) { return other == this; }
|
||||
public override bool Equals(object obj) { return obj is WAngle && Equals((WAngle)obj); }
|
||||
|
||||
public int Facing { get { return Angle / 4; } }
|
||||
|
||||
public int Sin() { return new WAngle(Angle - 256).Cos(); }
|
||||
|
||||
public int Cos()
|
||||
|
||||
@@ -58,6 +58,18 @@ namespace OpenRA
|
||||
(int)((lx * mtx[2] + ly * mtx[6] + lz * mtx[10]) / mtx[15]));
|
||||
}
|
||||
|
||||
public WAngle Yaw
|
||||
{
|
||||
get
|
||||
{
|
||||
if (LengthSquared == 0)
|
||||
return WAngle.Zero;
|
||||
|
||||
// OpenRA defines north as -y
|
||||
return WAngle.ArcTan(-Y, X) - new WAngle(256);
|
||||
}
|
||||
}
|
||||
|
||||
public static WVec Lerp(WVec a, WVec b, int mul, int div) { return a + (b - a) * mul / div; }
|
||||
|
||||
public static WVec LerpQuadratic(WVec a, WVec b, WAngle pitch, int mul, int div)
|
||||
@@ -134,7 +146,7 @@ namespace OpenRA
|
||||
case "X": return X;
|
||||
case "Y": return Y;
|
||||
case "Z": return Z;
|
||||
case "Facing": return Traits.Util.GetFacing(this, 0);
|
||||
case "Facing": return Yaw.Facing;
|
||||
default: throw new LuaException("WVec does not define a member '{0}'".F(key));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user