Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've seen box2d and bullet ports into javascript, but neither of them attracted me particularly, except by source code.

It all seemed, after all, quite simple once I looked inside them. But what are they doing within each of those libraries to get nice physics simulation? Are they explained anywhere?

It's all right to just list them and explain shortly, then provide bunch of links. I know even physics approximations are a wide topic that can't be answered with four paragraphs.

share|improve this question
    
I'll eventually answer the question myself because I am studying the sources. If you manage to shorten the effort I'll appreciate it. –  Cheery Jul 27 '10 at 0:05
add comment

6 Answers 6

Rigid body physics is actually quite simple in concept - that is, the behaviors an engine is trying to create are not very complicated. That's probably why the libraries you looked at seem quite simple to you.

The trick is that making a sim that is robust, stable, and fast, even in the presence of things like floating-point error and low, variable framerates, is quite difficult and usually involves a great deal of tweaking and fiddling. Further complicating the issue is the fact that a lot of extremely smart people have made heroic efforts at finding better solutions, and have come up with beautiful and powerful but difficult-to-understand algorithms that have given the field a reputation for black magic.

In general, a physics engine is going to be concerned with three things (the order in which they do them in the internal loop varies):

  1. Integration (approximating the Newtonian equations of motion),
  2. Collision detection, and
  3. Constraint solving (updating positions and velocities to satisfy nonpenetration or other user-specified constraints.)

For most of these, there are both simple but not-so-accurate algorithms and complex but more-accurate algorithms. To get you started:

  1. For integration, most people use either Symplectic Euler or Verlet (which are actually equivalent. You can read up on numerical integration if you like, but the consensus seems to be that cheap first-order methods are fine.
  2. You can find all the collision detection references you could want on the Real-Time Rendering resource page.
  3. For constraint solving, the method of sequential impulses is very easy to understand. Erin Catto (the author of Box2D) gives a presentation at GDC every year - the slides are linked from the Box2D main page. The 2006 slides cover sequential impulses pretty well. You can also look into fancier methods like Featherstone or projected Gauss-Seidel.

There's an excellent introduction to simple methods and what can go wrong in the early chapters of the just-published book Game Physics Pearls.

share|improve this answer
add comment

Read Glenn Fiedler's game physics series: http://gafferongames.com/game-physics/

Also, Erin Catto (the author of Box2D) has a paper on constrained dynamics.

For collision detection, read Real-Time Collision Detection by Christer Ericson

share|improve this answer
1  
That first link is broken but I think that the same articles can now be found here: gafferongames.com/game-physics/integration-basics (but I can't be sure because I never saw the originals) –  Justin Dec 14 '10 at 8:01
add comment

http://en.wikipedia.org/wiki/Rigid_body_dynamics might be a good place to start. Different games will divide things up into different bodies, but in general you have a number of discrete rigid bodies linked by joints with specific properties. Each loop through the game you calculate the forces on each body and calculate its new parameters (position, velocity, etc). You also have to transmit forces from each body to the others it shares joints with and factor in global forces (gravity).

This doesn't cover things like liquid or cloth physics, those are all gibberish to me. There are differential equations involved and thats about the point where my eyes glaze over.

share|improve this answer
    
Well.. wikipedia would be the first obvious place to look things from. Also everybody this far probably know that they tend to simulate body motions through forces. There's much more in box2d than that. Here's few things I'm interested about: Constraint solving and some other stuff that prevents simulation from exploding. Collision detection algorithms. Optimizations on constraint solving and collision detection. Joint/Collision response algorithms. Simulation of the friction. –  Cheery Jul 27 '10 at 0:02
    
Thats verging into "too long for a real answer" territory. For example, damping to prevent simulation artifacts is a complex bit of math. As for things like joint force transfer, the simple version is that each joint has specific axes it will transfer force on with a percentage of the body's energy counting towards the join depending on the angle between the two. The simplest joint is a fixed link, where all force from either side is translated across. –  coderanger Jul 27 '10 at 0:27
    
Like I said in the question: It's all right to just tell there's complex math here and there and provide a link for further reading. –  Cheery Jul 27 '10 at 11:03
    
Well, there you go then :-) –  coderanger Jul 27 '10 at 15:32
add comment

OpenCloth details all of the integration techniques in as simple a manner as possible. Alot is in the pipeline.

Details: http://code.google.com/p/opencloth/

share|improve this answer
add comment

One important thing besides the physics equations is tracking all the objects, so that checking for collision detection and interactions is as fast as possible. Spatial Hashing is the technique that the Chipmunk physics engine uses.

share|improve this answer
add comment

Just to add to the list of links, I found Baraff's SIGGRAPH notes very helpful.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.