Multiple call of NewtonContactsProcess callback

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Multiple call of NewtonContactsProcess callback

Postby Olee » Thu Jul 29, 2010 3:37 pm

Hi,

I think I found a bug in Newton when using the NewtonContactsProcess in combination with ContinuousCollisionMode and a complex collision such as collision-tree.

I'm creating a game-engine with newton and I've made some projectiles (small spheres) which fly at high-speed with ContinuousCollisionMode swtiched on.

For every Newton-Material in the world I registered a general callback, which handles some stuff such as playing a collision sound.

While I was testing my world and shooting around some projectiles I found a lot of areas where with one hit of the projectil on the ground many sounds were played at once.

After some debugging I found out that Newton calls the NewtonContactsProcess-callback numerous times with the SAME CollisionJoint parameter and the same data for position, normal, ... of for the contacts (of NewtonContactJointGetFirstContact).

This happens often when I shoot on the ground with a small angle and when there are more polygons forming a simple floor.

I think I will add a graphic of the problem soon.

EDIT:
I just found out that this also happens at low speed, but ONLY WITH CONTINIOUS-COLLISION-MODE SWITCHED ON.

Björn Zeutzheim
Olee
 
Posts: 11
Joined: Sun Jul 04, 2010 12:55 pm

Re: Multiple call of NewtonContactsProcess callback

Postby Julio Jerez » Thu Jul 29, 2010 4:36 pm

Olee wrote:While I was testing my world and shooting around some projectiles I found a lot of areas where with one hit of the projectil on the ground many sounds were played at once.

After some debugging I found out that Newton calls the NewtonContactsProcess-callback numerous times with the SAME CollisionJoint parameter and the same data for position, normal, ... of for the contacts (of NewtonContactJointGetFirstContact).

This happens often when I shoot on the ground with a small angle and when there are more polygons forming a simple floor.

EDIT:
I just found out that this also happens at low speed, but ONLY WITH CONTINIOUS-COLLISION-MODE SWITCHED ON.
Björn Zeutzheim

this is normal, when continue collision is on, and you have a body that move at hight speed,
or at a peed that in one timestep will generate a large penetration on teh colliding bodies, the engine do no integrate the body and the normal time step,
because that leads to contacts generation outside the sphere of the body, which also lead to very bad contact resolution.

say for example you have a small box with Continue collision on, and you move at speed that will make the body of the Box travel more than half the smallest with of the Box.
Say the Box will hit a wall on and edge.
the continue collision code determine that the contact point will be on the edge, but the edge is way outside the Box Shape.
If a contact pair like that is sent to the solve, the contact will generate unrealistic implsive torques that will make the Box move in strange ways,
some time even explosion. This is how 1.53 worked.

In 2.0 the engine save the state on the bodies and all the bodies that are in contact,
and the one in cont wit with other (the island), then is find the bodies with the world Time/space displacement and calculate the conservative time step.
until teh body react teh closest contact. Then is determine how many steps it need to execute to complete the time application step.
then is discard the contacts, and in a loop it advance the island by this smaler conservative time step,
each time calculating continue collision at the end of the smaller time step, solving the contacts and integrating the island.

the calculation is very efficient because the call to collision is seeded with the contacts that are already calculated,
and in the calculation determine that no there there are not more contact in the path of the body then is does the rest for the time in one iteration.

in the Box example in the box CC determine that it needs 10 steps then, in a loop is does this.
-abcance by convervatibe step, and recalculate contacts, this now make the contacts closer to the collision shape.
-the contacts are the same at before but the time is lot smaller, so the teh solver will calculate more accurate impulse,
-the contct are solve and the imuplse are applyed to each body,
-in the next step, continue collision is called again to get new contacts,
-if the Box collide again, the the loop repeacts until no more time is left
but if the box do not see a contacts the teh loop is terminated, and teh bodies are advanced by the time leftover.

this is why you see more than one call to contact call back when CC is on.
notice that this does not slow the entire when a body move at hight speed since only
that body and the bodies invlve in the collition are subsample in the calculation.



you can solve the problem of playing duplicate sounds by instead of playing the sound from the callback, you queue the sound, and the you play then the after the call to NewtonUpdate.
This is better anyway, because if you enable multithread, you may run in thread synchronization problem the may require critical section that may slow down the engine or worse race generate condition.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Multiple call of NewtonContactsProcess callback

Postby Olee » Fri Jul 30, 2010 3:10 pm

But there are more weird things:

The first is that even with very low speed and CC on, he Problem with the multiple calls of the callback still happens and the other thing is that the
collision reaction is sometimes (very) incorrect (this also happens at low-speed with CC).

