[ODE] Re: nearCallback

Andrzej Szombierski qq at kuku.eu.org
Sat Nov 13 13:24:20 MST 2004

On Sat, 13 Nov 2004, Daniel Marbach wrote:

> 3. What is a good value for the maximum number of contact points in the
> nearCallback? I think there was a discussion on this but I don't find it anymore
> in the archives. I remember that somebody said that it is good to generate a lot
> of contacts (how many exactly? 10? 100?) and to sort them, creating contact
> joints only for the most important ones. But which ones are important? Can't I
> expect ODE to give me 'important' ones if I request very few (e.g. 3)? If
> somebody could post / send me the code of this 'sorting' function that would be
> very nice.

I use something like this:

static bool operator< (const dContact & a, const dContact & b)
{ return a.geom.depth > b.geom.depth; }

[ ... and in near_callback ... ]
const int max_nc = 100;
eContact contact[max_nc];

int nc=dCollide(ga, gb, max_nc, &contact[0].geom, sizeof(eContact));
int max_c = 5;

if(nc > max_c){
	std::nth_element(contact, contact+max_c, contact+nc);
        nc = max_c;

for(int i=0;i<nc;i++){ 

This requests a lot of contacts (100 was always enough in my case) and 
then uses the "deepest" five (as defined by operator< ). Thanks to 
std::nth_element, it all happens in O(n) time :)

The max_c parameter could be adjusted depending on the geom types - 
sphere<->mesh seems much less demanding than box<->mesh.

:: Andrzej Szombierski :: qq at kuku.eu.org :: http://kuku.eu.org ::
:: anszom at bezkitu.com  :: radio bez kitu :: http://bezkitu.com ::

More information about the ODE mailing list