Update() private method

private Update ( ) : void
return void
コード例 #1
0
        public void RandomizingPositionsQT()
        {
            for (int i = 0; i < N; i++)
            {
                m_Objects[i].Position = m_Objects[(i + 1) % N].Position;
            }

            m_Tree.Update();
        }
コード例 #2
0
ファイル: QuadTreeDemo.cs プロジェクト: deanljohnson/QuadTree
        private void GraphicalTestUpdate(float dt)
        {
            m_Tree.Update();

            m_TestRefreshCounter += dt;
            if (m_TestRefreshCounter > m_TestRefreshRate)
            {
                m_TestRefreshCounter = 0f;
                //RefreshTest();
            }

            var mousePos = GetMousePos();

            foreach (var testObject in m_TestObjects)
            {
                var toMouse = (mousePos - testObject.Key.Position).Normalized();
                testObject.Key.Position += (testObject.Value + toMouse) * dt * m_SpeedMultiplier;
                testObject.Key.FillColor = Color.Blue;
                WrapPosition(testObject.Key);
            }

            var kClosest = m_Tree.GetKClosestObjects(GetMousePos(), 30, m_QueeryRange);

            foreach (var circle in kClosest.Cast <CircleShape>())
            {
                circle.FillColor = Color.Green;
            }
            if (kClosest.Length > 1)
            {
                ((CircleShape)kClosest[0]).FillColor = Color.Red;
            }

            while (m_NumCircles > m_TestObjects.Count)
            {
                var obj = new CircleShape(2f)
                {
                    FillColor = Color.Blue,
                    Position  = GetRandomPos()
                };
                m_TestObjects.Add(obj, RandomVelocity());
                m_Tree.Add(obj);
            }
            while (m_NumCircles < m_TestObjects.Count)
            {
                var obj = m_TestObjects.Keys.First();
                m_TestObjects.Remove(obj);
                m_Tree.Remove(obj);
            }

            for (int i = 0; i < 10; i++)
            {
                var removedObj = m_TestObjects.Keys.ToArray()[Random.Next(0, m_TestObjects.Count)];
                //m_TestObjects.Remove(removedObj);
                //m_Tree.Remove(removedObj);
            }
        }
コード例 #3
0
        public void GetKClosestObjectsTest()
        {
            QuadTree <TestObject> tree = new QuadTree <TestObject>(m_Bounds);

            SpacePartitionerTests.GetKClosestObjectsTest(tree);

            // Now execute tests that will hit all branches of
            // KNearestNeighbor search method

            tree.Clear();

            tree.Add(new TestObject(490, 499));
            tree.Add(new TestObject(501, 499));
            tree.Add(new TestObject(499.5f, 501));
            tree.Add(new TestObject(501, 501));
            tree.Update();

            // Uses different orders of child node iteration
            tree.GetKClosestObjects(new Vector2f(499, 499), 5);
            tree.GetKClosestObjects(new Vector2f(501, 499), 5);
            tree.GetKClosestObjects(new Vector2f(499, 501), 5);
            tree.GetKClosestObjects(new Vector2f(501, 501), 5);

            // Some objects not in range
            tree.GetKClosestObjects(new Vector2f(500, 499), 3, 1.001f);

            // Requires replacing elements in the PQ
            tree.GetKClosestObjects(new Vector2f(500, 499), 3, 10f);
        }
コード例 #4
0
        public void BulkCreationTest()
        {
            QuadTree <TestObject> individualTree = new QuadTree <TestObject>(m_Bounds);
            QuadTree <TestObject> bulkTree       = new QuadTree <TestObject>(m_Bounds);

            Random            random  = new Random(0);
            List <TestObject> objects = new List <TestObject>();

            for (int i = 0; i < 500; i++)
            {
                objects.Add(new TestObject(
                                new Vector2f((float)random.NextDouble(), (float)random.NextDouble()) * 1000));
                individualTree.Add(objects[objects.Count - 1]);
                bulkTree.Add(objects[objects.Count - 1]);
                individualTree.Update();
            }

            bulkTree.Update();

            List <FloatRect> regions1 = new List <FloatRect>();
            List <FloatRect> regions2 = new List <FloatRect>();

            individualTree.GetAllRegions(regions1);
            bulkTree.GetAllRegions(regions2);

            HashSet <FloatRect> remaining = new HashSet <FloatRect>(regions1);

            remaining.ExceptWith(regions2);

            Assert.AreEqual(0, remaining.Count);
        }
コード例 #5
0
ファイル: World.cs プロジェクト: GhostYiL/OgarII-CSharp
 public void UpdateCell(Cell cell)
 {
     cell.range.X      = cell.X;
     cell.range.Y      = cell.Y;
     cell.range.Width  = cell.Size;
     cell.range.Height = cell.Size;
     finder.Update(cell);
 }
