[ODE] How to perform efficient ray-space collision detection?
Maciej Sawitus
msawitus at gmail.com
Sun Apr 9 06:05:27 MST 2006
Hi everyone,
How would you implement ray-space collision detection?
I expected there would be
dCollide(dSpaceID, dGeomID, ...) method
but there's not.
I can only perform collision detection between 2 geoms.
Below is my (not working) implementation of ray tracing (my cSpace class
encapsulated ODE's space). In short, I'm creating a "temporary" ray, add
it to space and now I'd like to intersect it with all other geometries in
the same space. Unfortunately it doesn't work, because it doesn't compile
;) - dCollide can't be given geom and space.
void cSpace::traceRay(const cVec3& start, const cVec3& end,
cRayTraceResult& result)
{
cVec3 direction = end - start;
const Float length = cVec3::length(direction);
direction = cVec3::normalize(direction);
dGeomID rayId = dCreateRay(SpaceId, length);
dGeomRaySet(rayId, start[0], start[1], start[2], direction[0],
direction[1], direction[2]);
dContact contact;
// !!! Doesn't compile !!!
const Int numContacts = dCollide(rayId, SpaceId, 1, &contact,
sizeof(dContact));
if (numContacts == 0)
{
result.Hit = false;
return;
}
result.Hit = true;
result.Depth = contact.geom.depth;
result.Normal = contact.geom.normal;
result.Position = contact.geom.pos;
result.Body = dGeomGetData(contact.geom.g2);
dGeomDestroy(rayId);
}
I know I could implement it other way, by adding ray to the space and
performing regular dSpaceCollide and supplying special "ray callback" to
it. But it would unnecessarily find all pairs of intersecting geometries
within my space, while I only want to intersect space with a ray.
I'd be very happy to hear from anyone who implemented ray-space
intersection.
Thanks in advance.
Maciej Sawitus
More information about the ODE
mailing list