Hipmunk-5.0.0: A Haskell binding for Chipmunk.Source codeContentsIndex
Physics.Hipmunk.Common
Portabilityportable (needs FFI)
Stabilityprovisional
Maintainerfelipe.lessa@gmail.com
Contents
Initialization
Basic data types
Global variables
Shape counter
Contact persistence
Collision slop
Bias coefficient
Constraint bias coefficient
Vectors
Description
Functionality used by various modules and routines for initialization and change of global variables.
Synopsis
initChipmunk :: IO ()
type CpFloat = Double
infinity :: CpFloat
type Time = CpFloat
type Angle = CpFloat
type Distance = CpFloat
type Damping = CpFloat
resetShapeCounter :: IO ()
getContactPersistence :: IO CInt
setContactPersistence :: CInt -> IO ()
getCollisionSlop :: IO CpFloat
setCollisionSlop :: CpFloat -> IO ()
type BiasCoef = CpFloat
getBiasCoef :: IO BiasCoef
setBiasCoef :: BiasCoef -> IO ()
getConstraintBiasCoef :: IO BiasCoef
setConstraintBiasCoef :: BiasCoef -> IO ()
data Vector = Vector !CpFloat !CpFloat
type Position = Vector
fromAngle :: Angle -> Vector
len :: Vector -> CpFloat
normalize :: Vector -> Vector
scale :: Vector -> CpFloat -> Vector
toAngle :: Vector -> Angle
dot :: Vector -> Vector -> CpFloat
cross :: Vector -> Vector -> CpFloat
perp :: Vector -> Vector
project :: Vector -> Vector -> Vector
rotate :: Vector -> Vector -> Vector
unrotate :: Vector -> Vector -> Vector
Initialization
initChipmunk :: IO ()Source
Initilizes the Chipmunk library. This should be called once before using any functions of this library.
Basic data types
type CpFloat = DoubleSource
The floating point type used internally in Chipmunk.
infinity :: CpFloatSource
infinity may be used to create bodies with an infinite mass.
type Time = CpFloatSource
Type synonym used to hint that the argument or result represents time.
type Angle = CpFloatSource
Type synonym used to hint that the argument or result represents an angle in radians.
type Distance = CpFloatSource
Type synonym used to hint that the argument or result represents a distance.
type Damping = CpFloatSource
Type synonym used to hint that the argument or result represents a damping constant.
Global variables
Chipmunk tries to maintain a very few number of global variables to allow multiple Spaces to be used simultaneously, however there are some.
Shape counter
The shape counter is a global counter used for creating unique hash identifiers to the shapes.
resetShapeCounter :: IO ()Source

resetShapeCounter reset the shape counter to its default value. This is used to add determinism to a simulation. As the ids created with this counter may affect the order in which the collisions happen, there may be very slight differences in different simulations. It may be very useful to call resetShapeCounter everytime you start a new simulation.

However, be careful as you should not use shapes created before a call to resetCounter with shapes created after it as they may have the same id. This means that can't add shapes created after the call to a space created before it.

Contact persistence
This variable determines how long contacts should persist. It should be small as the cached contacts will only be close for a short time. (default is 3)
getContactPersistence :: IO CIntSource
setContactPersistence :: CInt -> IO ()Source
Collision slop
The collision slop is the amount that shapes are allowed to penetrate. Setting this to zero will work just fine, but using a small positive amount will help prevent oscillating contacts. (default is 0.1)
getCollisionSlop :: IO CpFloatSource
setCollisionSlop :: CpFloat -> IO ()Source
Bias coefficient
The amount of penetration to reduce in each step. Values should range from 0 to 1. Using large values will eliminate penetration in fewer steps, but can cause vibration. (default is 0.1)
type BiasCoef = CpFloatSource
getBiasCoef :: IO BiasCoefSource
setBiasCoef :: BiasCoef -> IO ()Source
Constraint bias coefficient
Similar to the bias coefficient, but sets the default bias for all constraints. (default is 0.1)
getConstraintBiasCoef :: IO BiasCoefSource
setConstraintBiasCoef :: BiasCoef -> IO ()Source
Vectors
data Vector Source
A two-dimensional vector. It is an instance of Num however the operations signum and (*) are not supported.
Constructors
Vector !CpFloat !CpFloat
show/hide Instances
type Position = VectorSource
Type synonym used to hint that the argument or result represents a position.
fromAngle :: Angle -> VectorSource
Constructs an unitary vector pointing to the given angle (in radians).
len :: Vector -> CpFloatSource
The length of a vector.
normalize :: Vector -> VectorSource
Normalizes the vector (i.e. divides it by its length).
scale :: Vector -> CpFloat -> VectorSource
Scales the components of a vector by the same amount.
toAngle :: Vector -> AngleSource
toAngle v is the angle that v has with the vector Vector 1 0 (modulo 2*pi).
dot :: Vector -> Vector -> CpFloatSource
v1 `dot` v2 computes the familiar dot operation.
cross :: Vector -> Vector -> CpFloatSource
v1 `cross` v2 computes the familiar cross operation.
perp :: Vector -> VectorSource
perp v is a vector of same length as v but perpendicular to v (i.e. toAngle (perp v) - toAngle v equals pi/2 modulo 2*pi).
project :: Vector -> Vector -> VectorSource
v1 `project` v2 is the vector projection of v1 onto v2.
rotate :: Vector -> Vector -> VectorSource
v1 `rotate` v2 uses complex multiplication to rotate (and scale) v1 by v2.
unrotate :: Vector -> Vector -> VectorSource
The inverse operation of rotate, such that unrotate (rotate v1 v2) v2 equals v1.
Produced by Haddock version 2.4.2