Highly experimental toy physics engine in Elm.
The API is currently shaping up and will be most likely changed.
Let be the new world!
Call it to set the world's gravity, cause by default it's an open space
world
|> setGravity (vec3 0 0 -10)You can also add bodies to the world
Body is a solid matter without any moving parts
This gives you an empty body, add shapes to turn it into smth meaningful
After creating a body, you have to give it a mass. Bodies without mass don't move!
Adds shapes to the body. For example, call this to add a box:
body
|> addShape (box (vec3 1 1 1))Rotate the body around the axis by a specific angle from its current orientation
Move the body from its current position
A box shape defined by its half extends. To create a 2x2 box, call this:
box (vec3 1 1 1)A plane shape, with a normal pointing in the direction of the z axis
Simulate the world, given the time delta since the last step.
Call this function on a message from the AnimationFrame subscription!
Fold over each shape in the world. Use this to convert shapes into visual representation, e.g. WebGL entities.
entities =
foldl
({ transform, bodyId, shapeId } currentEntities ->
makeEntity transform bodyId shapeId :: currentEntities
)
[]
worldtransform is a transformation matrix that offsets and rotates a shape into the world coorditantes
bodyId is an id of a body the shape belongs to, each new body in the world gets and id starting from 0
shapeId is an id of the shape, each new shape in a body gets and id starting from 0
Use bodyId and shapeId to link additional information from the outside of the engine, e.g. which mesh to render
or what color should this shape be.
Get the contact points in the world for visual debugging