For now I have a good workaround for this Problem:

I store the collision-jointof the callback and when the callback gets calld the second time I just check if it was already called with the same collision-joint.

This works really good for now.
Olee
 
Posts: 11
Joined: Sun Jul 04, 2010 12:55 pm

Re: Multiple call of NewtonContactsProcess callback

Postby Julio Jerez » Fri Jul 30, 2010 3:32 pm

The collision should be perfect at all time. That is why it does the subsampling of the time step.
at low speed the wil happen is the object is too small.
hwo small is the object?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Multiple call of NewtonContactsProcess callback

Postby Olee » Fri Jul 30, 2010 4:44 pm

The Problem appears if I just shoot on that floor.
But this floor is made of at last more than 6 polygons in that area.
Image
Uploaded with ImageShack.us

The Object is small (0.075 radius), but the Problem still appears if it's moving with 8 units/sec (with 60 Steps/sec this would be 0.13 units/sec) which
is not that fast.
Olee
 
Posts: 11
Joined: Sun Jul 04, 2010 12:55 pm

Re: Multiple call of NewtonContactsProcess callback

Postby Julio Jerez » Fri Jul 30, 2010 4:58 pm

Olee wrote:The Object is small (0.075 radius), but the Problem still appears if it's moving with 8 units/sec (with 60 Steps/sec this would be 0.13 units/sec) which
is not that fast.


the caculation indicate that iti should do subsampling, it could not be more clear.
the ball is 0.075 in radio, that means diameter (crss section) = 0.15 of a unit
if the velocity is 8 units/sec at 60 fps it travel 0.13 of a unit each timestep.

teh engien check that 0.13 is larget tha half the cross setion whist is 0.075, therfore the engine subsampel the island.
if it does not do that and then ball hit a bump or a wall, it will go right trough the first polygon it hits.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Multiple call of NewtonContactsProcess callback

Postby Olee » Fri Jul 30, 2010 5:12 pm

But still the result of the collision is wrong.

It doesn't bother me any more that there are multiple calls of the callback each frame, but the wrong collision is still a problem.

Sometimes when a ball collides with the ground it ends up bumpung vertically up and down on the surface until it gets deleted,
which is one of the weird results I get.
I think I will check my geometry again as a next step.
Maybe there is the reason of the problem.
Olee
 
Posts: 11
Joined: Sun Jul 04, 2010 12:55 pm

Re: Multiple call of NewtonContactsProcess callback

Postby Olee » Fri Jul 30, 2010 5:19 pm

Polygonal view of the geometry (above the floor)
Image

Below the floor
Image
Uploaded with ImageShack.us

I think the problem appears around the polygon-edge on the floor (where I shot at in the picture in post #5)
Olee
 
Posts: 11
Joined: Sun Jul 04, 2010 12:55 pm

Re: Multiple call of NewtonContactsProcess callback

Postby Julio Jerez » Fri Jul 30, 2010 5:22 pm

Ha that may be a bug I am looking for some time.

The engine have special handling for when and objec go across and edge, but some time there are bugs where the edge cannot be match with adjacent.
people have reported that in the pass but noone has produce a demo that I can use to test the bug. can you post a demo? so tha I can see why this happens?

the ball should move perfectly smooth over the terrain, no bumps no jumps under any circunstance when everything is correct.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Multiple call of NewtonContactsProcess callback

Postby Olee » Fri Jul 30, 2010 6:45 pm

I will try to create a demo in the next time so please be patient.

The problem is that my engine is still a secret project and closed source so I want to adjust things a bit before that :wink:
Olee
 
Posts: 11
Joined: Sun Jul 04, 2010 12:55 pm

Re: Multiple call of NewtonContactsProcess callback

Postby Stucuk » Fri Jul 30, 2010 7:07 pm

You can send a demo to Julio as a Private Message. That way only he could ever download it.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: Multiple call of NewtonContactsProcess callback

Postby Julio Jerez » Fri Jul 30, 2010 7:23 pm

all you need to do is a demo tha link to the newton DLL. I do not need the source, just the binary.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Multiple call of NewtonContactsProcess callback

Postby Olee » Tue Aug 03, 2010 2:04 pm

I've sent you a link to a copy of the game in which you can see the problem.

I hope this helps you fixing the bug.
Olee
 
Posts: 11
Joined: Sun Jul 04, 2010 12:55 pm

Re: Multiple call of NewtonContactsProcess callback

Postby Julio Jerez » Tue Aug 03, 2010 2:44 pm

Ha thank you I will debug it, give a day or two, because I have few thing in the list first.

but I was looking for a test liek this for some time.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 10 guests