module Physics.Hipmunk.Joint
(
Joint,
JointType(..),
newJoint
)
where
import Foreign
import Physics.Hipmunk.Common
import Physics.Hipmunk.Internal
data JointType =
Pin {anchor1, anchor2 :: Position}
| Slide {anchor1, anchor2 :: Position,
minDist, maxDist :: CpFloat}
| Pivot {pivot :: Position}
| Groove {groove1 :: (Position, Position),
pivot2 :: Position}
deriving (Eq, Ord, Show)
newJoint :: Body -> Body -> JointType -> IO Joint
newJoint body1@(B b1) body2@(B b2) (Pin a1 a2) =
withForeignPtr b1 $ \b1_ptr ->
withForeignPtr b2 $ \b2_ptr ->
with a1 $ \a1_ptr ->
with a2 $ \a2_ptr ->
mallocForeignPtrBytes (72) >>= \joint ->
withForeignPtr joint $ \joint_ptr -> do
wrPinJointInit joint_ptr b1_ptr b2_ptr a1_ptr a2_ptr
return (J joint body1 body2)
newJoint body1@(B b1) body2@(B b2) (Slide a1 a2 mn mx) =
withForeignPtr b1 $ \b1_ptr ->
withForeignPtr b2 $ \b2_ptr ->
with a1 $ \a1_ptr ->
with a2 $ \a2_ptr ->
mallocForeignPtrBytes (76) >>= \joint ->
withForeignPtr joint $ \joint_ptr -> do
wrSlideJointInit joint_ptr b1_ptr b2_ptr a1_ptr a2_ptr mn mx
return (J joint body1 body2)
newJoint body1@(B b1) body2@(B b2) (Pivot pos) =
withForeignPtr b1 $ \b1_ptr ->
withForeignPtr b2 $ \b2_ptr ->
with pos $ \pos_ptr ->
mallocForeignPtrBytes (84) >>= \joint ->
withForeignPtr joint $ \joint_ptr -> do
wrPivotJointInit joint_ptr b1_ptr b2_ptr pos_ptr
return (J joint body1 body2)
newJoint body1@(B b1) body2@(B b2) (Groove (g1,g2) anchor) =
withForeignPtr b1 $ \b1_ptr ->
withForeignPtr b2 $ \b2_ptr ->
with g1 $ \g1_ptr ->
with g2 $ \g2_ptr ->
with anchor $ \anchor_ptr ->
mallocForeignPtrBytes (112) >>= \joint ->
withForeignPtr joint $ \joint_ptr -> do
wrGrooveJointInit joint_ptr b1_ptr b2_ptr g1_ptr g2_ptr anchor_ptr
return (J joint body1 body2)
foreign import ccall unsafe "wrapper.h"
wrPinJointInit :: JointPtr -> BodyPtr -> BodyPtr
-> VectorPtr -> VectorPtr -> IO ()
foreign import ccall unsafe "wrapper.h"
wrSlideJointInit :: JointPtr -> BodyPtr -> BodyPtr -> VectorPtr
-> VectorPtr -> CpFloat -> CpFloat -> IO ()
foreign import ccall unsafe "wrapper.h"
wrPivotJointInit :: JointPtr -> BodyPtr -> BodyPtr
-> VectorPtr -> IO ()
foreign import ccall unsafe "wrapper.h"
wrGrooveJointInit :: JointPtr -> BodyPtr -> BodyPtr
-> VectorPtr -> VectorPtr -> VectorPtr -> IO ()