Box2DFlashAS3 released

November 20, 2007 on 2:34 pm | In Miscellaneous, Physics | 15 Comments

Someone made a direct port of the great Box2D physics library from C++ to AS3 called Box2DFlashAS3. Because the physics solver of the motor engine is based on Box2D Light and the version I’m currently developing follows the Box2D engine framework closely I’m feeling a little redundant with my project now. Anyway I’ll continue development but there isn’t really a reason to wait for my release since Box2D is simply the best!

Motor Physics goes Open Source

October 2, 2007 on 9:30 pm | In Actionscript, Physics | 37 Comments

I’m pleased to announce that my 2D physics engine will be released as Open Source under the zlib/libpng license at the end of this year.
Till then the code definitely needs some refactoring and clean up for better readability. But as it’s optimized so much don’t expect beautiful code :) Stay tuned!

Updates

July 16, 2007 on 1:21 am | In Actionscript, Physics | 14 Comments

Motor Physics

Finally I added support for arbitrary convex polygons, now supporting contact ids for managing persistent contacts. This is needed for a feature called warm starting which improves the quality of the solver. Furthermore the complexity of the polygon intersection algorithm was reduced from [(N0 + N1)^2] to [2*N0*N1] (N = number of separation axis to be tested) making it nearly twice as fast. Adding lines and circles is pretty straight-forward and shouldn’t take much time.

Contact point calculation also has been drastically improved. Computation now adds almost no overhead because most of the information needed is already computed during the collision detection phase. After all the simulation is very stable, and scales nicely with the amount of bodies since most algorithms are O(n) or O(log(n)). Chris is meanwhile working on different constraint types while I am enhancing the API for user interaction. We hope to get a new demo finished soon.

‘polygon soup’, click and drag to attract objects to mouse cursor

Data Structures

Besides some minor bug fixes, I included a new HashMap class, which is a replacement to the HashTable class (it’s much faster). The HashMap supports perfect hashing (direct lookup) using dictionaries. Think of it as an associative array with the additional capability of using object instances as keys as well.
The existing HashTable on the other hand is a ‘classic’ hash table using an array and linked overflow for resolving collisions. I leave it in the package for now, because it has one advantage over the HashMap – you can directly traverse the value/key pairs using an iterator without making a copy of the complete data set first.

Actually the HashMap class is so simple that you should considering using a Dictionary directly when speed is crucial, but it’s nice to have a common interface for all structures.

Motor Physics: 50 dancing boxes

June 15, 2007 on 5:25 pm | In Actionscript, Physics | 10 Comments
move mouse inside stage, press ‘w’ key to wiggle the floor

This is a follow up to the post about the SI-Solver from the Box2D engine. The revised demo shows a worst case scenario with 50 stacked boxes. It took great effort to max out performance, but I think it’s fast enough now, especially when realizing that the engine does a lot of computations each frame to make things stable (for example 50 sequential impulse computations per box). Performance is top priority, because a physics system which sucks up all processing time doesn’t leave room for rendering, AI and other game engine elements and hence is useless for more complex games.

I still see a lot potential to make it faster, probably in the range of 30-70%, but I won’t go into that for now. Instead I’m concentrating on putting the engine pieces together and adding forces, constraints and user interactivity. Enough with just bouncing stuff!

As a side note, I also decoupled the simulation from the frame rate (which I should have done a long time ago), so the physics attempts to run at a constant rate, which is very important for games. The example above is limited to 60fps so it tries to update the simulation every ~16ms. When the fps counter shows more than 60fps, there is still processing time available.

Motor Physics: sequential impulses

May 27, 2007 on 5:01 pm | In Actionscript, Physics | 5 Comments
move mouse inside stage, press ‘F’ for more fun

I have now implemented Erin Catto’s Sequential Impulses solver which he presented in his Box2D mini demo. It’s equivalent to the PGS (Projected Gauss Seidel) algorithm when using SI with clamped accumulated impulses. You find more information in his paper.

The flash runs currently very slow because it’s not optimized at all, but so far I’m happy that it works. I really love SI as it overcomes the jitter of objects which also made stacking nearly impossible in the previous version. But I keep my old solver because it’s very fast and great for non-gravity environments or particle-sized objects where jitter was not an issue.

The last (and probably hardest) step is to rewrite all my collision functions to add contact caching capability, which is quite complicated. The Box2D engine only supports (guess what.. boxes) and the collision and contact generation code is far to slow to be enjoyable in flash, so it’s crucial to find a fast solution for this. Once this is done I can concentrate on the API.

« Previous PageNext Page »

Proudly powered by WordPress Theme based upon Pool theme by Borja Fernandez.
Entries and comments feeds.