当前位置: 首页>>代码示例>>C#>>正文


C# Polygon.GetNormals方法代码示例

本文整理汇总了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.
        }
开发者ID:tylermenezes,项目名称:Hunt-the-Wumpus-2010,代码行数:17,代码来源:Collision.cs

示例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.
        }
开发者ID:tylermenezes,项目名称:Hunt-the-Wumpus-2010,代码行数:36,代码来源:Collision.cs


注:本文中的Polygon.GetNormals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。