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


C# World.QueryAABB方法代码示例

本文整理汇总了C#中FarseerPhysics.Dynamics.World.QueryAABB方法的典型用法代码示例。如果您正苦于以下问题:C# World.QueryAABB方法的具体用法?C# World.QueryAABB怎么用?C# World.QueryAABB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FarseerPhysics.Dynamics.World的用法示例。


在下文中一共展示了World.QueryAABB方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetFixtureCircleIntersections

        public static FixtureCoord[] GetFixtureCircleIntersections(World world, Vector2 point, float radius)
        {
            List<Fixture> potentials = new List<Fixture>();
            var box = new FarseerPhysics.Collision.AABB(new Xna.Vector2(point.X, point.Y), radius * 2, radius * 2);
            world.QueryAABB(delegate (Fixture fixture)
            {
                potentials.Add(fixture);
                return false;
            }, ref box);

            List<FixtureCoord> collisions = new List<FixtureCoord>();
            foreach (Fixture f in potentials)
            {
                Xna.Vector2 relativePoint = f.Body.GetLocalPoint(new Xna.Vector2(point.X, point.Y));
                switch (f.Shape.ShapeType)
                {
                    case ShapeType.Polygon:
                        PolygonShape polygon = (PolygonShape)f.Shape;
                        for (int i = 0; i < polygon.Vertices.Count; i++)
                        {
                            int iNext = (i + 1) % polygon.Vertices.Count;
                            LineF edge = new LineF(polygon.Vertices[i], polygon.Vertices[iNext]);
                            IntersectCoord[] intersects = MathExt.LineCircleIntersect(new Vector2(relativePoint.X, relativePoint.Y), radius, edge, true);
                            for (int j = 0; i < intersects.Length; i++)
                            {
                                collisions.Add(new FixtureCoord(f, i, (float)intersects[j].TFirst));
                            }
                            /*if (intersects.Length > 0)
                            {
                                fixtureCollisions.Add(f);
                                break;
                            }*/
                        }
                        break;

                    default:
                        throw new NotImplementedException();
                }
            }
            return collisions.ToArray();
        }
开发者ID:AyyTee,项目名称:Aventyr,代码行数:41,代码来源:FixtureExt.cs

示例2: FindTarget

        private void FindTarget(World world)
        {
            Vector2 currentPosition = Owner.Position;
            closestTarget = Owner.PlayWindow.GoodCellList.First();
            closestDistance = (currentPosition - closestTarget.Position).LengthSquared();
            float boxSideStep = 2;
            targetFound = false;
            while (boxSideStep < 64 && targetFound == false)
            {
                AABB boundingBox = new AABB(ConvertUnits.ToSimUnits(currentPosition), boxSideStep, boxSideStep);

                world.QueryAABB(AABBCollision, ref boundingBox);

                boxSideStep *= 4;
            }
            _target = closestTarget;
        }
开发者ID:em-mo,项目名称:sommarhack,代码行数:17,代码来源:VirusStrategy.cs


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