本文整理汇总了C#中Polygon.GetNormals方法的典型用法代码示例。如果您正苦于以下问题:C# Polygon.GetNormals方法的具体用法?C# Polygon.GetNormals怎么用?C# Polygon.GetNormals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polygon
的用法示例。
在下文中一共展示了Polygon.GetNormals方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestPointInPoly
public static bool TestPointInPoly(Polygon a, Vector2 pt)
{
var norms = a.GetNormals();
foreach (Vector2 ax in norms)
{
var p = a.Project(ax);
var pt_p = Vector2.Dot(pt, ax);
if (pt_p > p.Max || pt_p < p.Min) //no collision if even 1 separating axis found
{
return false;
}
}
return true; //must check all SAs before confirming a collision.
}
示例2: TestCollisionPolyFull
//axis is the normal of collision, FROM a TO b!. DISP IS ALWYAS NEGATIVE! (for collisions)
public static bool TestCollisionPolyFull(Polygon a, Polygon b, out Vector2 axis, out float disp)
{
axis = new Vector2();
disp = float.MinValue;
//
//Collision test
//
//var norms = a.GetNormals().ToList(); //used to be a union.
//norms.AddRange(b.GetNormals().ToList());
var norms = a.GetNormals().Union(b.GetNormals());
foreach (Vector2 ax in norms)
{
float d = Projection.IntervalDist(a.Project(ax), b.Project(ax));
if (d > 0) //no collision if even 1 separating axis found
{
disp = 0;
return false;
}
else if (d > disp) //return disp w/ lowset overlap (ie: highest separation)
{
disp = d;
axis = ax;
}
}
if (Vector2.Dot(b.Position - a.Position, axis) < 0) //make sure the normal always points from a->b. (should this use .GetCentroid() instead of position?)
axis = -axis;
return true; //must check all SAs before confirming a collision. return SA w/ lowest overlap.
}