w0rm / elm-physics

3D physics engine in Elm
https://package.elm-lang.org/packages/w0rm/elm-physics/latest
BSD 3-Clause "New" or "Revised" License
146 stars 12 forks source link

Extend Physics.elm constructor methods to exercise multi-shape bodies. #17

Closed paulmartel closed 5 years ago

paulmartel commented 6 years ago

Allow support for concave bodies composed of individually transformed ConvexPolyhedron shapes. Support for constructing arbitrary tetrahedron shapes would also help here, providing universal building blocks for constructing arbitrary concave polyhedron bodies.

This would allow testing equivalences such as between a body consisting of a single cube shape with side length N and a body composed of NxNxN offset unit cubes with the same total mass uniformly apportioned.

w0rm commented 6 years ago

I think the only thing that is missing here is an ability to add shapes at certain positions and with certain rotations. This is already in the code, it is just not exposed in the api.

w0rm commented 6 years ago

I think there is a room for performance improvement. Right now, the positions and rotations of shapes are stored in a separate dictionary of each body. We could apply these transformations on the shapes directly. This means that plane would need to store its normal and position, and a sphere would need to store its position. For convex, it's just transforming each vertex, normal and edge

The downside of this is that we would need to transform the meshes separately. But as the initial data is known, it should be possible to make a single mesh containing all shapes of a body. This would reduce the number of expensive draw calls in WebGL and improve the rendering performance.

This could also result in API simplification, there would be no need to deal with ShapeId.

w0rm commented 5 years ago

This was addressed in #43 by compound bodies:

https://github.com/w0rm/elm-physics/blob/master/examples/Compound.elm

Can be seen live here: https://unsoundscapes.com/elm-physics/examples/compound/