Querying for Nearby Objects


For the simulation I am writing, one of the things I need to be able to test is find units within a certain radius of a given unit. I was wondering if there was an easy way to query the scene graph for such queries, or do people normally maintain a separate location graph to handle such queries?.

Also was wondering how people handle such things in general? Do people maintain two graphs, one the actual graph that contains all the units in the game and one graph (the render graph ) which gets populated every frame?

I would think of something like this

-> an OctTree based scene graph to do quick radius checks
-> Every frame
-> Walk octTree and find nodes visible to the player
-> for all visible nodes add to render graph
-> render frame
-> clear render graph [ how would one do this, detach the nodes individually? ]

Any ideas on how to accomplish something similar without maintaining a separate graph?

using the good old collision system with spheres will do a good job, combined with an octree-structured scene graph.
using a collisionqueue you can directly get a list of nodes involved in the collision.

just in case you are thinking about implementing frustum-culling. panda does that by default already.

Its not collisions i am looking for. This is for the AI of an unit to be able to respond when certain units come into its visibility radius. So I want to be able to check for every unit if there are hostile units nearby.

Not looking to implement frustum culling. Just reducing the number of units I need to go through to find nearby units.

collision detection is not only good for lettings things collide.

using collision spheres you can get a list of all units within the sphere of node.(which is pretty much what you’r looking for as far as i can tell).

using the collision system panda will deal with all the distance calculations in c++ which is rather fast. + you dont need a seperate scene graph.

Oooh didn’t know i could get a list of units within a sphere using collision detection…Doh that makes it quite easy…Thanks a lot.