thunguyenphuoc
thunguyenphuoc

Reputation: 11

PhysX: collision onContact does not work

I'm using PhysX.NET (C# wrapper for PhysX) and I am trying to get a notification of collision between two spheres using onContact in SimulationEventCallBack.

I have created a new subclass for SimulationEventCallback and overridden the OnContact method so that it will give me a message when collision happens. I have then set the simulationEventCallback of the scene to an instance of my subclass. This does not work even though the two spheres (rigid dynamic) obviously collide. Below is my code:


// Creating subclass

public class robotCollision : SimulationEventCallback
    {
        public override void OnContact(ContactPairHeader pairHeader, ContactPair[] pairs)
        {
            base.OnContact(pairHeader, pairs);        
            Rhino.RhinoApp.Write("Contact!");
        }
     }

// Create scene

scene = engine.CreateScene(sceneDesc);
scene.SetSimulationEventCallback(myContactCallback,0);

Is there something else that needs to be considered? Any flags to be set? I am sorry if this is a very naive question, but I have worked on this for the whole day for something that seems to be quite simple and I can't wrap my head around it.

Thanks in advance.

Upvotes: 1

Views: 804

Answers (1)

ofir agranat
ofir agranat

Reputation: 90

I'm a PhysX C++ user so I would no mark this as a solution. In general, you need to define a contact between two actors using either PxSimulationFilterShader or PxSimulationFilterCallback. The later is a specific callback you need to implement, so I doubt you want to do that. A default PxSimulationFilterShader will be provided so no worries there.

In order for the filter shader to work, you must define the actors a collision group and mask. see PxSetGroup and PxSetGroupsMask. The group is just a number ID between 0-31. The mask is a 4 shorts (PxU16) bit set that defines "for each group, whom should I collide with". Now the group mask is a bit finicky.. The math behind is.. annoying... But you can implement your own collision filtering with a more simple one, using the input data in the group mask. There are samples on how to do so in the PhysX code and documentation. see Collision Filtering

Again, I'm a C++ answer, I'm sure there is something similar in the C# wrapper.

Upvotes: 1

Related Questions