Add WPos/WVec.LerpQuadratic to simplify ballistic calculations.

This commit is contained in:
Paul Chote
2013-07-07 12:49:43 +12:00
parent 1e7f1ab225
commit 5976913c73
2 changed files with 28 additions and 0 deletions

View File

@@ -36,6 +36,20 @@ namespace OpenRA
public static WPos Lerp(WPos a, WPos b, int mul, int div) { return a + (b - a) * mul / div; }
public static WPos LerpQuadratic(WPos a, WPos b, WAngle pitch, int mul, int div)
{
// Start with a linear lerp between the points
var ret = Lerp(a, b, mul, div);
if (pitch.Angle == 0)
return ret;
// Add an additional quadratic variation to height
// Uses fp to avoid integer overflow
var offset = (int)((float)((float)(b - a).Length*pitch.Tan()*mul*(div - mul)) / (float)(1024*div*div));
return new WPos(ret.X, ret.Y, ret.Z + offset);
}
public static WPos Average(params WPos[] list)
{
if (list == null || list.Length == 0)

View File

@@ -53,6 +53,20 @@ namespace OpenRA
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)
{
// Start with a linear lerp between the points
var ret = Lerp(a, b, mul, div);
if (pitch.Angle == 0)
return ret;
// Add an additional quadratic variation to height
// Uses fp to avoid integer overflow
var offset = (int)((float)((float)(b - a).Length*pitch.Tan()*mul*(div - mul)) / (float)(1024*div*div));
return new WVec(ret.X, ret.Y, ret.Z + offset);
}
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode(); }
public override bool Equals(object obj)