Game Development Community

How to find objects within a certain distance of a point?

by Alex Stittle · in Torque X 3D · 01/21/2009 (7:21 pm) · 5 replies

For TX3D, is there a way to find all objects in a given distance from a given position?

Basically, something similiar to the 2D method T2DSceneGraph.Instance.FindObjects

#1
01/23/2009 (12:02 am)
I did find something but it doesn't have very much information. Seems like documentation for TX3D might be incomplete.
docs.garagegames.com/torquex/official/content/documentation/TorqueX%203D/Referen...
#2
01/23/2009 (1:46 pm)
Thanks for the find. I tried the following but I didn't get any ResultList, it is always null. Admittedly, I'm not too sure what I'm doing haha. Can anyone shed some light?

T3DSceneContainer sceneContainer = new T3DSceneContainer(_playerSceneComponent.SceneGraph);
            T3DSceneContainerQueryData queryData = new T3DSceneContainerQueryData();
            Vector3 min = Vector3.Add(_playerSceneComponent.Position, new Vector3(-100,-100,-100));
            Vector3 max = Vector3.Add(_playerSceneComponent.Position, new Vector3(100,100,100));
            queryData.WorldBox = new Box3F(min, max);                       
            
            sceneContainer.FindObjects(queryData);

            

            if (queryData.ResultList != null)
            {

#3
01/25/2009 (6:51 pm)
I would definitely be interested to know. Definitely could be useful for some things.
#4
02/04/2009 (6:31 pm)
So I decided to re-visit this today since it started to bug me not using it in my game. And man do I feel like a noob, I totally forgot that the FPS Demo has explosions in it!

So after looking through the code I found exactly what I was looking for.

Here it is in all it's simple glory:

// The sphere we want to check in the world for objects
SphereQueryData _sphereData = new SphereQueryData();
_sphereData.Radius = 2.0f;
_sphereData.Position = _playerSceneComponent.Position;
_sphereData.IgnoreObject = this.Owner;
 
// Scan the world using the RigidManager and populate the   
// results into our query               
if(_rigidComponent.RigidManager.CollisionScene.QuerySphere(_sphereData))
{
 // Loop through the results and do what we want
 for (int i = 0; i < _sphereData.ResultList.Count; i++)
 {                    
    ...
  }
}
#5
02/04/2009 (6:33 pm)
Nice! Thanks for looking into it. I'll definitely remember that when T3D is out.

Brian