w0rm/elm-physics/3.1.0

NOTE: the latest version is 6.2.0

Physics.Body

type alias Body data =
Protected data

Represents a physical body containing user defined data, like a WebGL mesh.

By default a body is positioned in the center of the world and has zero mass. To change this, use setPosition or setMass. Bodies with zero mass don’t move!

The supported bodies are:

For complex bodies check compound.

box :
{ x : Float
, y : Float
, z : Float
}
-> data
-> Body data

A box is defined by its dimensions along the corresponding axes. To create a 1x1 box, call this:

box { x = 1, y = 1, z = 1 } data
plane : data -> Body data

A plane with the normal that points in the direction of the z axis.

A plane is collidable in the direction of the normal.

sphere : Float -> data -> Body data

A sphere is defined by its radius.

setMass : Float -> Body data -> Body data

Set the body mass. Bodies with zero mass don’t move!

{ x : Float
, y : Float
, z : Float
}
-> Body data
-> Body data

Set the absolute position of the body in the world.

Body data
-> { m11 : Float
, m21 : Float
, m31 : Float
, m41 : Float
, m12 : Float
, m22 : Float
, m32 : Float
, m42 : Float
, m13 : Float
, m23 : Float
, m33 : Float
, m43 : Float
, m14 : Float
, m24 : Float
, m34 : Float
, m44 : Float
}

Get the position and the orientation of the body in a single matrix.

Elements are given by their row and column indices, starting at 1, so m23 means the element in the second row, third column.

To use this with WebGL, pass the result to Math.Matrix4.fromRecord.

setMaterial : Material -> Body data -> Body data

Set the material to controll friction and bounciness.

Positioning

{ x : Float
, y : Float
, z : Float
}
-> Body data
-> Body data

Move the body by a vector offset from the current position.

Body data
-> { x : Float
, y : Float
, z : Float
}

Orientation

Float
-> { x : Float
, y : Float
, z : Float
}
-> Body data
-> Body data

Rotate the body by a specific angle around the axis from the current orientation. Angle must be specified in radians.

{ x : Float
, y : Float
, z : Float
, w : Float
}
-> Body data
-> Body data

Set the body orientation to a unit quaternion.

Body data
-> { x : Float
, y : Float
, z : Float
, w : Float
}

Get orientation as a unit quaternion.

User-Defined Data

setData : data -> Body data -> Body data

Set user-defined data.

getData : Body data -> data

Get user-defined data.

Advanced

compound : List Shape -> data -> Body data

Make a compound body from a list of shapes.

For example, the sphere from above can be defined like this:

sphere radius data =
    compound [ Shape.sphere radius ] data

We only support rigid bodies.