Hipmunk-5.1.0: A Haskell binding for Chipmunk.

Portability portable (needs FFI) provisional felipe.lessa@gmail.com

Physics.Hipmunk.Body

Description

Rigid bodies and their properties.

Synopsis

# Creating

data Body Source

A rigid body representing the physical properties of an object, but without a shape. It may help to think of it as a particle that is able to rotate.

Instances

 Eq Body Ord Body Entity Body

`newBody mass inertia` creates a new `Body` with the given mass and moment of inertia.

It is recommended to call `setPosition` afterwards.

# Static properties

## Linear components of motion

### Position

Note that using this function to change the position on every step is not recommended as it may leave the velocity out of sync.

### Velocity

Maximum linear velocity after integrating, defaults to infinity.

## Angular components of motion

### Angular velocity

Maximum angular velocity after integrating, defaults to infinity.

# Dynamic properties

slew :: Body -> Position -> Time -> IO ()Source

`slew b newpos dt` changes the body `b`'s velocity so that it reaches `newpos` in `dt` time.

It is usually used to change the position of a static body in the world. In that case, remember to reset the velocity to zero afterwards!

`updateVelocity b gravity damping dt` redefines body `b`'s linear and angular velocity to account for the force/torque being applied to it, the gravity and a damping factor during `dt` time using Euler integration.

Note that this function only needs to be called if you are not adding the body to a space.

`updatePosition b dt` redefines the body position like `updateVelocity` (and it also shouldn't be called if you are adding this body to a space).

`resetForces b` redefines as zero all forces and torque acting on body `b`.

`applyForce b f r` applies to the body `b` the force `f` with offset `r`, both vectors in world coordinates. This is the most stable way to change a body's velocity.

Note that the force is accumulated in the body, so you may need to call `applyOnlyForce`.

`applyOnlyForce b f r` applies a force like `applyForce`, but calling `resetForces` before. Note that using this function is preferable as it is optimized over this common case.

`applyImpulse b j r` applies to the body `b` the impulse `j` with offset `r`, both vectors in world coordinates.

applyDampedSpring :: (Body, Position) -> (Body, Position) -> Distance -> CpFloat -> Damping -> Time -> IO ()Source

`dampedSpring (b1,a1) (b2,a2) rlen k dmp dt` applies a damped spring force between bodies `b1` and `b2` at anchors `a1` and `a2`, respectively. `k` is the spring constant (force/distance), `rlen` is the rest length of the spring, `dmp` is the damping constant (force/velocity), and `dt` is the time step to apply the force over. Both anchors are in body coordinates.

Note: large damping values can be unstable, you should use the damped spring constraint instead.

# Utilities

For a vector `p` in body `b`'s coordinates, `localToWorld b p` returns the corresponding vector in world coordinates.

For a vector `p` in world coordinates, `worldToLocal b p` returns the corresponding vector in body `b`'s coordinates.