Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 54 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
 Post subject: Box2D Demo & Tutorial
PostPosted: Sat Mar 25, 2006 11:57 pm 
Offline

Joined: Fri Jul 01, 2005 5:29 am
Posts: 323
Location: Irvine
I wrote a tutorial for an impulse based constraint solver. The zip file comes with slides and source code for a 2D engine.

http://www.gphysics.com/files/GDC2006_ErinCatto.zip


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 26, 2006 6:59 pm 
Offline

Joined: Fri Jul 22, 2005 8:00 pm
Posts: 44
Location: Santa Monica
I don't think you cover this in your slides, but how do you handle non-zero restitutions in such a scheme?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 26, 2006 8:47 pm 
Offline

Joined: Fri Jul 01, 2005 5:29 am
Posts: 323
Location: Irvine
Restitution can be handled (approximately) by adding a "bounce velocity" into the normal impulse computation, just like the bias velocity used for resolving penetration.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 6:02 pm 
Offline

Joined: Sun Jul 03, 2005 4:06 pm
Posts: 759
Location: Bellevue, WA
You could also use the Guendelman integration:

1) Move to candidates and handle collisions
2) Integrate velocity
3) Handle contact
4) Integrate position


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 2:17 am 
Offline

Joined: Wed Nov 30, 2005 11:07 am
Posts: 24
Location: China
Why do not write a tutorial for an LCP based constraint solver,because i saw that your introduced method in your this paper:"Iterative Dynamics with Temporal Coherence " is LCP based constraint solver


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 6:54 am 
Offline

Joined: Fri Jul 01, 2005 5:29 am
Posts: 323
Location: Irvine
Quote:
Why do not write a tutorial for an LCP based constraint solver,because i saw that your introduced method in your this paper:"Iterative Dynamics with Temporal Coherence " is LCP based constraint solver


It turns out that the sequential impulse algorithm is very similar to the iterative LCP algorithm, but is easier to understand and implement. Think of it as Revision 2.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 22, 2006 10:06 pm 
Offline

Joined: Fri Mar 31, 2006 7:13 pm
Posts: 90
Thanks for this impulse based method!
I like it very well, it is easy to understand and implement.

I finally implimented 3D simulation and it looks prety stabele and fast, even without optimisation.

The only problem seems to make bias:
if it is smal the the stacking will be stable but the collision looks not well.
but if is is biiger to make collision looks well the stacking scenario gains too many extra energy and becomes jumpily.

Da you have any ideas how to avoid or compensate this extra energy from bias?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 23, 2006 12:09 am 
Offline

Joined: Fri Jul 01, 2005 5:29 am
Posts: 323
Location: Irvine
I haven't tried this yet, but you should be able to propagate two velocity states. One velocity state includes the bias and is used to update position. The second velocity state does not include the biase and is carried over to the next step.

Even with this method you shouldn't use a large bias factor because the overlap correction can overshoot and you will lose coherence.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 11, 2006 9:34 am 
Offline
User avatar

Joined: Sat Jun 17, 2006 6:13 pm
Posts: 1
Yo

I implement your collision response in my physics engine and it is great
http://www.dathox.unit1.pl/files/phylum2d.rar

I tried to create player in my demo and I have one problem.
Sometimes, when player hits the ground, he doesnt slide :/. friction = 0.5.
http://www.dathox.unit1.pl/files/Slide.rar
any idea ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 6:54 pm 
Offline

Joined: Mon Aug 07, 2006 6:48 pm
Posts: 7
Location: Davis, CA, USA
I've been trying to implement good looking restitution in my Box2D dervied Java code for a while now. I've assigned a "hardness" factor (0 -> 1.0) and use this to dervice a value to apply to the normal impulse calculation as suggested above.

However, the results I'm getting are pretty unstable - I think most due to the acceptence of penetration and result incorrect relative positions of the bodies. The current implementation is reasonable in that it results in some bounce back based on the hardness value assigned - the value applied has to be tuned for different situations.

I wonder if theres a more formal solution in this case or whether there are some resources I could read up on to better understand how restitution might be resolve in impulse based case.

Thanks for any help,

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 7:44 pm 
Offline
Site Admin
User avatar

Joined: Sun Jun 26, 2005 6:43 pm
Posts: 3746
Location: California, USA
Adding restitution can be done by calculating its value at the start (NOT during the solver iterations).
Then, using this restitution as target velocity instead of 0.
SimdScalar velocityError = cpd->m_restitution - rel_vel;

