Exemplo n.º 1
0
    public int AddProxy(ref FixtureProxy proxy)
    {
        int proxyID = _currID++;

        proxy.ProxyId = proxyID;
        AABB aabb = Fatten(ref proxy.AABB);
        Element <FixtureProxy> qtnode = new Element <FixtureProxy>(proxy, aabb);

        _idRegister.Add(proxyID, qtnode);
        _quadTree.AddNode(qtnode);

        return(proxyID);
    }
Exemplo n.º 2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            Texture2D px   = Content.Load <Texture2D>("pixel");
            Texture2D ball = Content.Load <Texture2D>("ball");

            GraphicsUtils.Load(spriteBatch, px, ball);

            Objs = new List <Object>();
            QT   = new QuadTree <Object>(new Region(0, graphics.PreferredBackBufferWidth, 0, graphics.PreferredBackBufferHeight), 10, 10);

            printTree <Object>(QT, 0);


            for (int i = 0; i < 10000; i++)
            {
                var ob = new Object(getRandRegion());
                QT.AddNode(ob);
                Objs.Add(ob);
            }

            var start = DateTime.Now.Ticks; //time the query

            for (int i = 0; i < 1000; i++)
            {
                QT.Query(new Region(0, 50, 0, 50));
            }
            var end = DateTime.Now.Ticks;

            Console.WriteLine("QUERY TOOK " + (end - start).ToString() + " TICKS");
        }
Exemplo n.º 3
0
                void CreateChildNode(ref QuadTree tree, double desiredSpeed, double angle)
                {
                    var newPosition = new Vector2D(Math.Cos(angle) * desiredSpeed_, Math.Sin(angle) * desiredSpeed_) + position_;

                    var newNode = new MovementNode(newPosition, angle, desiredSpeed, goal_, depth_ + 1);

                    if (tree.AddNode(newNode))
                    {
                        children_.Add(newNode);
                    }
                }
Exemplo n.º 4
0
        void frame_KeyUp(Element sender, KeyEventArgs e)
        {
            Size winSize = (Size)DefaultSettings.Settings["WindowSize"];

            switch (e.InterestingKeys[0])
            {
            case Keys.Z:
                for (int i = 0; i < 1000; i++)
                {
                    var ob = new Object(getRandRegion(winSize));
                    QT.AddNode(ob);
                    Objs.Add(ob);
                }

                break;

            case Keys.R:
                for (int i = 0; i < 50; i++)
                {
                    var ob = new Object(getRandRegion(winSize));
                    QT.AddNode(ob);
                    Objs.Add(ob);
                }

                break;

            case Keys.Space:
                Objs.Clear();
                QT = new QuadTree <Object>(new Region(0, winSize.Width, 0, winSize.Height), 1, 100);
                break;

            default:
                break;
            }

            Console.WriteLine(Objs.Count + " objects");
        }
Exemplo n.º 5
0
 public void AddNode(NodeBase node)
 {
     quadTree.AddNode(node);
     Invalidate();
 }
Exemplo n.º 6
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            if (Mouse.GetState().LeftButton == ButtonState.Pressed && prevstateL == ButtonState.Released)
            {
                var x  = Mouse.GetState().X;
                var y  = Mouse.GetState().Y;
                var ob = new Object(new Region(x - 10, x + 10, y - 10, y + 10));
                Objs.Add(ob);
                QT.AddNode(ob);
                //printTree<Object>(QT, 0);
                Console.WriteLine(Objs.Count + " objects");
            }
            if (Mouse.GetState().RightButton == ButtonState.Pressed && prevstateR == ButtonState.Released) //down
            {
                qactive = true;
                Objs.ForEach(n => n.Flagged = false);

                query      = new Region();
                query.XMin = Mouse.GetState().X;
                query.YMin = Mouse.GetState().Y;
            }
            if (Mouse.GetState().RightButton == ButtonState.Released && prevstateR == ButtonState.Pressed) //up
            {
                qactive = false;

                query.FixBoundOrder();

                var start = DateTime.Now.Ticks; //time the query
                var hits  = QT.Query(query);
                var end   = DateTime.Now.Ticks;

                Console.WriteLine("QUERY TOOK " + (end - start).ToString() + " TICKS");

                hits.ForEach(n => n.Flagged = true);
                Console.WriteLine("selected: " + hits.Count + " objects");
            }
            prevstateL = Mouse.GetState().LeftButton;
            prevstateR = Mouse.GetState().RightButton;


            query.XMax = Mouse.GetState().X;
            query.YMax = Mouse.GetState().Y;


            var kcurr = Keyboard.GetState().GetPressedKeys();

            foreach (var k in kcurr)
            {
                if (!kold.Contains(k))
                {
                    //
                    //Key 'k' newly pressed down. Process here.
                    //
                    switch (k)
                    {
                    case Keys.Z:
                        for (int i = 0; i < 1000; i++)
                        {
                            var ob = new Object(getRandRegion());
                            QT.AddNode(ob);
                            Objs.Add(ob);
                        }

                        break;

                    case Keys.R:
                        for (int i = 0; i < 50; i++)
                        {
                            var ob = new Object(getRandRegion());
                            QT.AddNode(ob);
                            Objs.Add(ob);
                        }

                        break;

                    case Keys.Space:
                        Objs.Clear();
                        QT = new QuadTree <Object>(new Region(0, graphics.PreferredBackBufferWidth, 0, graphics.PreferredBackBufferHeight), 1, 100);
                        break;

                    default:
                        break;
                    }

                    //printTree<Object>(QT, 0);
                    Console.WriteLine(Objs.Count + " objects");
                }
            }
            kold = kcurr;


            base.Update(gameTime);
        }
Exemplo n.º 7
0
 public static QuadTree<IRigidBody> GenerateQT(List<IRigidBody> bodies, int maxbucket)
 {
     var QT = new QuadTree<IRigidBody>(MAXSPAN, maxbucket, 10);
     bodies.ForEach(b => QT.AddNode(b));
     return QT;
 }