{-# LINE 1 "Physics/Hipmunk/Common.hsc" #-}{-# CFILES
{-# LINE 2 "Physics/Hipmunk/Common.hsc" #-}
Chipmunk-5.3.4/src/chipmunk.c,
Chipmunk-5.3.4/src/constraints/cpConstraint.c,
Chipmunk-5.3.4/src/constraints/cpDampedRotarySpring.c,
Chipmunk-5.3.4/src/constraints/cpDampedSpring.c,
Chipmunk-5.3.4/src/constraints/cpGearJoint.c,
Chipmunk-5.3.4/src/constraints/cpGrooveJoint.c,
Chipmunk-5.3.4/src/constraints/cpPinJoint.c,
Chipmunk-5.3.4/src/constraints/cpPivotJoint.c,
Chipmunk-5.3.4/src/constraints/cpRatchetJoint.c,
Chipmunk-5.3.4/src/constraints/cpRotaryLimitJoint.c,
Chipmunk-5.3.4/src/constraints/cpSimpleMotor.c,
Chipmunk-5.3.4/src/constraints/cpSlideJoint.c,
Chipmunk-5.3.4/src/cpArbiter.c,
Chipmunk-5.3.4/src/cpArray.c,
Chipmunk-5.3.4/src/cpBB.c,
Chipmunk-5.3.4/src/cpBody.c,
Chipmunk-5.3.4/src/cpCollision.c,
Chipmunk-5.3.4/src/cpHashSet.c,
Chipmunk-5.3.4/src/cpPolyShape.c,
Chipmunk-5.3.4/src/cpShape.c,
Chipmunk-5.3.4/src/cpSpace.c,
Chipmunk-5.3.4/src/cpSpaceComponent.c,
Chipmunk-5.3.4/src/cpSpaceHash.c,
Chipmunk-5.3.4/src/cpSpaceQuery.c,
Chipmunk-5.3.4/src/cpSpaceStep.c,
Chipmunk-5.3.4/src/cpVect.c,
Physics/Hipmunk/wrapper.c #-}------------------------------------------------------------------------------- |-- Module : Physics/Hipmunk/Common.hsc-- Copyright : (c) 2008-2010 Felipe A. Lessa-- License : MIT (see LICENSE)---- Maintainer : felipe.lessa@gmail.com-- Stability : provisional-- Portability : portable (needs FFI)---- Functionality used by various modules and routines for-- initialization and change of global variables.-------------------------------------------------------------------------------modulePhysics.Hipmunk.Common(-- * InitializationinitChipmunk,-- * Basic data typesCpFloat,infinity,Time,Angle,Distance,Damping,-- * Global variables-- $global_vars-- ** Shape counter-- $shape_counterresetShapeCounter,-- ** Contact persistence-- $contact_persistencecontactPersistence,-- ** Collision slop-- $collision_slopcollisionSlop,-- ** Bias coefficient-- $bias_coefBiasCoef,biasCoef,-- ** Constraint bias coefficient-- $constraint_bias_coefconstraintBiasCoef,-- * VectorsVector(..),Position,fromAngle,len,normalize,scale,toAngle,dot,cross,perp,project,rotate,unrotate)whereimportData.StateVarimportForeignhiding(rotate)importForeign.C.Types(CInt){-# LINE 102 "Physics/Hipmunk/Common.hsc" #-}error'::String->aerror'=error.("Physics.Hipmunk.Common: "++)-- | Initilizes the Chipmunk library. This should be called-- once before using any functions of this library.initChipmunk::IO()initChipmunk=cpInitChipmunkforeignimportccallunsafe"wrapper.h"cpInitChipmunk::IO()-- | The floating point type used internally in Chipmunk.typeCpFloat=Double{-# LINE 117 "Physics/Hipmunk/Common.hsc" #-}-- | @infinity@ may be used to create bodies with-- an infinite mass.infinity::CpFloatinfinity=1e1000-- | Type synonym used to hint that the argument or result-- represents time.typeTime=CpFloat-- | Type synonym used to hint that the argument or result-- represents an angle in radians.typeAngle=CpFloat-- | Type synonym used to hint that the argument or result-- represents a distance.typeDistance=CpFloat-- | Type synonym used to hint that the argument or result-- represents a damping constant.typeDamping=CpFloat-- $global_vars-- Chipmunk tries to maintain a very few number of global-- variables to allow multiple @Space@s 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@ 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 you can't add-- shapes created after the call to a space created before it.resetShapeCounter::IO()resetShapeCounter=cpResetShapeIdCounterforeignimportccallunsafe"wrapper.h"cpResetShapeIdCounter::IO()-- $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)contactPersistence::StateVarCIntcontactPersistence=makeStateVarFromPtrcp_contact_persistencemakeStateVarFromPtr::Storablea=>Ptra->StateVaramakeStateVarFromPtrp=makeStateVar(peekp)(pokep)foreignimportccallunsafe"wrapper.h &cp_contact_persistence"cp_contact_persistence::PtrCInt-- $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)collisionSlop::StateVarCpFloatcollisionSlop=makeStateVarFromPtrcp_collision_slopforeignimportccallunsafe"wrapper.h &cp_collision_slop"cp_collision_slop::PtrCpFloat-- $bias_coef-- 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)typeBiasCoef=CpFloatbiasCoef::StateVarBiasCoefbiasCoef=makeStateVarFromPtrcp_bias_coefforeignimportccallunsafe"wrapper.h &cp_bias_coef"cp_bias_coef::PtrCpFloat-- $constraint_bias_coef-- Similar to the bias coefficient, but sets the default bias-- for all constraints. (default is 0.1)constraintBiasCoef::StateVarBiasCoefconstraintBiasCoef=makeStateVarFromPtrcp_constraint_bias_coefforeignimportccallunsafe"wrapper.h &cp_constraint_bias_coef"cp_constraint_bias_coef::PtrCpFloat-- | A two-dimensional vector. It is an instance of 'Num'-- however the operations 'signum' and @(*)@ are not-- supported.dataVector=Vector!CpFloat!CpFloatderiving(Eq,Show,Ord)-- | Type synonym used to hint that the argument or result-- represents a position.typePosition=VectorinstanceNumVectorwhere(Vectorx1y1)+(Vectorx2y2)=Vector(x1+x2)(y1+y2)(Vectorx1y1)-(Vectorx2y2)=Vector(x1-x2)(y1-y2)negate(Vectorx1y1)=Vector(-x1)(-y1)absv=Vector(lenv)0fromIntegern=Vector(fromIntegern)0signum_=error'"signum not supported"_*_=error'"(*) not supported"instanceStorableVectorwheresizeOf_=(16){-# LINE 243 "Physics/Hipmunk/Common.hsc" #-}alignment_=alignment(undefined::CpFloat)peekptr=dox<-(\hsc_ptr->peekByteOffhsc_ptr0)ptr{-# LINE 246 "Physics/Hipmunk/Common.hsc" #-}y<-(\hsc_ptr->peekByteOffhsc_ptr8)ptr{-# LINE 247 "Physics/Hipmunk/Common.hsc" #-}return(Vectorxy)pokeptr(Vectorxy)=do(\hsc_ptr->pokeByteOffhsc_ptr0)ptrx{-# LINE 250 "Physics/Hipmunk/Common.hsc" #-}(\hsc_ptr->pokeByteOffhsc_ptr8)ptry{-# LINE 251 "Physics/Hipmunk/Common.hsc" #-}-- | Constructs an unitary vector pointing to the given-- angle (in radians).fromAngle::Angle->VectorfromAngletheta=Vector(costheta)(sintheta){-# INLINE fromAngle #-}-- | The length of a vector.len::Vector->CpFloatlen(Vectorxy)=sqrt$x*x+y*y{-# INLINE len #-}-- | Normalizes the vector (i.e. divides it by its length).normalize::Vector->Vectornormalizev=v`scale`(recip$lenv){-# INLINE normalize #-}-- | Scales the components of a vector by the same amount.scale::Vector->CpFloat->Vectorscale(Vectorxy)s=Vector(x*s)(y*s){-# INLINE scale #-}-- | @toAngle v@ is the angle that @v@ has-- with the vector @Vector 1 0@ (modulo @2*pi@).toAngle::Vector->AngletoAngle(Vectorxy)=atan2yx{-# INLINE toAngle #-}-- | @v1 \`dot\` v2@ computes the familiar dot operation.dot::Vector->Vector->CpFloatdot(Vectorx1y1)(Vectorx2y2)=x1*x2+y1*y2{-# INLINE dot #-}-- | @v1 \`cross\` v2@ computes the familiar cross operation.cross::Vector->Vector->CpFloatcross(Vectorx1y1)(Vectorx2y2)=x1*y2-y1*x2{-# INLINE cross #-}-- | @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@).perp::Vector->Vectorperp(Vectorxy)=Vector(-y)x{-# INLINE perp #-}-- | @v1 \`project\` v2@ is the vector projection of @v1@ onto @v2@.project::Vector->Vector->Vectorprojectv1v2=v2`scale`swheres=(v1`dot`v2)/(v2`dot`v2){-# INLINE project #-}-- | @v1 \`rotate\` v2@ uses complex multiplication-- to rotate (and scale) @v1@ by @v2@.rotate::Vector->Vector->Vectorrotate(Vectorx1y1)(Vectorx2y2)=Vectorx3y3wherex3=x1*x2-y1*y2y3=x1*y2+y1*x2{-# INLINE rotate #-}-- | The inverse operation of @rotate@, such that-- @unrotate (rotate v1 v2) v2@ equals @v1@.unrotate::Vector->Vector->Vectorunrotate(Vectorx1y1)(Vectorx2y2)=Vectorx3y3wherex3=x1*x2+y1*y2y3=y1*x2-x1*y2{-# INLINE unrotate #-}