{-# LINE 1 "Physics/Hipmunk/Internal.hsc" #-}-----------------------------------------------------------------------------{-# LINE 2 "Physics/Hipmunk/Internal.hsc" #-}-- |-- Module : Physics/Hipmunk/Internal.hsc-- Copyright : (c) 2008-2009 Felipe A. Lessa-- License : MIT (see LICENSE)---- Maintainer : felipe.lessa@gmail.com-- Stability : provisional-- Portability : portable (needs FFI)-------------------------------------------------------------------------------modulePhysics.Hipmunk.Internal(VectorPtr,BodyPtr,Body(..),unB,ShapePtr,Shape(..),unS,ConstraintPtr,Constraint(..),unC,Unknown(..),ConstraintInit,ConstraintType(..),SpacePtr,Space(..),unP,Contact(..),ContactPtr)whereimportData.IORefimportData.Map(Map)importForeign{-# LINE 44 "Physics/Hipmunk/Internal.hsc" #-}importPhysics.Hipmunk.CommontypeVectorPtr=PtrVector-- | 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.newtypeBody=B(ForeignPtrBody)typeBodyPtr=PtrBodyunB::Body->ForeignPtrBodyunB(Bb)=binstanceEqBodywhereBb1==Bb2=b1==b2instanceOrdBodywhereBb1`compare`Bb2=b1`compare`b2-- | A collision shape is attached to a 'Body' to define its-- shape. Multiple shapes may be attached, including-- overlapping ones (shapes of a body don't generate collisions-- with each other).---- Note that to have any effect, a 'Shape' must also be-- added to a 'Space', even if the body was already added.dataShape=S!(ForeignPtrShape)!BodytypeShapePtr=PtrShape-- Note also that we have to maintain a reference to the-- 'Body' to avoid garbage collection in the case that-- the user doesn't add the body to a space and don't keep-- a reference (common when adding bodies with infinite mass).---- However, the body doesn't need to keep references to-- the attached shapes because cpBody do not reference them,-- so it wouldn't notice at all if they disappeared =).-- A space would notice, but then the space will keep its-- own reference the the shape.unS::Shape->ForeignPtrShapeunS(Ss_)=sinstanceEqShapewhereSs1_==Ss2_=s1==s2instanceOrdShapewhereSs1_`compare`Ss2_=s1`compare`s2-- | 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.dataConstrainta=C!(ForeignPtr(Constraint()))!Body!BodytypeConstraintPtr=Ptr(Constraint())unC::Constrainta->ForeignPtr(Constraint())unC(Cj__)=jinstanceEq(Constrainta)whereCj1__==Cj2__=j1==j2instanceOrd(Constrainta)whereCj1__`compare`Cj2__=j1`compare`j2-- | An unknown constraint \"type\". Note that this isn't a-- 'ConstraintType' because you can't create a constraint of-- @Unknown@ type.dataUnknown=Unknown-- | Type of generic constraint initializar.typeConstraintInit=ConstraintPtr->BodyPtr->BodyPtr->IO()-- | Class implemented by all constraint types.classConstraintTypeawheresize::a->Intinit_::a->ConstraintInitredef::ConstraintPtr->Body->Body->a->IO()-- | A space is where the simulation really occurs. You add-- bodies, shapes and constraints to a space and then step it-- to update it as whole.dataSpace=P!(ForeignPtrSpace)!(IORefEntities)-- Active and static entities!(IORefCallbacks)-- Added callbackstypeSpacePtr=PtrSpacetypeEntities=Map(Ptr())(Either(ForeignPtr())Shape)typeCallbacks=(Maybe(FunPtr()),-- DefaultMap(CollisionType_,CollisionType_)(FunPtr()))typeCollisionType_=Word32{-# LINE 143 "Physics/Hipmunk/Internal.hsc" #-}-- Duplicated to avoid bringing the documentation from Shape module.unP::Space->ForeignPtrSpaceunP(Psp__)=spinstanceEqSpacewherePs1__==Ps2__=s1==s2instanceOrdSpacewherePs1__`compare`Ps2__=s1`compare`s2-- 'Contact's are an exception to the pattern we've been following-- as we're going to use StorableArray with them, so we need-- them to be Storable (like Vector).-- | A 'Contact' contains information about a collision.-- It is passed to 'Physics.Hipmunk.Space.Full'.---- The fields 'ctJnAcc' and 'ctJtAcc' do not have any meaningfull-- value until 'Physics.Hipmunk.Space.step' has returned-- (i.e. during a call to a callback this information-- contains garbage), and by extension you can only know-- the impulse sum after @step@ returns as well.---- /IMPORTANT:/ You may maintain a reference to an array of-- @Contact@s that was passed to a callback to do any other-- processing later. However, /a new call to/ @step@ /will/-- /invalidate any of those arrays!/ Be careful.dataContact=Contact{ctPos::Position,-- ^ Position of the collision in world's coordinates.ctNormal::Vector,-- ^ Normal of the collision.ctDist::CpFloat,-- ^ Penetration distance of the collision.ctJnAcc::CpFloat,-- ^ Normal component of final impulse applied.-- (Valid only after @step@ finishes.)ctJtAcc::CpFloat-- ^ Tangential component of final impulse applied.-- (Valid only after @step@ finishes.)}deriving(Eq,Ord,Show)typeContactPtr=PtrContactinstanceStorableContactwheresizeOf_=(132){-# LINE 197 "Physics/Hipmunk/Internal.hsc" #-}alignment_=alignment(undefined::Vector)peekptr=dop<-(\hsc_ptr->peekByteOffhsc_ptr0)ptr{-# LINE 200 "Physics/Hipmunk/Internal.hsc" #-}n<-(\hsc_ptr->peekByteOffhsc_ptr16)ptr{-# LINE 201 "Physics/Hipmunk/Internal.hsc" #-}dist<-(\hsc_ptr->peekByteOffhsc_ptr32)ptr{-# LINE 202 "Physics/Hipmunk/Internal.hsc" #-}jnAcc<-(\hsc_ptr->peekByteOffhsc_ptr96)ptr{-# LINE 203 "Physics/Hipmunk/Internal.hsc" #-}jtAcc<-(\hsc_ptr->peekByteOffhsc_ptr104)ptr{-# LINE 204 "Physics/Hipmunk/Internal.hsc" #-}return$Contact{ctPos=p,ctNormal=n,ctDist=dist,ctJnAcc=jnAcc,ctJtAcc=jtAcc}pokeptrc=do(\hsc_ptr->pokeByteOffhsc_ptr0)ptr(ctPosc){-# LINE 211 "Physics/Hipmunk/Internal.hsc" #-}(\hsc_ptr->pokeByteOffhsc_ptr16)ptr(ctNormalc){-# LINE 212 "Physics/Hipmunk/Internal.hsc" #-}(\hsc_ptr->pokeByteOffhsc_ptr32)ptr(ctDistc){-# LINE 213 "Physics/Hipmunk/Internal.hsc" #-}(\hsc_ptr->pokeByteOffhsc_ptr96)ptr(ctJnAccc){-# LINE 214 "Physics/Hipmunk/Internal.hsc" #-}(\hsc_ptr->pokeByteOffhsc_ptr104)ptr(ctJtAccc){-# LINE 215 "Physics/Hipmunk/Internal.hsc" #-}