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


C# QuadTree类代码示例

本文整理汇总了C#中QuadTree的典型用法代码示例。如果您正苦于以下问题:C# QuadTree类的具体用法?C# QuadTree怎么用?C# QuadTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: GameplayScreen

        public GameplayScreen(Game1 game, Vector2 worldSize, Levels currentLevel)
            : base(game)
        {
            this.worldSize = worldSize;
            eCurrentLevel = currentLevel;

            heatmapWriteTimer = 0;

            //Make the tree a bit wider for outer walls.
            quadTree = new QuadTree(new Rectangle(
                -10, -10, (int)worldSize.X + 20, (int)worldSize.Y + 20));

            //Add the 4 walls on the outside of the world.
            Components.Add(new Wall(GDGame, new Vector2(-10, -10), new Vector2(worldSize.X + 10, 0)));
            Components.Add(new Wall(GDGame, new Vector2(worldSize.X, -10), new Vector2(worldSize.X + 10, worldSize.Y)));
            Components.Add(new Wall(GDGame, new Vector2(0, worldSize.Y), new Vector2(worldSize.X + 10, worldSize.Y + 10)));
            Components.Add(new Wall(GDGame, new Vector2(-10, 0), new Vector2(0, worldSize.Y + 10)));

            //Add the player to world.
            Components.Add(Player = new PlayerBall(GDGame, new Vector2(300, 300)));

            //Give the camera the new world size.
            GDGame.Camera.WorldSize = worldSize + new Vector2(0, 100);

            gameOver = won = false;
            GDGame.IsMouseVisible = false;
        }
开发者ID:Whojoo,项目名称:Bubble-popper,代码行数:27,代码来源:GameplayScreen.cs

示例2: Map

 public Map()
 {
     _Random = Regulus.Utility.Random.Instance;
     _EntranceSet = new List<Visible>();
     this._Set = new Dictionary<Guid, Visible>();
     this._QuadTree = new QuadTree<Visible>(new Size(2, 2), 100);
 }
开发者ID:jiowchern,项目名称:ItIsNotAGame1-Backend,代码行数:7,代码来源:Map.cs

示例3: QuadTreeTestOne

        public void QuadTreeTestOne()
        {
            GridVector2[] points = new GridVector2[] { new GridVector2(0,0),
                                                       new GridVector2(1,1),
                                                       new GridVector2(-10,-10),
                                                       new GridVector2(-7.5, 2.5),
                                                       new GridVector2(8.5, -1.5),
                                                       new GridVector2(3.5, -6.5),
                                                       new GridVector2(1.5, -8.5),
                                                       new GridVector2(10, 10)};
            int[] values = new int[] {0,1,2,3,4,5,6,7};
            GridRectangle border = GridVector2.Border(points);
            QuadTree<int> tree = new QuadTree<int>(points, values, border);

            //Start with a basic test ensuring we can find all the existing points
            for(int i = 0; i < points.Length; i++)
            {
                double distance;
                int RetValue;
                RetValue = tree.FindNearest(points[i], out distance);

                Debug.Assert(RetValue == i);
                Debug.Assert(distance == 0);
            }

            //Check to see if we can find nearby points
            GridVector2[] nearpoints = new GridVector2[] { new GridVector2(.25,.25),
                                                       new GridVector2(.5,.51),
                                                       new GridVector2(-7.5,-7.5),
                                                       new GridVector2(-7.5, -1.5),
                                                       new GridVector2(8.5, -5.5),
                                                       new GridVector2(4.5, -7.75),
                                                       new GridVector2(1, -8.75),
                                                       new GridVector2(11, 11)}; //Out of original boundaries

            for (int i = 0; i < nearpoints.Length; i++)
            {
                double distance;
                int RetValue;
                RetValue = tree.FindNearest(nearpoints[i], out distance);

                Debug.Assert(RetValue == i);
                Debug.Assert(distance == GridVector2.Distance(points[i], nearpoints[i]));
            }

            //Check to see if we can return all points in a rectangle
            GridRectangle gridRect = new GridRectangle(0,15, 0,15);
            List<GridVector2> intersectPoints;
            List<int> intersectValues;
            tree.Intersect(gridRect, out intersectPoints, out intersectValues);
            Debug.Assert(intersectValues.Contains(0));
            Debug.Assert(intersectValues.Contains(1));
            Debug.Assert(intersectValues.Contains(7));

            Debug.Assert(false == intersectValues.Contains(2));
            Debug.Assert(false == intersectValues.Contains(3));
            Debug.Assert(false == intersectValues.Contains(4));
            Debug.Assert(false == intersectValues.Contains(5));
            Debug.Assert(false == intersectValues.Contains(6));
        }
