Implement heightmap-aware view -> cell conversion.

This commit is contained in:
Paul Chote
2015-03-27 21:43:48 +00:00
parent c68cb995f4
commit 1e54b19bd3
3 changed files with 87 additions and 5 deletions

View File

@@ -87,6 +87,29 @@ namespace OpenRA
return r.Contains(p.ToPointF());
}
static int WindingDirectionTest(int2 v0, int2 v1, int2 p)
{
return (v1.X - v0.X) * (p.Y - v0.Y) - (p.X - v0.X) * (v1.Y - v0.Y);
}
public static bool PolygonContains(this int2[] polygon, int2 p)
{
var windingNumber = 0;
for (var i = 0; i < polygon.Length; i++)
{
var tv = polygon[i];
var nv = polygon[(i + 1) % polygon.Length];
if (tv.Y <= p.Y && nv.Y > p.Y && WindingDirectionTest(tv, nv, p) > 0)
windingNumber++;
else if (tv.Y > p.Y && nv.Y <= p.Y && WindingDirectionTest(tv, nv, p) < 0)
windingNumber--;
}
return windingNumber != 0;
}
public static bool HasModifier(this Modifiers k, Modifiers mod)
{
return (k & mod) == mod;