Edit: Updated design to avoid memory allocations inside user app.
The current API does not use structures. So I'll not introduce them
My suggestion will achieve the same thing:
Code:
int castRay(NodeHandle node,
float ox, float oy, float oz,
float dx, float dy, float dz,
int flags,
int numNearest);
flags:
UNSORTED - do not sort result list (may be faster, default is sorted)
(more? depending on getCastRayResults implementation here can be determined which information should be calculated)
numNearest: if == 0 return all intersecting nodes; if != 0 and UNSORTED was specified, it is undefined which n nodes are included in the result
return value: number of intersections found
Code:
bool getCastRayResults(int index,
NodeHandle *node,
float *distance,
float *intersection);
index: result index in range [0, result of castRay)
node: NodeHandle or NULL
distance: float or NULL
intersection: float[3] or NULL
return value: true on success, otherwise false (really needed? as long as the index is valid, this call should succeed always)
Code:
void clearCastRayResults();
releases internal memory. Automatically called by castRay.
Sample use case for all intersections:
Code:
int num = castRay(startNode, ox, oy, oz, dx, dy, dz, 0, 0)
for(int i; i < num; ++i)
{
NodeHandle node;
float distance;
float intersection[3];
getCastRayResults(i, &node, &distance, intersection);
// do something with the result
// ..
}
clearCastRayResult();
Sample use case for only nearest intersection:
Code:
if(castRay(startNode, ox, oy, oz, dx, dy, dz, 0, 1))
{
NodeHandle node;
float distance;
float intersection[3];
getCastRayResult(0, &node, &distance, intersection);
// do something with result
// ...
}
clearCastRayResult();
In order to avoid duplicating code with picking replace Horde3DUtils::pick with a function that returns the ray origin and direction. Then the user can do the ray cast as usual.