Hipmunk-5.2.0.14: A Haskell binding for Chipmunk.

Copyright(c) 2008-2010 Felipe A. Lessa
LicenseMIT (see LICENSE)
Maintainerfelipe.lessa@gmail.com
Stabilityprovisional
Portabilityportable (needs FFI)
Safe HaskellNone
LanguageHaskell98

Physics.Hipmunk.Constraint

Contents

Description

Constraints that restrict the bodies' movement.

Synopsis

Common interface

data Constraint a Source

Represents a constraint between two bodies. Don't forget to add the bodies and the constraint itself to the space. The phantom type indicates the type of the constraint.

Instances

newConstraint :: ConstraintType a => Body -> Body -> a -> IO (Constraint a) Source

newConstraint b1 b2 type_ connects the two bodies b1 and b2 with a constraint of the given type. Note that you should add the Constraint to a space.

The ConstraintType type class is implemented by all constraint types to allow them to be manipulated by the same framework while retaining type-safety, consequently it isn't exported.

redefineC :: ConstraintType a => Constraint a -> a -> IO () Source

redefine constr type_ redefines constr's parameters on-the-fly, allowing you to dynamically change the constraint's behaviour.

setBiasCoefC :: BiasCoef -> Constraint a -> IO () Source

Sets the constraint's bias coefficient. By default it is equal to the last value set globally with setConstraintBiasCoef, which initially is 0.1

Forgetting the phantom type

These functions discard the phantom type of the constraint. They're useful, for example, if you want to put different constraints in a homogeneous data structure (such as a list).

data Unknown Source

An unknown constraint "type". Note that this isn't a ConstraintType because you can't create a constraint of Unknown type.

forgetC :: Constraint a -> Constraint Unknown Source

Completely safe function that discards the constraint type (which is a phantom type). You can "remember" it again by using unsafeRemember from the Unsafe module.

Constraint types

There are currently nine types of constraints. When appending a number to a property, we hint that it refer to one of the bodies that the constraint is intercting with (e.g. "Second anchor" is the position of the anchor on the second body in its coordinates).

Pin joint

data Pin Source

A pin joint connects the bodies with a solid pin. The anchor points are kept at a fixed distance.

Constructors

Pin 

Fields

pinAnchor1 :: !Position

First anchor.

pinAnchor2 :: !Position

Second anchor.

Instances

Slide joint

data Slide Source

A slide joint is similar to a pin joint, however it has a minimum and a maximum distance.

Constructors

Slide 

Fields

slideAnchor1 :: !Position

First anchor.

slideAnchor2 :: !Position

Second anchor.

slideMinDist :: !Distance

Minimum distance.

slideMaxDist :: !Distance

Maximum distance.

Instances

Pivot joint

data Pivot Source

A pivot joint allows the bodies to pivot around a single point.

Constructors

Pivot1

You may specify the pivot point in world's coordinates (so both bodies should be already in place).

Fields

pivotPos :: !Position

Pivot point in world's coordinates.

Pivot2

Or you may specify the joint as two anchors (on each body's coordinates), removing the need having the bodies already in place.

Fields

pivotAnchor1 :: !Position

First anchor.

pivotAnchor2 :: !Position

Second anchor.

Instances

Groove joint

data Groove Source

A groove joint attaches a point on the second body to a groove in the first one.

Constructors

Groove 

Fields

groovePoints :: !(Position, Position)

Groove, in first body's coordinates.

groovePivot :: !Position

Pivot, in second body's coordinates.

Instances

Gear joint

data Gear Source

A gear joint restricts the bodies movement to be coordinated as if they were attached like dented gears.

Constructors

Gear 

Fields

gearPhase :: !Angle

Phase of the movement.

gearRatio :: !CpFloat

Ratio between the gears.

Instances

Damped spring

data DampedSpring Source

A simple damped spring. Generally this constraint should be used instead of applyDampedSpring.

Constructors

DampedSpring 

Fields

dampedAnchor1 :: !Position

First anchor.

dampedAnchor2 :: !Position

Second anchor.

dampedRestLength :: !Distance

Rest length.

dampedStiffness :: !CpFloat

Stiffness.

dampedDamping :: !Damping

Damping.

Damped rotary spring

data DampedRotarySpring Source

A damped rotary spring constraint.

Constructors

DampedRotarySpring 

Fields

dampedRotRestAngle :: !Angle

Rest angle.

dampedRotStiffness :: !CpFloat

Stiffness.

dampedRotDamping :: !Damping

Damping.

Ratchet joint

data Ratchet Source

A ratchet constraint.

Constructors

Ratchet 

Fields

ratchetPhase :: !CpFloat

Phase.

ratchet :: !CpFloat

Ratchet.

Rotary limit

data RotaryLimit Source

A rotary limit constraints the difference of angle between two bodies.

Constructors

RotaryLimit 

Fields

rotaryMinDist :: Distance

Minimum distance.

rotaryMaxDist :: Distance

Maximum distance.

Simple motor

data SimpleMotor Source

A simple motor that applies opposite impulses to each body. The rate is used to compute the torque.

Constructors

SimpleMotor 

Fields

simpleMotorRate :: CpFloat

Rate.