Bullet implements a 3D version of Sequential Impulse, and includes restitution support.

See calculation of restitution:
http://www.continuousphysics.com/Bullet ... tml#l00116
and its application:
http://www.continuousphysics.com/Bullet ... tml#l00051

I'm not familiar with the Box2D code, but if this info is not enough, ask again, and I can check it out (or Erin Catto?).

Thanks,
Erwin


kevglass wrote:
I've been trying to implement good looking restitution in my Box2D dervied Java code for a while now. I've assigned a "hardness" factor (0 -> 1.0) and use this to dervice a value to apply to the normal impulse calculation as suggested above.

However, the results I'm getting are pretty unstable - I think most due to the acceptence of penetration and result incorrect relative positions of the bodies. The current implementation is reasonable in that it results in some bounce back based on the hardness value assigned - the value applied has to be tuned for different situations.

I wonder if theres a more formal solution in this case or whether there are some resources I could read up on to better understand how restitution might be resolve in impulse based case.

Thanks for any help,

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 08, 2006 3:13 am 
Offline

Joined: Mon Aug 07, 2006 6:48 pm
Posts: 7
Location: Davis, CA, USA
Thanks for the prompt reply Erwin. I've applied what you've shown in your source and it looks good for direct collisions. However, when I get an collisions where the velocities are at an angle to the normal of collision things seem to go astray in that I *appear* to get extra velocity into the system somehow.

Are there any obvious mistakes I might have made that would have these symptoms? I realise this is a long shot :)

Thanks for your help up to now anyway, it's really helped me to understand the original code.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 08, 2006 3:27 am 
Offline
Site Admin
User avatar

Joined: Sun Jun 26, 2005 6:43 pm
Posts: 3746
Location: California, USA
You might introduce extra energy/verlocity due to penetration depth recovery. This can be fixed by keeping the impulses split. So you can download a new Box2D.zip from the quote below.

As Erin mentioned on the ODE list:

Erin on ODE mailinglist 6-26-2006 wrote:
I didn't have time to check the patch, but I updated my 2D physics engine
Box2D. This engine uses sequential impulses, which are mathematically
equivalent to PGS. Here's how I did it:

- Each body has a bias velocity that is only used for correcting overlap.
- A separate bias impulse is accumulated for each contact.
- The bias velocity and impulse are initialized to zero each time step (no
warm starting).

The bias impulse and velocity are completely independent of the regular
impulses and velocity, so they could be solved in parallel. However, it was
convenient to solve them together and that should be more cache friendly.

You can get the code here: http://www.gphysics.com/files/Box2D.zip

You can switch between the two methods by using the macro
BIAS_PRESERVES_MOMENTUM in Arbiter.cpp. With the split velocity I was able
to use a large bias factor (0.8). This means that overlap is reduced 80% per
step. Such a large bias factor leads to serious bouciness with the merged
velocity.

I also tried using a split velocity for joints. The results were not nearly
so nice, especially for my suspension bridge test. I think that particular
arrangement is more stable with some compliance in the joints.

Erin



Make sure to clip the restitution to 0, don't make it negative.
(Minor) As the friction depends on the normal impulse/force, it might be magnified by the restitution. Try to not add positive restitution to the friction component.

Erwin


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 08, 2006 4:52 am 
Offline

Joined: Mon Aug 07, 2006 6:48 pm
Posts: 7
Location: Davis, CA, USA
Thanks for the second pointer. I've integrated the seperating of bias impulse and actual impulse into my java code. That generally seems to make the system more accurate.

Unfortunately, doesn't seem to resolve my restitution issues. Maybe I'm measuring the energy wrong. Is there something wrong with summing up the length of all the velocities (speed?) given my test in this case is frictionless, no damping and with 10 circles all of equal mass. It's a pool/snooker triangle - the cue ball appraoches at a speed of 150. Am I wrong in thinking that the sum of the speeds of all bodies should never exceed 150 (given they're all equal masses) ?

Wow - don't I sound newb? :) Questioning everything I thought I knew now :)

Thanks again for the pointer, nice to keep up to date. Is the ODE mailing list public or do you have to get an invite?

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 08, 2006 6:38 am 
Offline

Joined: Fri Jul 01, 2005 5:29 am
Posts: 323
Location: Irvine
Kev,

Try it with just two spheres colliding. You should be able to compare the results with theory and figure out where the numbers go wrong.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 54 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC


Who is online

Users browsing this forum: Basroil and 1 guest


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:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group