开发者ID:abordt,项目名称:Viking,代码行数:60,代码来源:QuadTreeTest.cs

示例4: getObjectsColliding

        private void getObjectsColliding(Rectangle bounds, QuadTree<Object.Object>.QuadNode currentNode, List<Object.Object> result, List<SearchFlags.Searchflag> _SearchFlags)
        {
            if (Utility.Collision.Intersection.RectangleIsInRectangle(bounds, currentNode.Bounds))
            {
                //Circle fits in node, so search in subnodes
                Boolean circleFitsInSubnode = false;
                foreach (QuadTree<Object.Object>.QuadNode node in currentNode.Nodes)
                {
                    if (node != null)
                    {
                        if (Utility.Collision.Intersection.RectangleIsInRectangle(bounds, node.Bounds))
                        {
                            circleFitsInSubnode = true;
                            getObjectsInRange(bounds, node, result, _SearchFlags);
                        }
                    }
                }

                //Aggrocircle fit into a subnode? then
                if (!circleFitsInSubnode)
                {
                    addAllObjectsInRange(currentNode, bounds, result, _SearchFlags);
                }
                return;
            }
            if (currentNode.Equals(this.quadTreeObject.Root))
            {
                addAllObjectsInRange(currentNode, bounds, result, _SearchFlags);
            }
        }
开发者ID:Gothen111,项目名称:2DWorld,代码行数:30,代码来源:World.Collision.cs

示例5: QuadTreeBroadPhase

 /// <summary>
 /// Creates a new quad tree broadphase with the specified span.
 /// </summary>
 /// <param name="span">the maximum span of the tree (world size)</param>
 public QuadTreeBroadPhase(AABB span)
 {
     _quadTree = new QuadTree<FixtureProxy>(span, 5, 10);
     _idRegister = new Dictionary<int, Element<FixtureProxy>>();
     _moveBuffer = new List<Element<FixtureProxy>>();
     _pairBuffer = new List<Pair>();
 }
开发者ID:kyallbarrows,项目名称:Cinch_4-3,代码行数:11,代码来源:QuadTreeBroadPhase.cs

示例6: Search_AreaWithOnePoint_ReturnsOnePoint

        public void Search_AreaWithOnePoint_ReturnsOnePoint()
        {
            var center = new Point(0, 0);
            var boundary = new Boundary(center, 1, 1);
            var quad = new QuadTree<Point>(boundary);

            // insert one point in the second quadrant
            var point = new Point(-0.75, +0.75);
            quad.Insert(point);

            // then insert one point in each remaining quadrant
            var points = new List<Point>
            {
                new Point(+0.75, +0.75), // first quadrant
                new Point(-0.75, -0.75), // third quadrant
                new Point(+0.75, -0.75) // fourth quadrant
            };

            points.ForEach(p => quad.Insert(p));

            // search second quadrant
            var searchArea = new Boundary(new Point(-0.5, 0.5), 0.5, 0.5);

            var results = quad.Search(searchArea);

            Assert.IsTrue(results.Count == 1);
            Assert.IsTrue(results.Contains(point));
        }
开发者ID:clapis,项目名称:roamler,代码行数:28,代码来源:PointQuadTreeTests.cs

示例7: GameWorld

        public GameWorld(int width, int height)
        {
            Width = width;
            Height = height;
            TileMap = new TileMap(Width, Height);

            _gameObjects = new List<GameObject>();
            _quadTree = new QuadTree<GameObject>(new Rectangle(0,0, Width * 64, Height * 64));
            _quadTree.MaxGeneration = 4;
            _addNewObjectsQueue = new Queue<GameObject>();
            _deleteObjectsQueue = new Queue<GameObject>();

            Camera = new Camera(Game.g_screenSize, new Point(Game.g_screenSize.Width / 2, Game.g_screenSize.Height / 2), true);
            Camera.ScaleTo(1f);
            Camera.MoveSpeed = 7;

            background = new ParallaxBackground(this);
            BloodSystem = new BloodSystem(this);
            BloodSystem.Init();
            BloodSystem.BlendWith(back);

            mback = new MagicBackground();

            UpdateObjectsEnqueues();
        }
