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.
No comments:
Post a Comment