Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


implementing a generic quad tree.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 freeworld   Members   -  Reputation: 325

Like
0Likes
Like

Posted 21 February 2013 - 02:39 PM

As a learning experience im putting together a templated quad tree as a container. But theres a few things im curious about and google on my phone is being a nuisance.

Im storing objects by there center and forcing them to only one quad at a time. My tree will be populated quite heavily with a limit to the amount per quad. My biggest concern lies in moving the objects. This will probably be trivial... 100 or more. Per frame with that number being very dynamic aswell as my tree possible being 20-30 + nodes deep.

The way im doing it right now is the owner of the objects will remove them from the tree then reinsert them every time it moves.

But all morning I was thinking maybe I should give a member function to my nodes to move an object. So I could do it logically. Such as no need to reinsert if it still is in the current node.
[ dev journal ]
[ current projects' videos ]
[ Zolo Project ]
I'm not mean, I just like to get to the point.

Sponsor:

#2 frob   Moderators   -  Reputation: 22218

Like
1Likes
Like

Posted 21 February 2013 - 04:04 PM

I think you would be better served with a loose quadtree, which allows for a bigger range of motion because each quadtree node has motion on it.


As for your tree being "20-30+ nodes deep", you must either have an amazingly big world or a extremely tiny subdivision space.

At 1 meter per cell, a 20 deep quadtree will cover an area of just over one million meters by one million meters. Roughly the entire land mass of New York City at a one-meter-per-cell ratio.

A 30 deep quadtree will cover over the entire state of California, or the entire state of Texas, at one millimeter per cell accuracy.


For our complete 10km square world we have a depth 10 loose quadtree at 1 cell per meter.

Edited by frob, 21 February 2013 - 04:04 PM.

Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I write about assorted stuff.


#3 freeworld   Members   -  Reputation: 325

Like
0Likes
Like

Posted 21 February 2013 - 04:12 PM

I think you would be better served with a loose quadtree, which allows for a bigger range of motion because each quadtree node has motion on it.


As for your tree being "20-30+ nodes deep", you must either have an amazingly big world or a extremely tiny subdivision space.

At 1 meter per cell, a 20 deep quadtree will cover an area of just over one million meters by one million meters. Roughly the entire land mass of New York City at a one-meter-per-cell ratio.

A 30 deep quadtree will cover over the entire state of California, or the entire state of Texas, at one millimeter per cell accuracy.


For our complete 10km square world we have a depth 10 loose quadtree at 1 cell per meter.

 

It came out right in my head.... I meant it could be checking that many nodes each time, (5 - 7 nodes deep multiplied by the 4 nodes each might possibly check). I'm using the quad tree for several objects in my game, all but one are very static so I don't have to worry about those.

 

One container stores all the aI-creatures though, and I use a system similar to diablo where only awake creatures are ever updated, and any creatures outside a certain range from the player are automatically considered a sleep. So in theory I will only ever move creatures in close range to the player. But these objects can move from one side of the world to the other instantly but that shouldn't happen often.

 

The other big question I forgot to ask, is an easy way to find all the nodes that border a node?


Edited by freeworld, 21 February 2013 - 04:13 PM.

[ dev journal ]
[ current projects' videos ]
[ Zolo Project ]
I'm not mean, I just like to get to the point.

#4 larspensjo   Members   -  Reputation: 1557

Like
0Likes
Like

Posted 22 February 2013 - 05:16 AM

I'm using the quad tree for several objects in my game, all but one are very static so I don't have to worry about those.

 

If you need to detect collisions between any two of these objects, then this may be a good choice. However, otherwise consider using more than one quad tree. If there is only one of the objects that isn't static, then it may be an advantage to have a quad tree of its own for this object type.

 

...Such as no need to reinsert if it still is in the current node.

 

Are you sure you need this? It is a performance optimization, but do you have measurements that show this is needed?

 

Using more than one quadtree is a simple solution that can also improve performance.


Current project: Ephenation.
Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS