A block is created from elm-geometry Block3d. To create a 1x1x1 cube, centered at the origin of the body, call this:
cubeBody =
block
(Block3d.centeredOn
Frame3d.origin
( meters 1, meters 1, meters 1 )
)
dataA plane with the normal that points in the direction of the z axis.
A plane is collidable in the direction of the normal. Planes don’t collide with other planes and are always static.
A sphere is created from elm-geometry Sphere3d.
To create a 1 meter radius sphere, that is centered at the origin of the body, call this:
sphereBody =
sphere
(Sphere3d.atOrigin (meters 1))
dataA particle is an abstract point that doesn’t have dimensions. Particles don’t collide with each other.
Bodies may have static or dynamic behavior.
Dynamic bodies move and react to forces and collide with other dynamic and static bodies.
Change the behavior, e.g. to make a body dynamic:
dynamicBody =
staticBody
|> withBehavior (dynamic (Mass.kilograms 5))Get the position and orientation of the body in the world as Frame3d.
This is useful to transform points and directions between world and body coordinates.
Get the origin point of a body in the world
Get the linear velocity of a body
Get the angular velocity of a body
Get the center of mass of a body in the body coordinate system.
Set the position of the body in the world, e.g. to raise a body 5 meters above the origin:
movedBody =
body
|> moveTo (Point3d.meters 0 0 5)Move the body in the world relative to its current position, e.g. to translate a body down by 5 meters:
translatedBody =
body
|> translateBy (Vector3d.meters 0 0 -5)Rotate the body in the world around axis, e.g. to rotate a body 45 degrees around Z axis:
movedBody =
body
|> rotateAround Axis3d.z (Angle.degrees 45)Get user-defined data.
Update user-defined data.
Apply a force in a direction at a point on a body. The force will be applied during one simulation step.
Keep applying the force every simulation step to accelerate.
pushedBox =
box
|> applyForce
(Force.newtons 50)
Direction3d.positiveY
pointOnBoxApply an impulse in a direction at a point on a body. Applying an impulse is the same as applying a force during the interval of time. The changes are applied to velocity and angular velocity of the body.
For example, to hit a billiard ball with a force of 50 newtons, with the duration of the hit 0.005 seconds:
impulse =
Force.newtons 50
|> Quantity.times (Duration.seconds 0.005)
hitCueBall =
cueBall
|> applyImpulse
impulse
Direction3d.positiveY
hitPointSet the material to controll friction and bounciness.
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
(Sphere3d.atOrigin (meters 1))
]
dataWe only support rigid bodies.
Set linear and angular damping, in order to decrease velocity over time.
This may be useful to e.g. simulate the friction of a sphere rolling on the flat surface. The normal friction between these surfaces doesn’t work, because there is just 1 contact point.
Inputs are clamped between 0 and 1, the defaults are 0.01.
Represents a physical body containing user defined data, like a WebGL mesh.
By default bodies don’t move. To change this, use withBehavior.
All bodies start out centered on the origin, use moveTo to set the position.
The supported bodies are:
For complex bodies check compound.