w0rm/elm-physics/6.0.0

NOTE: the latest version is 6.2.0

Physics.Shape

type alias Shape =
Shape

Shapes are needed for creating compound dynamic and static bodies.

The supported primitive shapes are block, sphere, and cylinder. For complex geometry use unsafeConvex.

Shapes within a body should not overlap — composing shapes only affects physical properties like mass, inertia, and center of mass. Use plus and minus to combine shapes, for example to create hollow bodies.

block : Block3d Meters BodyCoordinates -> Shape
sphere : Sphere3d Meters BodyCoordinates -> Shape
cylinder : Int -> Cylinder3d Meters BodyCoordinates -> Shape

Create a cylinder shape with the given number of side faces, clamped to at least 3. Even numbers are more efficient, because collision performance depends on the number of unique non-parallel faces and edges.

Complex shapes

minus : Shape -> Shape -> Shape

Subtract the first shape from the second. The subtracted shape must be fully contained within the other. It reduces volume, mass, and inertia, and is excluded from collision detection.

Useful for hollow bodies.

crate =
    Shape.block outer
        |> Shape.minus (Shape.block inner)
plus : Shape -> Shape -> Shape

Add a shape to another.

snowman =
    Shape.sphere bottom
        |> Shape.plus (Shape.sphere top)
sum : List Shape -> Shape

Combine a list of shapes.

dumbbell =
    Shape.sum
        [ Shape.cylinder 12 leftWeight
        , Shape.cylinder 12 bar
        , Shape.cylinder 12 rightWeight
        ]
unsafeConvex : TriangularMesh (Point3d Meters BodyCoordinates) -> Shape

Create a shape from a triangular mesh. This is useful if you want to import from Blender using elm-obj-file.

Note: this may cause unexpected behavior, unless you make sure that: