Lots of moving objects, quadtree, scenemanager

Hi,



I am a beginner to jME so I need a few pointers…



Let's say I want to display a lot of moving asteroids. I decided to use quad tree for spatial ordering. The player just can move in 2 dimensions, so no need for an octree. Since jME doesn't support quadtrees yet, I want to implement my own. I know how a quadtree works, but I don't how to implement it with the scenetree jME offers. For example if I want to check if an asteroid is still in a node, I would test it's own bounding volume against the one of the node… but this doesn't work so well, because jME's scenetree seems to modify the bounding volumes all the time…



so, any ideas? thanks in advance!

you shouldn’t test against the bounding volume of the node. you’ll probably need some data structure to support your quad tree if you are going to use sparse quadtrees.

taking a look at mr coder’s quadtree vegetation might help.

still, if you have moving objects, you probably don’t want to use sparse quadtrees.

sfera said:

still, if you have moving objects, you probably don't want to use sparse quadtrees.

Yes, I know.. a quadtree is surely not the best thing to do here.. but I see it as a test. What kind of datastructure would you suggest?

sfera said:

you shouldn't test against the bounding volume of the node. you'll probably need some data structure to support your quad tree if you are going to use sparse quadtrees.
taking a look at mr coder's quadtree vegetation might help.

Thanks for the link! I'm not sure if I understand the sourcecode fully.. The author checks his own bounding geometry against a camera and overrides the draw method, so that the scenetree can't compute these things itself? And to get the correct renderstates for the Objects he adds them to the quadtree node once?

Why is the auther using a second camera? Is it just because of the contest? Because they needed a special field of view?

you probably don't need anything very complex if your objects move only on a plane. a tree maybe? :stuck_out_tongue:


paul said:


The author checks his own bounding geometry against a camera and overrides the draw method, so that the scenetree can't compute these things itself? And to get the correct renderstates for the Objects he adds them to the quadtree node once?

Why is the auther using a second camera? Is it just because of the contest? Because they needed a special field of view?


well, the quadtree vegetation implements a sparse quadtree (and so does TerrainPage for example) . if it is supposed to be a quadtree you can't assume the scene graph will do everything for you. the scene graph is more general, while a quadtree is a bit more specialized. the additional camera is used for the checks inside of the quadtree (otherwise the current camera's state would be altered).

the additional camera is used for the checks inside of the quadtree (otherwise the current camera's state would be altered).


Does it need to be a camera to do this or 6 planes representing the frustrum ???

no it doesn't have to be a camera. it's just that the camera code does all the stuff needed to do those checks. of course you could reimplement all that and call it QuadTreeFrustrumChecker. :stuck_out_tongue: you'll just end up with duplicate code.

i used a simple grid once.

there is a list of asteroids: List<Asteroid>

for every asteroid, you do:

space[currentAsteroid.getX()/space.lenth][currentAsteroid.getY()/space.lenth] //assuming x & y length of your world are equal



space is an [][] of List<Asteroids>

now you can iterate over all asteroids being in the same grid and minimize the bounding checks.

for asteroids being on borders between grids, add them to both/all three/all four.



if it's a 2d game, it's also easy to determine which grids are currently visible.