Manifolds num ok but no contact except near the margin.

User avatar
Narann
Posts: 7
Joined: Sun Feb 02, 2014 5:57 pm

Manifolds num ok but no contact except near the margin.

Post by Narann »

I just find something weird that took me hours to solve so I share my story here to maybe help futur peoples.

I was setting my btCollisionObject position this way:

Code: Select all

btTransform world_transform = btTransform();
btVector3 pos = btVector3();
pos.setX( myPlayer->feet_position().X );
pos.setY( myPlayer->feet_position().Y );
pos.setZ( myPlayer->feet_position().Z );
world_transform.setOrigin( pos );
m_player_collider_objects[ i ]->setWorldTransform( world_transform );
The code was compiling well but their was a strange behavior: The Manifold detections (getNumManifolds) was fine but their was contact (getNumContacts) only if the two shape was near 0.04 from each other. What ever was the shape and the size (two sphere of radius 10 have to be near 0.04 from each other to make getNumContacts() return more than zero.

After few code digging I've change the piece of code above to this:

Code: Select all

m_player_collider_objects[ i ]->getWorldTransform().setOrigin( btVector3( myPlayer->feet_position().X,
                                                            myPlayer->feet_position().Y,
                                                            myPlayer->feet_position().Z) );
And it work now even if this code look similar to the above one.

If there is nothing wrong with my first piece of code (I don't see anything actually bad with it), I would suggest a unit test (if there is) because I think it's a bug.

Any word about this? Do you want I log this in the github or it's normal?
User avatar
Narann
Posts: 7
Joined: Sun Feb 02, 2014 5:57 pm

Re: Manifolds num ok but no contact except near the margin.

Post by Narann »

Should I open a bug for this? :)
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Manifolds num ok but no contact except near the margin.

Post by Basroil »

Did you try setting margins to zero? The 0.04 value sounds like you're just getting normal results and misinterpreting the margin for an actual issue.
User avatar
Narann
Posts: 7
Joined: Sun Feb 02, 2014 5:57 pm

Re: Manifolds num ok but no contact except near the margin.

Post by Narann »

Reading again, I realized I've bad explained. Sorry for that. :)

What ever the margin value is (zero, one, ten, etc...), results were the same:

Bullet was able to detect manifolds intersections correctly but unable to detect collisions between spheres until their centers (origin) distance was less that 0.04. And this, what ever the sphere size or margin size was.

And this for sphere and capsule (didn't test other shapes).

The only way to make everything work was to set the origin with the second approach. This two codes are intent to do the same right?

Code: Select all

btTransform world_transform = btTransform();
btVector3 pos = btVector3();
pos.setX( myPlayer->feet_position().X );
pos.setY( myPlayer->feet_position().Y );
pos.setZ( myPlayer->feet_position().Z );
world_transform.setOrigin( pos );
m_player_collider_objects[ i ]->setWorldTransform( world_transform );
And:

Code: Select all

m_player_collider_objects[ i ]->getWorldTransform().setOrigin( btVector3( myPlayer->feet_position().X,
                                                            myPlayer->feet_position().Y,
                                                            myPlayer->feet_position().Z) );
But, in my case, just changing the first to the second make everything work as expect. This is why I through it's a bug. :)
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: Manifolds num ok but no contact except near the margin.

Post by c6burns »

Those two code snippets are clearly not doing the same thing. If you initialized the transform in the first snippet like this, then they would be:

Code: Select all

btTransform world_transform(m_player_collider_objects[ i ]->getWorldTransform());
The first snippet is clearing out the rotation. The second is preserving it. Not sure that matters in your case, just pointing out they aren't the same.
User avatar
Narann
Posts: 7
Joined: Sun Feb 02, 2014 5:57 pm

Re: Manifolds num ok but no contact except near the margin.

Post by Narann »

c6burns wrote:The first snippet is clearing out the rotation. The second is preserving it. Not sure that matters in your case, just pointing out they aren't the same.
You are right on this point (and thanks for notice it), but as you guess, there was no rotation stuff needed in my case. The reaction is still weird. :?