Highly experimental toy physics engine in Elm.
The API is currently shaping up and will be most likely changed.
Call it to set the world’s gravity, cause by default it’s an open space:
setGravity (vec3 0 0 -10) world
--> worldWithGravityYou can also add bodies to the world. The function returns updated world and an id of the body.
addBody body world
--> (newWorld, bodyId)A unique identifier of a body in the world. It can be used to link additional information, like meshes.
Body is a solid matter without any moving parts.
After creating a body, you have to give it a mass. Bodies without mass don’t move!
setMass 5 boxBody
--> heavyBoxBodyAdds a shape at the center of the body and returns a tuple of updated body and a shape id. For example, call this to add a box:
addShape (box (vec3 1 1 1)) body
--> (newBody, shapeId)Same as BodyId, but for shapes within a body.
Rotate the body around the axis by a specific angle from its current orientation.
rotateBy (vec3 1 0 0) pi body
--> upsideDownBodyMove the body from its current position.
offsetBy (vec3 0 0 12) body
--> elevatedBodyA box shape is defined by its half extends. To create a 2x2 box, call this:
box (vec3 1 1 1)Simulate the world, given the time delta since the last step.
Call this function on a message from the onAnimationFrame subscription!
Fold over each shape in the world. Use this to convert shapes into visual representation, e.g. WebGL entities.
entities =
fold
({ 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 the body the shape belongs to
shapeId is an id of the shape within the body
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.
The following functions are exposed for debugging. Check the demos for usage details.
Fold over the contact points in the world.
Fold over all the face normals in the world, where each face normal consists of a normal vector for a face and a reference point within the face. These are both expressed within the local shape coordinate system. The transform to the current world coordinates from the shape coordinates is also provided.
Fold over all the unique edges in the world, where each unique edge consists of a unit direction vector that runs parallel to an edge of a face in the shape. A vertex point of the shape and a transform to the current world coordinates from the shape coordinates is also provided for context. Both the vector and the point are expressed within the local shape coordinate system.