[ODE] How to perform efficient ray-space collision detection?

Maciej Sawitus msawitus at gmail.com
Sun Apr 9 10:23:50 MST 2006


Thanks for reply,

Anyway it seems highly inefficient to implement basic ray-space  
intersection using ODE, doesn't it?

Testing against closest only geometry would be much better. Using hash  
space - according to ODE's docs - it should be very fast, since this kind  
of space precalculates overlapping relations between all geometries within  
space.

Looping through all is kind of slow when there's whole lot of objects in  
the scene.

Maciej Sawitus

On Sun, 09 Apr 2006 17:31:18 +0200, Hampus Soderstrom <hampus at sxp.se>  
wrote:

> Hi Maciej,
>
> I think you are on the right track. Either you loop through all geoms  
> and do dCollide on them with the ray or you use dSpaceCollide with a  
> callback. If you think (and measure) that dSpaceCollide is too slow you  
> can add collide bits to the geoms to remove unnecesary collisions.
>
> If you go with dSpaceCollide why don't you use the the callback you  
> already have instead of a special "ray callback"?
>
> cheers
>
> /Hampa
> toribash.com
>
> 9 apr 2006 kl. 20.05 skrev Maciej Sawitus:
>
>> 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
>> _______________________________________________
>> ODE mailing list
>> ODE at q12.org
>> http://q12.org/mailman/listinfo/ode
>>
>>


More information about the ODE mailing list