{-# LINE 1 "Physics/Hipmunk/Body.hsc" #-}-----------------------------------------------------------------------------{-# LINE 2 "Physics/Hipmunk/Body.hsc" #-}-- |-- Module : Physics/Hipmunk/Body.hsc-- Copyright : (c) 2008-2010 Felipe A. Lessa-- License : MIT (see LICENSE)---- Maintainer : felipe.lessa@gmail.com-- Stability : provisional-- Portability : portable (needs FFI)---- Rigid bodies and their properties.-------------------------------------------------------------------------------modulePhysics.Hipmunk.Body(-- * CreatingBody,newBody,-- * Static properties-- ** Basic-- *** MassMass,mass,-- *** Moment of inertiaMoment,moment,-- ** Linear components of motion-- *** Positionposition,-- *** VelocityVelocity,velocity,maxVelocity,-- *** ForceForce,force,-- ** Angular components of motion-- *** Angleangle,-- *** Angular velocityAngVel,angVel,maxAngVel,-- *** TorqueTorque,torque,-- * Dynamic propertiesslew,updateVelocity,updatePosition,resetForces,applyForce,applyOnlyForce,applyImpulse,applyDampedSpring,-- * UtilitieslocalToWorld,worldToLocal)whereimportData.StateVarimportForeignhiding(rotate,new){-# LINE 70 "Physics/Hipmunk/Body.hsc" #-}importPhysics.Hipmunk.CommonimportPhysics.Hipmunk.Internal-- | @newBody mass inertia@ creates a new 'Body' with-- the given mass and moment of inertia.---- It is recommended to call 'setPosition' afterwards.newBody::Mass->Moment->IOBodynewBodymass_inertia=dob<-mallocForeignPtrBytes(200){-# LINE 81 "Physics/Hipmunk/Body.hsc" #-}withForeignPtrb$\ptr->docpBodyInitptrmass_inertiareturn(Bb)foreignimportccallunsafe"wrapper.h"cpBodyInit::BodyPtr->CpFloat->CpFloat->IO()typeMass=CpFloatmass::Body->StateVarMassmass(Bb)=makeStateVargettersetterwheregetter=withForeignPtrb(\hsc_ptr->peekByteOffhsc_ptr8){-# LINE 96 "Physics/Hipmunk/Body.hsc" #-}setter=withForeignPtrb.flipcpBodySetMassforeignimportccallunsafe"wrapper.h"cpBodySetMass::BodyPtr->Mass->IO()typeMoment=CpFloatmoment::Body->StateVarMomentmoment(Bb)=makeStateVargettersetterwheregetter=withForeignPtrb(\hsc_ptr->peekByteOffhsc_ptr24){-# LINE 108 "Physics/Hipmunk/Body.hsc" #-}setter=withForeignPtrb.flipcpBodySetMomentforeignimportccallunsafe"wrapper.h"cpBodySetMoment::BodyPtr->CpFloat->IO()angle::Body->StateVarAngleangle(Bb)=makeStateVargettersetterwheregetter=withForeignPtrb(\hsc_ptr->peekByteOffhsc_ptr88){-# LINE 119 "Physics/Hipmunk/Body.hsc" #-}setter=withForeignPtrb.flipcpBodySetAngleforeignimportccallunsafe"wrapper.h"cpBodySetAngle::BodyPtr->CpFloat->IO()-- | Note that using this function to change the position-- on every step is not recommended as it may leave-- the velocity out of sync.position::Body->StateVarPositionposition(Bb)=makeStateVargettersetterwheregetter=withForeignPtrb(\hsc_ptr->peekByteOffhsc_ptr40){-# LINE 133 "Physics/Hipmunk/Body.hsc" #-}setter=withForeignPtrb.flip(\hsc_ptr->pokeByteOffhsc_ptr40){-# LINE 134 "Physics/Hipmunk/Body.hsc" #-}typeVelocity=Vectorvelocity::Body->StateVarVelocityvelocity(Bb)=makeStateVargettersetterwheregetter=withForeignPtrb(\hsc_ptr->peekByteOffhsc_ptr56){-# LINE 142 "Physics/Hipmunk/Body.hsc" #-}setter=withForeignPtrb.flip(\hsc_ptr->pokeByteOffhsc_ptr56){-# LINE 143 "Physics/Hipmunk/Body.hsc" #-}-- | Maximum linear velocity after integrating, defaults to infinity.maxVelocity::Body->StateVarCpFloatmaxVelocity(Bb)=makeStateVargettersetterwheregetter=withForeignPtrb(\hsc_ptr->peekByteOffhsc_ptr132){-# LINE 149 "Physics/Hipmunk/Body.hsc" #-}setter=withForeignPtrb.flip(\hsc_ptr->pokeByteOffhsc_ptr132){-# LINE 150 "Physics/Hipmunk/Body.hsc" #-}typeForce=Vectorforce::Body->StateVarForceforce(Bb)=makeStateVargettersetterwheregetter=withForeignPtrb(\hsc_ptr->peekByteOffhsc_ptr72){-# LINE 159 "Physics/Hipmunk/Body.hsc" #-}setter=withForeignPtrb.flip(\hsc_ptr->pokeByteOffhsc_ptr72){-# LINE 160 "Physics/Hipmunk/Body.hsc" #-}typeAngVel=CpFloatangVel::Body->StateVarAngVelangVel(Bb)=makeStateVargettersetterwheregetter=withForeignPtrb(\hsc_ptr->peekByteOffhsc_ptr96){-# LINE 168 "Physics/Hipmunk/Body.hsc" #-}setter=withForeignPtrb.flip(\hsc_ptr->pokeByteOffhsc_ptr96){-# LINE 169 "Physics/Hipmunk/Body.hsc" #-}-- | Maximum angular velocity after integrating, defaults to infinity.maxAngVel::Body->StateVarCpFloatmaxAngVel(Bb)=makeStateVargettersetterwheregetter=withForeignPtrb(\hsc_ptr->peekByteOffhsc_ptr140){-# LINE 175 "Physics/Hipmunk/Body.hsc" #-}setter=withForeignPtrb.flip(\hsc_ptr->pokeByteOffhsc_ptr140){-# LINE 176 "Physics/Hipmunk/Body.hsc" #-}typeTorque=CpFloattorque::Body->StateVarTorquetorque(Bb)=makeStateVargettersetterwheregetter=withForeignPtrb(\hsc_ptr->peekByteOffhsc_ptr104){-# LINE 185 "Physics/Hipmunk/Body.hsc" #-}setter=withForeignPtrb.flip(\hsc_ptr->pokeByteOffhsc_ptr104){-# LINE 186 "Physics/Hipmunk/Body.hsc" #-}-- | @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!slew::Body->Position->Time->IO()slew(Bb)newposdt=dowithForeignPtrb$\ptr->dop<-(\hsc_ptr->peekByteOffhsc_ptr40)ptr{-# LINE 198 "Physics/Hipmunk/Body.hsc" #-}(\hsc_ptr->pokeByteOffhsc_ptr56)ptr$(newpos-p)`scale`(recipdt){-# LINE 199 "Physics/Hipmunk/Body.hsc" #-}-- | @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.updateVelocity::Body->Vector->Damping->Time->IO()updateVelocity(Bb)gddt=withForeignPtrb$\b_ptr->withg$\g_ptr->dowrBodyUpdateVelocityb_ptrg_ptrddtforeignimportccallunsafe"wrapper.h"wrBodyUpdateVelocity::BodyPtr->VectorPtr->CpFloat->Time->IO()-- | @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).updatePosition::Body->Time->IO()updatePosition(Bb)dt=dowithForeignPtrb$\ptr->docpBodyUpdatePositionptrdtforeignimportccallunsafe"wrapper.h"cpBodyUpdatePosition::BodyPtr->Time->IO()-- | @resetForces b@ redefines as zero all forces and torque-- acting on body @b@.resetForces::Body->IO()resetForcesb=doforceb$=0torqueb$=0-- | @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'.applyForce::Body->Vector->Position->IO()applyForce(Bb)fp=withForeignPtrb$\b_ptr->withf$\f_ptr->withp$\p_ptr->dowrBodyApplyForceb_ptrf_ptrp_ptrforeignimportccallunsafe"wrapper.h"wrBodyApplyForce::BodyPtr->VectorPtr->VectorPtr->IO()-- | @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.applyOnlyForce::Body->Vector->Position->IO()applyOnlyForcebfp=doforceb$=ftorqueb$=p`cross`f-- | @applyImpulse b j r@ applies to the body @b@ the impulse-- @j@ with offset @r@, both vectors in world coordinates.applyImpulse::Body->Vector->Position->IO()applyImpulse(Bb)jr=withForeignPtrb$\b_ptr->withj$\j_ptr->withr$\r_ptr->dowrBodyApplyImpulseb_ptrj_ptrr_ptrforeignimportccallunsafe"wrapper.h"wrBodyApplyImpulse::BodyPtr->VectorPtr->VectorPtr->IO()-- | @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: large damping values can be unstable, you should use-- the damped spring constraint instead.applyDampedSpring::(Body,Position)->(Body,Position)->Distance->CpFloat->Damping->Time->IO()applyDampedSpring(Bb1,a1)(Bb2,a2)rlenkdmpdt=withForeignPtrb1$\b1_ptr->withForeignPtrb2$\b2_ptr->witha1$\a1_ptr->witha2$\a2_ptr->dowrApplyDampedSpringb1_ptrb2_ptra1_ptra2_ptrrlenkdmpdtforeignimportccallunsafe"wrapper.h"wrApplyDampedSpring::BodyPtr->BodyPtr->VectorPtr->VectorPtr->CpFloat->CpFloat->CpFloat->Time->IO()-- | For a vector @p@ in body @b@'s coordinates,-- @localToWorld b p@ returns the corresponding vector-- in world coordinates.localToWorld::Body->Position->IOPositionlocalToWorld(Bb)p=withForeignPtrb$\b_ptr->withp$\p_ptr->dowrBodyLocal2Worldb_ptrp_ptrpeekp_ptrforeignimportccallunsafe"wrapper.h"wrBodyLocal2World::BodyPtr->VectorPtr->IO()-- | For a vector @p@ in world coordinates,-- @worldToLocal b p@ returns the corresponding vector-- in body @b@'s coordinates.worldToLocal::Body->Position->IOPositionworldToLocal(Bb)p=withForeignPtrb$\b_ptr->withp$\p_ptr->dowrBodyWorld2Localb_ptrp_ptrpeekp_ptrforeignimportccallunsafe"wrapper.h"wrBodyWorld2Local::BodyPtr->VectorPtr->IO()