Box2D Forums

It is currently Sat May 18, 2013 1:45 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sat Jun 23, 2012 5:33 am 
Offline

Joined: Thu Oct 27, 2011 11:36 am
Posts: 13
Hi,

i have made some research about this topic. I know how to create N bodies (the debris) from a single box body, put them
on screen and get a good effect.

Now i need to understand when the box should break. In the testbed i have found this code:
Code:
int32 count = contact->GetManifold()->pointCount;

float32 maxImpulse = 0.0f;
for (int32 i = 0; i < count; ++i)
{
   maxImpulse = b2Max(maxImpulse, impulse->normalImpulses[i]);
}

if (maxImpulse > 40.0f)
{
   // Flag the body for breaking.
   m_break = true;
}



I have tried to scale maxImpuse by the body mass to get more consistent results (that is, if i have two type of boxes, i would like
to assign them a strength factor (with values in a range between [0..1] or something similar).

I have tried some tests:

http://tinypic.com/player.php?v=24dv8&s=6


in the video, different runs of the same test are done. In the first one, no box breaks (when a box breaks, it simply disappear).
In the second and third run, the highest box fall on two boxes that both breaks, but the highest one is still solid.
It doesn't seems the correct result to me: the highest box too should break, but probably i am wrong and i am missing something here.

Am i on the right path? How you guys decide when a box (or, generally speaking, a body) should break due to collision?

Thank you
Luca


Top
 Profile  
 
PostPosted: Sat Jun 23, 2012 9:54 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1515
Location: Tokyo
Are you flagging both bodies of the collision for breaking, or just one?


Top
 Profile  
 
PostPosted: Sun Jun 24, 2012 4:34 am 
Offline

Joined: Thu Oct 27, 2011 11:36 am
Posts: 13
Hi, in the game editor i have a box entity having 5 instances spawned in the game.
The entity box is breakable, so the answer is yes: every instance of box is flagged to be breakable.

Maybe the fact that i use a threshold to decide when something breaks is the reason why
in the first run nothing breaks while in the second and third run is different.

I fail to understand why the highest box does not break. Maybe frame-rate drops (since i print
a lot of things and run in debug mode on) alter the simulation?


Top
 Profile  
 
PostPosted: Sun Jun 24, 2012 12:22 pm 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1515
Location: Tokyo
I meant "flag to break", not "flagged to be breakable".
When two boxes collide they are both subject to the same correcting impulse, so if they both have the same threshold then they should both be flagged to break, I would have expected.


Top
 Profile  
 
PostPosted: Mon Jun 25, 2012 3:42 am 
Offline

Joined: Thu Oct 27, 2011 11:36 am
Posts: 13
Hi irr_force,

i have printed some information and this is what i get:


scene configuration:

Code:
    4



   3
  2
0 1
--------

The floor is depicted by the line ------. The 0,1,..,4 are the boxes (two boxes on the floor (0,1), one (2) on the first two, another (3) on the box 2 and
finally the highest box (4).
I have printed only collisions with a 'normalized impulse strength' > 5 (that is, the max impulse is scaled by the body mass).
The configuration is similar to the video i posted before, but with a difference: box 4 finally breaks when it reaches the floor.
A box only breaks when the impulse strength is > 8:

box 3 collided with box 4 with impulse strength of 7.72
box 4 collided with box 3 with impulse strength of 7.72
box 2 collided with box 3 with impulse strength of 9.59 => box2 breaks
box 3 collided with box 2 with impulse strength of 9.59 => box3 breaks
box 0 collided with box 2 with impulse strength of 6.57
box 2 collided with box 0 with impulse strength of 6.57
box 4 collided with floor with impulse strength of 12.25 => box4 breaks

What i fail to understand is this:

box 4 is falling and impacting with box 3 with impulse 7.72. This collision
produce an impact force of 9.59 between box 2 and box 3 greater than 7.72!!!!

I expected the impact between box 3 and 4 to be the same (or at least really similar) to the impact between box 2 and 3.

To conclude the analysis, we see that box 4 breaks. Box 4 first collide with box 3 but doesn't break. This slow down its run towards the floor, but
at the same time it start to spin. When box 4 hit the floor it is spinning. Maybe this makes the difference (one of the corner hit
the floor with high velocity).


Top
 Profile  
 
PostPosted: Mon Jun 25, 2012 9:31 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1515
Location: Tokyo
I see. That does seem kinda strange. Maybe the angle of the collision is having an effect somehow.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron
Powered by phpBB® Forum Software © phpBB Group