コード例 #6
0
        public void InvalidObjectPositionTest()
        {
            var tree = new QuadTree <TestObject>(m_Bounds);

            tree.Add(new TestObject(-10, -10));
            tree.Add(new TestObject(10, 10));

            AssertThrows <Exception>(() => tree.Update());
        }
コード例 #7
0
    private void Update()
    {
        if (quadtree == null)
        {
            return;
        }

        quadtree.Update(camRoot.position, false);
        // quadtree.DrawDebugLines();
    }
コード例 #8
0
        public void GetClosestObjectTest()
        {
            QuadTree <TestObject> tree = new QuadTree <TestObject>(m_Bounds);

            SpacePartitionerTests.GetClosestObjectTest(tree);

            // Now execute tests that will hit all branches of
            // NearestNeighbor search method

            tree.Clear();
            tree.Add(new TestObject(488, 499));
            tree.Add(new TestObject(508, 499));
            tree.Add(new TestObject(496, 501));
            tree.Add(new TestObject(501, 501));
            tree.Update();
            tree.GetClosestObject(new Vector2f(499, 499), 5);

            tree.Clear();
            tree.Add(new TestObject(492, 499));
            tree.Add(new TestObject(512, 499));
            tree.Add(new TestObject(499, 501));
            tree.Add(new TestObject(504, 501));
            tree.Update();
            tree.GetClosestObject(new Vector2f(501, 499), 5);

            tree.Clear();
            tree.Add(new TestObject(496, 499));
            tree.Add(new TestObject(501, 499));
            tree.Add(new TestObject(488, 501));
            tree.Add(new TestObject(508, 501));
            tree.Update();
            tree.GetClosestObject(new Vector2f(499, 501), 5);

            tree.Clear();
            tree.Add(new TestObject(499, 499));
            tree.Add(new TestObject(504, 499));
            tree.Add(new TestObject(492, 501));
            tree.Add(new TestObject(512, 501));
            tree.Update();
            tree.GetClosestObject(new Vector2f(501, 501), 5);
        }
コード例 #9
0
        public void MovingObjectsTest()
        {
            TestObject[] objs =
            {
                new TestObject(250, 250),
                new TestObject(450, 450),
                new TestObject(750, 250),
                new TestObject(750, 750),
                new TestObject(250, 750)
            };

            QuadTree <TestObject> tree = new QuadTree <TestObject>(m_Bounds);

            foreach (var obj in objs)
            {
                tree.Add(obj);
            }

            List <FloatRect> regions = new List <FloatRect>();

            tree.Update();
            tree.GetAllRegions(regions);
            Assert.AreEqual(8, regions.Count);
            regions.Clear();

            objs[1].Position = new Vector2f(125, 125);
            tree.Update();
            tree.GetAllRegions(regions);
            Assert.AreEqual(8, regions.Count);
            regions.Clear();

            objs[0].Position = new Vector2f(675, 675);
            tree.Remove(objs[0]);
            tree.Update();
            tree.GetAllRegions(regions);
            Assert.AreEqual(7, regions.Count);
            regions.Clear();
        }
コード例 #10
0
        public void Setup()
        {
            m_Tree    = new QuadTree <TestObject>(new FloatRect(0, 0, 100, 100));
            m_Objects = new List <TestObject>(NumObjects);

            for (int i = 0; i < NumObjects; i++)
            {
                var obj = new TestObject(RandomPosition());
                m_Objects.Add(obj);
                m_Tree.Add(obj);
            }

            m_Tree.Update();
        }
コード例 #11
0
        public void EnumerationTests()
        {
            var tree = new QuadTree <TestObject>(m_Bounds);

            var one   = new TestObject(1, 1);
            var two   = new TestObject(2, 2);
            var three = new TestObject(3, 3);

            tree.Add(one);
            tree.Add(two);
            tree.Add(three);

            tree.Update();

            HashSet <TestObject> enumerated = new HashSet <TestObject>(tree);

            Assert.IsTrue(enumerated.Contains(one));
            Assert.IsTrue(enumerated.Contains(two));
            Assert.IsTrue(enumerated.Contains(three));
            Assert.AreEqual(3, enumerated.Count);
        }
コード例 #12
0
ファイル: Game1.cs プロジェクト: elkorn/Tanks3DFPP
 private void MenuOnGameComponentsReady(object sender, EventArgs eventArgs)
 {
     terrain.Update(this.camera);
 }
コード例 #13
0
 internal void BoundsChanged(Segment segment)
 {
     segments.Update(segment);
 }
コード例 #14
0
 internal void BoundsChanged(Node node)
 {
     nodes.Update(node);
 }