   Physics engine (Erin Catto method)
  I'm new here, so Hello everyone.I'm trying to write my own physics engine. Right now i'm stuck with collision response. I have all collision points with normals, and exact time, when collision appeared.I was trying an approach described by Baraff but i failed. Right now i would like to try Erin Catto method (Iterative Dynamics with Temporal Coherence - http://www.continuousphysics.com/ftp/pub/test/physics/papers/IterativeDynamics.pdf)Do You know, where i can find example implementation of it?Any hints and  would be appreciated :).thanks   
  I did a presentation not so long ago on resolving collisions like you have.  It's AFAIK different than the way most physics engines work.  But it should be pretty manageable to implement and understand since it only relies on understanding the coefficient of restitution, the article Physics, part 3: Collision Response by Chris Hecker, and solving linear systems of equations.This is my powerpoint.  And you might need to install TexPoint to have the math render correctly.  And if you don't have powerpoint you can get the free reader.The basic idea is to form your collision equations into a system of linear equations and solve for unknown impulses.  If you aren't familiar with linear systems, check out Chapter 2 of Numerical Recipes.The downside here is that I've only worked through the math for the 2D case.  It's basically the same for 3D, but you'd need to work through the angular parts and make sure that they make sense still.It's how I'm building my own physics engine implementation at the moment.  I use GJK to compute the minimum distance between bodies, get an upper estimate for relative velocity between bodies, and iteratively work to find the exact time of impact between the bodies ala Conservative Advancement.  Then solve contact islands using this method I present.   ;  Thank You for your quick response.Your method seems to be Relatively easy to implement.  Tomorrow I'll try to analyze it better. What about friction and stacking? Do You think is possible to extend those equations to cover that?   ;  No idea.  That's what I'm working on now.  Any ideas would be appreciated :)tAt the end of that presentation, I present 3 test cases that the current method couldn't handle (at least not well).  They all relate to stacking.  Of course, most engines freak out with stacking anyway, :)   ;Quote:Original post by Numsgil...since it only relies on understanding the coefficient of restitution...One thing from glancing at your ppt - you seem to be assuming that Newton's restitution law, which is only really valid for the collision of two particles, is valid not only at a single contact point between two bodies (reasonable), or even at multiple contact points between two bodies (easy to come up with cases where it's not correct), but at multiple contact points between multiple bodies (not correct - consider Newton's cradle). Another way of looking at this is that the rigid body approximation requires that collisions are instantaneous. So, a genuinely simultaneous collision in such a system is a really "freaky"/edge-case event - even if you detect two collisions as occurring at the same time, they would in practice (in this ideal world!) happen at slightly different times. So - iterative resolution of collisions seems to be the solution method that is most appropriate.Contacts are different of course - they are not instantaneous, so you can (and "should") resolve them simultaneously.;Quote:Original post by MrRowlQuote:Original post by Numsgil...since it only relies on understanding the coefficient of restitution...One thing from glancing at your ppt - you seem to be assuming that Newton's restitution law, which is only really valid for the collision of two particles, is valid not only at a single contact point between two bodies (reasonable), or even at multiple contact points between two bodies (easy to come up with cases where it's not correct), but at multiple contact points between multiple bodies (not correct - consider Newton's cradle). Actually it works.  Work through some examples if you don't believe me.  What happens is that the restitution law applies to a single contact point, but by building the matrix of simultaneous collisions, and solving for all unknown impulses at the same time, all the relevant impulses propagate down the line.I think anyway :)   ;  Here's an example - consider a Newton's cradle with 3 equal, elastic balls, A on the left moving to the right with speed 2, B in the middle stationary (not accelerating), C on the right moving to the left with speed 1:A-->B<--CA and C hit B at the same time.So Va = 2, Vb = 0, Vc = -1If you solve both collisions at the same time, then if you:1. and enforce Newton's law of restitution in both collisions - i.e.Vb' - Va' = 2, Vc' - Vb' = 1 (' means vel after collision)AND2. conserve momentum:Va' + Vb' + Vc' = Va + Vb + Vc = 1then you get:Va' = -4/3, Vb' = 2/3, Vc' = 5/3However, this isn't what _actually_ happens! If you work through it in terms of individual collisions (doesn't matter what order you consider them in):1. Initially Va = 2, Vb = 0, Vc = -12. Collide A with B -> Va = 0, Vb = 23. Collide B with C -> Vb = -1, Vc = 24. Collide B with A -> Va = -1, Vb = 0, Vc = 2and this is what happens in practice = the two balls A and C will "swap" velocities, and leave B unchanged.This problem happened in Phun, though I don't know if it's still the case, and I never got confirmation that it happens because it tries to solve collisions simultaneously (where the maths is right, but the physics is wrong).;  Hmm, I'll have to play with it and see what happens.  I'm still in the process of writing the algorithm in code, so I haven't been able to experiment very thoroughly.   