Game Development Community

spherical raycast? or equivilant?

by deepscratch · in Torque 3D Professional · 10/16/2011 (2:40 pm) · 5 replies

hi all,

is there a way to do a spherical raycast around the player?
or is there something that could give a similar result?

I need to know when the player is within a certain distance from certain objectTypes.
this is in source, not in script.

I am using a "gClientContainer.castRay" at the moment and it works for a straight ahead raycast, but, I need it to work in a full sphere around the player, in case he moves backwards or sideways or jumps, onto these objectTypes.

any ideas or suggestions on this?

thanks in advance

#1
10/16/2011 (2:58 pm)
initContainerRadiusSearch() in TScript or initRadiusSearch() in C++.
#2
10/17/2011 (8:28 pm)
Yes - was going to ask why you would spend the bandwidth doing all of those raycasts when you could just use a bounding sphere and check for intersection.
#3
10/22/2011 (2:54 pm)
thanks for the replies guys,

@Richard, I would like to use a bounding sphere, or even the box, but how would I go about it?

I am not a coder, per se,
but an example would get me far.

@Chris, unfortunately there are no code examples of initRadiusSearch(), only the script call, and this needs to be code based
#4
10/22/2011 (3:38 pm)
Not a problem. Incoming examples!

Let's say your player was at a location of (0, 0, 0) and you wanted to find all objects of type ShapeBaseObjectType within 10 units of the player. You also wanted to do this search on the server container (gServerContainer) rather than on the client container (gClientContainer).

const Point3F searchStartPoint(0.0f, 0.0f, 0.0f); // point within the world to perform the search
const F32 searchRadius = 10.0f // radius in world units to search

gServerContainer.initRadiusSearch(searchStartPoint, searchRadius, ShapeBaseObjectType);

The above code would fill a list with the objects found. To access the objects in this list, there are two methods available: SceneContainer::containerSearchNext() and SceneContainer::containerSearchNextObject(). containerSearchNext() returns object IDs and containerSearchNextObject() returns SceneObjects.

So, we've performed a radius search and have a list of objects within a 10 unit radius around the player. Here's how to iterate through the list:

U32 objectId = gServerContainer.containerSearchNext(); // returns 0 when the list is empty

while objectId != 0
{
    // do stuff with the objectId
    ...

    // grab the next objectId in the list (if available)
    objectId = gServerContainer.containerSearchNext();
}
#5
10/23/2011 (5:29 am)
thanks Chris,
does the job as advertized.