I'm writing the beginnings of a lightweight 2d rigid body engine (in javascript, as a hobby project), and i'm debating whether to store collision shapes in local or in (updated as needed) world coordinates.

Most physics engines out there (e.g. box2d, bullet, dyn4j, chipmunk, PhysicsJS) and indeed most treatments of the subject store the collision shape(s) of a rigid body in local coordinates. Since the body is rigid, these local coordinates never have to be updated.

However, when performing collision detection, the shapes have to be transformed into world coordinates (or into the local coordinates of another body) - and even if most collisions can be discarded with some kind of broadphase culling, shapes that have moved still have to be transformed when updating bounding boxes/volumes (unless one uses some orientable or rotation invariant bounding box/volume).

In the worst case, in some of the above implementations, the shapes seem to be transformed multiple times each time-step (computing AABBs + multiple collision tests).

Would there not be a possible performance benefit in storing the shapes in world coordinates (and updating them when needed) instead, and why is it that no one seems to use this approach? There is at least a benefit for static bodies.

  • 1
    \$\begingroup\$ Hmm, maybe it's Rule of Economy in action? ("Conserve programmer time over machine time.") \$\endgroup\$ – Anko Apr 11 '14 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.