Hipmunk-0.1: A Haskell binding for Chipmunk.Source codeContentsIndex
Physics.Hipmunk.Body
Portabilityportable (needs FFI)
Stabilitybeta
Maintainerfelipe.lessa@gmail.com
Contents
Creating
Static properties
Basic
Mass
Moment of inertia
Linear components of motion
Position
Velocity
Force
Angular components of motion
Angle
Angular velocity
Torque
Dynamic properties
Utilities
Description
Rigid bodies and their properties.
Synopsis
data Body
newBody :: CpFloat -> CpFloat -> IO Body
type Mass = CpFloat
getMass :: Body -> IO Mass
setMass :: Body -> Mass -> IO ()
type Moment = CpFloat
getMoment :: Body -> IO Moment
setMoment :: Body -> Moment -> IO ()
getPosition :: Body -> IO Position
setPosition :: Body -> Position -> IO ()
type Velocity = Vector
getVelocity :: Body -> IO Velocity
setVelocity :: Body -> Velocity -> IO ()
type Force = Vector
getForce :: Body -> IO Force
setForce :: Body -> Force -> IO ()
getAngle :: Body -> IO Angle
setAngle :: Body -> Angle -> IO ()
type AngVel = CpFloat
getAngVel :: Body -> IO AngVel
setAngVel :: Body -> AngVel -> IO ()
type Torque = CpFloat
getTorque :: Body -> IO Torque
setTorque :: Body -> Torque -> IO ()
slew :: Body -> Position -> Time -> IO ()
updateVelocity :: Body -> Vector -> CpFloat -> Time -> IO ()
updatePosition :: Body -> Time -> IO ()
resetForces :: Body -> IO ()
applyForce :: Body -> Vector -> Position -> IO ()
applyOnlyForce :: Body -> Vector -> Position -> IO ()
applyImpulse :: Body -> Vector -> Position -> IO ()
dampedSpring :: (Body, Position) -> (Body, Position) -> CpFloat -> CpFloat -> CpFloat -> Time -> IO ()
localToWorld :: Body -> Position -> IO Position
worldToLocal :: Body -> Position -> IO Position
Creating
data Body Source
A rigid body representing the physical properties of an object, but without a shape. It may help to think as a particle that is able to rotate.
show/hide Instances
newBody :: CpFloat -> CpFloat -> IO BodySource

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

It is recommended to call setPosition afterwards.

Static properties
Basic
Mass
type Mass = CpFloatSource
getMass :: Body -> IO MassSource
setMass :: Body -> Mass -> IO ()Source
Moment of inertia
type Moment = CpFloatSource
getMoment :: Body -> IO MomentSource
setMoment :: Body -> Moment -> IO ()Source
Linear components of motion
Position
getPosition :: Body -> IO PositionSource
setPosition :: Body -> Position -> IO ()Source
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
type Velocity = VectorSource
getVelocity :: Body -> IO VelocitySource
setVelocity :: Body -> Velocity -> IO ()Source
Force
type Force = VectorSource
getForce :: Body -> IO ForceSource
setForce :: Body -> Force -> IO ()Source
Angular components of motion
Angle
getAngle :: Body -> IO AngleSource
setAngle :: Body -> Angle -> IO ()Source
Angular velocity
type AngVel = CpFloatSource
getAngVel :: Body -> IO AngVelSource
setAngVel :: Body -> AngVel -> IO ()Source
Torque
type Torque = CpFloatSource
getTorque :: Body -> IO TorqueSource
setTorque :: Body -> Torque -> IO ()Source
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 :: Body -> Vector -> CpFloat -> Time -> IO ()Source

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 :: Body -> Time -> IO ()Source
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 :: Body -> IO ()Source
resetForces b redefines as zero all forces and torque acting on body b.
applyForce :: Body -> Vector -> Position -> IO ()Source

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 :: Body -> Vector -> Position -> IO ()Source
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 :: Body -> Vector -> Position -> IO ()Source
applyImpulse b j r applies to the body b the impulse j with offset r, both vectors in world coordinates.
dampedSpring :: (Body, Position) -> (Body, Position) -> CpFloat -> CpFloat -> CpFloat -> 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: not solving the damping forces in the impulse solver causes problems with large damping values. This function will eventually be replaced by a new constraint (joint) type.

Utilities
localToWorld :: Body -> Position -> IO PositionSource
For a vector p in body b's coordinates, localToWorld b p returns the corresponding vector in world coordinates.
worldToLocal :: Body -> Position -> IO PositionSource
For a vector p in world coordinates, worldToLocal b p returns the corresponding vector in body b's coordinates.
Produced by Haddock version 2.3.0