Motor Physics: pushing performance to its limit

February 15, 2007 on 3:28 pm | In Actionscript, Physics | 2 Comments

Last week I have finally resumed work on my physics engine, so you can expect more frequent updates in the future :-) First thing I did was rewriting and optimizing the portion of the code that handles and resolves collisions, because I was still not satisfied with the overall performance and felt that I can further improve it.

The third revision is not only more robust, but also runs 3-4x faster – collisions between convex polygons are even 9x faster. I am very excited about the latest improvements, and the engine is now ready to handle massive polygon counts. This was done with some radical design changes:

  1. Collisions are split into specialized classes to handle an individual object pair whereas the former version quite often used a generic polygon vs polygon collision approach.
  2. Collisions now coexist in two packages: discrete and continuous (or static and dynamic). The idea is, that you define a speed threshold value to blend between both versions.
    For example, if you know in advance that the objects will not move at insane speeds and the chance that collisions are missed is rare or it doesn’t matter at all the fast static test is used, and if objects are moving very fast (like bullets) the dynamic collision system kicks in (which is roughly half as fast). This should give a higher frame rate, especially when frame coherence is high.
  3. The code was further optimized to drastically decrease execution time. The downside is that the code is now quite obfuscated and barely readable – but without pain no gain ;-)

Next I’ll try to optimize contact point calculations, followed by a version which has different strategies for collision culling.

2 Comments

TrackBack URI

  1. Sounds brilliant! No demo?

    Comment by Nate Chatellier — February, 15 2007 #

  2. hi nate, new demo is coming next week, I want to revise some other parts as well before posting something half-finished.

    Comment by mike — February, 15 2007 #

Sorry, the comment form is closed at this time.

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