MogreNewt collision event

creyzee

28-08-2007 19:47:50

Is there any way to get a collision event between 2 bodies without materials?

Creating material pairs and derived classes from ContactCallback separately for each body is not the best way for me.

bleubleu

30-08-2007 06:02:00

Hi!

Sadly, I think that's the only way. If you dont use materials at all, you could create a pair between two "default" materials (See World.DefaultMaterialID) and create a class that derives from ContactCallback. That's pretty much what you are doing, except you dont create new materials.

Mat

creyzee

30-08-2007 10:49:59

Thanks, i didn't know about World.DefaultMaterialID , think i can use it.
So, in ContactCallback, UserBegin() called at collision first detection, UserProcess() calling while collision is being continious, and UserEnd() after collision stops. Is that right?

bleubleu

30-08-2007 23:54:31

Yup!

These are the only 3 methods you are allowed to override (virtual). For the 2 first ones (Begin and Process) you can return 0 to prevent the objects from colliding or 1 to let them collide.

In the UserProcess method, the properties of the ContactCallback objects will be filled in (ContactForce, ContactPosition, etc...) and you can use them to affect the behavior of the collision.

At any time within these methods, you can access "m_body0" and "m_body1" to get information about the 2 bodies that are colliding.

Have fun!

Mat

creyzee

02-09-2007 13:40:06

Thanks for help Mat.

Now, i'm trying to control collisions and have some new problems. So, i'm derived my collision class from ContactCallback, and rewrited User...() methods to see when they're being called. And what I see is:
Collision start
Collision process
Collision process
Collision process
Collision process
Collision process
Collision process
Collision end
Collision start
Collision process
Collision process
Collision process
Collision process
Collision process
Collision process
Collision end

So it's not like one continious collision, but as many separate collisions. And also, UserProcess() is called same number of times for each collision sequence, i really dont know why. :shock:
I use one TreeCollision body as floor, and a ConvexHull body falling onto it. I have tried to use primitives like box collisions, but result is the same.
And another strange issue is, when for example i have terrain which is TreeCollision body, and when another body goes into terrain's bounding box, but does not contact with terrain itself, i have repeated call UserStart()/UserEnd() without calling UserProcess().

So, is that all normal and i should only check UserProcess() in my app, while start/end are newton's internal, or something goes wrong and i have to fix it?

pitmodano12

07-09-2007 09:39:22

//This captures the collision event. Put code here to trigger actions on collision int userProcess() I guess now im gonna have to do it in mogrenewt

Sweenie

07-09-2007 12:49:27

From the Newton SDK docs...
When the AABB extend of the collision geometry of two bodies overlap, Newton collision system retrieves the material interaction that defines the behavior between the pair of bodies. The material interaction is collected from a database of materials, indexed by the material gruopID assigned to the bodies. If the material is tagged as non collidable, then no action is taken and the simulation continues. If the material is tagged as collidable, and a beginCallback was set for this material, then the beginCallback function is called. If the function *beginCallback* returns 0, no further action is taken for this material (this can be use to ignore the interaction under certain conditions). If the function *beginCallback* returns 1, Newton proceeds to calculate the array of contacts for the pair of colliding bodies. If the function processCallback was set, the application receives a callback for every contact found between the two colliding bodies. Here the application can perform fine grain control over the behavior of the collision system. For example, rejecting the contact, making the contact frictionless, applying special effects to the surface etc. After all contacts are processed and if the function endCallback was set, Newton calls endCallback. Here the application can collect information gathered during the contact-processing phase and provide some feedback to the player. A typical use for the material callback is to play sound effects. The application passes the address of structure in the userData along with three event function callbacks. When the function beginCallback is called by Newton, the application resets a variable say maximumImpactSpeed. Then for every call to the function processCallback, the application compares the impact speed for this contact with the value of maximumImpactSpeed, if the value is larger, then the application stores the new value along with the position, and any other quantity desired. When the application receives the call to endCallback the application plays a 3d sound based in the position and strength of the contact.

In short, you get a callback for each contact point being processed.