开发者ID:mokujin,项目名称:DN,代码行数:25,代码来源:GameWorld.cs

示例8: CollisionDetector

 /// <summary>
 /// Default ctor
 /// </summary>
 public CollisionDetector()
 {
     // TODO: evaluate these numbers
     // sample usage says
     // "Use larger min size, and higher min object values for better performance"
     m_tree = new QuadTree<Collider>(new DoubleSize(25, 25), 0, false);
 }
开发者ID:dallasmccall,项目名称:metroid-ai-project,代码行数:10,代码来源:CollisionDetector.cs

示例9: createSpatialIndex

 public void createSpatialIndex()
 {
     this._spatialIndex = new QuadTree<OGRBufferCacheRow>(this._envelope);
     foreach (OGRBufferCacheRow row in this._rows)
     {
         this._spatialIndex.add(row);
     }
 }
开发者ID:scoobird,项目名称:SSIS-GDAL,代码行数:8,代码来源:OGRBufferCache.cs

示例10: GameObjectsManager

        public GameObjectsManager(Camera camera)
        {
            _camera = camera;
            _gameObjects = new List<GameObject>(150);
            _addNewObjectsQueue = new Queue<GameObject>(150);
            _deleteObjectsQueue = new Queue<GameObject>(150);

            QuadTree = new QuadTree<ColliderComponent>(new Rectangle(0, 0, 1024, 1024));
        }
开发者ID:remy22,项目名称:BlueberryEngine,代码行数:9,代码来源:GameObjectsManager.cs

示例11: Map

        private Map()
        {
            const int numTiles = TerrainConstants.TilesPerMapSide * TerrainConstants.TilesPerMapSide;
            _tiles = new Dictionary<TileIdentifier, Tile>(numTiles);

            const float baseLength = TerrainConstants.MapLength / 2.0f;
            var basePosition = new Point(baseLength, baseLength);
            QuadTree = new QuadTree<Tile>(basePosition, TerrainConstants.TilesPerMapSide, TerrainConstants.TileSize);
        }
开发者ID:WCell,项目名称:WCell-Terrain,代码行数:9,代码来源:Map.cs

示例12: EntityManager

 public EntityManager()
 {
     float gridSize = 262144.0f / 2;
     quadTree = new QuadTree(new Vector2(-gridSize / 2, -gridSize / 2), gridSize, null, QuadType.Parent);
     Random r = Game1.Instance.Random;
     Time = 1.0f;
     selectRect = new Rectangle(400, 400, 400, 400);
     results = new List<GraphicalEntity>();
 }
开发者ID:Bigalan09,项目名称:Zombies,代码行数:9,代码来源:EntityManager.cs

示例13: Build

 public static TriangulationQuadTree Build(IReadOnlyList<DelaunayTriangle> triangulation)
 {
     var quadTree = new QuadTree<DelaunayTriangle, Vec2>(
     GetBoundingRectangle(triangulation.SelectMany(x => x.Points)),
     GetRectangle,
     Convert,
     Test);
      return new TriangulationQuadTree(quadTree);
 }
开发者ID:ItzWarty,项目名称:AdventuresInShade,代码行数:9,代码来源:TriangulationQuadTree.cs

示例14: Insert_WithinBoundary_ReturnsTrue

        public void Insert_WithinBoundary_ReturnsTrue()
        {
            var center = new Point(0, 0);
            var boundary = new Boundary(center, 1, 1);
            var quad = new QuadTree<Point>(boundary);

            Assert.IsTrue(quad.Insert(new Point(0, 0)));
            Assert.IsTrue(quad.Insert(new Point(-0.5, 0.5)));
        }
开发者ID:clapis,项目名称:roamler,代码行数:9,代码来源:PointQuadTreeTests.cs

示例15: Insert_OutOfBoundary_ReturnsFalse

        public void Insert_OutOfBoundary_ReturnsFalse()
        {
            var center = new Point(0, 0);
            var boundary = new Boundary(center, 1, 1);
            var quad = new QuadTree<Point>(boundary);

            Assert.IsFalse(quad.Insert(new Point(2, 0)));
            Assert.IsFalse(quad.Insert(new Point(0, 2)));
        }
开发者ID:clapis,项目名称:roamler,代码行数:9,代码来源:PointQuadTreeTests.cs


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