-- Produced by boxnd-gen; edit the generator, not this file.

module Box2D.Joint
  ( destroy
  , isValid
  , getType
  , getBodyA
  , getBodyB
  , getWorld
  , setLocalFrameA
  , getLocalFrameA
  , getLocalFrameAInto
  , setLocalFrameB
  , getLocalFrameB
  , getLocalFrameBInto
  , setCollideConnected
  , getCollideConnected
  , setUserData
  , getUserData
  , wakeBodies
  , getConstraintForce
  , getConstraintForceInto
  , getConstraintTorque
  , getLinearSeparation
  , getAngularSeparation
  , setConstraintTuning
  , getConstraintTuning
  , setForceThreshold
  , getForceThreshold
  , setTorqueThreshold
  , getTorqueThreshold
  )

  where

import Foreign
import Foreign.C.Types (CBool(..), CInt(..))
import Data.Coerce (coerce)
import Box2D.Id (BodyId(..), JointId(..), WorldId(..))
import Box2D.MathTypes (Transform, Vec2)
import Box2D.Types (JointType(..))

foreign import ccall unsafe "b2DestroyJoint"
  c_b2DestroyJoint :: JointId -> CBool -> IO ()

foreign import ccall unsafe "b2Joint_IsValid"
  c_b2Joint_IsValid :: JointId -> IO CBool

foreign import ccall unsafe "b2Joint_GetType"
  c_b2Joint_GetType :: JointId -> IO CInt

foreign import ccall unsafe "b2Joint_GetBodyA"
  c_b2Joint_GetBodyA :: JointId -> IO BodyId

foreign import ccall unsafe "b2Joint_GetBodyB"
  c_b2Joint_GetBodyB :: JointId -> IO BodyId

foreign import ccall unsafe "b2Joint_GetWorld"
  c_b2Joint_GetWorld :: JointId -> IO WorldId

foreign import ccall unsafe "hsg_b2Joint_SetLocalFrameA"
  c_b2Joint_SetLocalFrameA :: JointId -> Ptr Transform -> IO ()

foreign import ccall unsafe "hsg_b2Joint_GetLocalFrameA"
  c_b2Joint_GetLocalFrameA :: JointId -> Ptr Transform -> IO ()

foreign import ccall unsafe "hsg_b2Joint_SetLocalFrameB"
  c_b2Joint_SetLocalFrameB :: JointId -> Ptr Transform -> IO ()

foreign import ccall unsafe "hsg_b2Joint_GetLocalFrameB"
  c_b2Joint_GetLocalFrameB :: JointId -> Ptr Transform -> IO ()

foreign import ccall unsafe "b2Joint_SetCollideConnected"
  c_b2Joint_SetCollideConnected :: JointId -> CBool -> IO ()

foreign import ccall unsafe "b2Joint_GetCollideConnected"
  c_b2Joint_GetCollideConnected :: JointId -> IO CBool

foreign import ccall unsafe "b2Joint_SetUserData"
  c_b2Joint_SetUserData :: JointId -> Ptr () -> IO ()

foreign import ccall unsafe "b2Joint_GetUserData"
  c_b2Joint_GetUserData :: JointId -> IO (Ptr ())

foreign import ccall unsafe "b2Joint_WakeBodies"
  c_b2Joint_WakeBodies :: JointId -> IO ()

foreign import ccall unsafe "hsg_b2Joint_GetConstraintForce"
  c_b2Joint_GetConstraintForce :: JointId -> Ptr Vec2 -> IO ()

foreign import ccall unsafe "b2Joint_GetConstraintTorque"
  c_b2Joint_GetConstraintTorque :: JointId -> IO Float

foreign import ccall unsafe "b2Joint_GetLinearSeparation"
  c_b2Joint_GetLinearSeparation :: JointId -> IO Float

foreign import ccall unsafe "b2Joint_GetAngularSeparation"
  c_b2Joint_GetAngularSeparation :: JointId -> IO Float

foreign import ccall unsafe "b2Joint_SetConstraintTuning"
  c_b2Joint_SetConstraintTuning :: JointId -> Float -> Float -> IO ()

foreign import ccall unsafe "b2Joint_GetConstraintTuning"
  c_b2Joint_GetConstraintTuning :: JointId -> Ptr Float -> Ptr Float -> IO ()

foreign import ccall unsafe "b2Joint_SetForceThreshold"
  c_b2Joint_SetForceThreshold :: JointId -> Float -> IO ()

foreign import ccall unsafe "b2Joint_GetForceThreshold"
  c_b2Joint_GetForceThreshold :: JointId -> IO Float

foreign import ccall unsafe "b2Joint_SetTorqueThreshold"
  c_b2Joint_SetTorqueThreshold :: JointId -> Float -> IO ()

foreign import ccall unsafe "b2Joint_GetTorqueThreshold"
  c_b2Joint_GetTorqueThreshold :: JointId -> IO Float

{- | Destroy a joint. Optionally wake attached bodies.

Binds @b2DestroyJoint@.
-}
destroy
  :: JointId
  -> Bool
  -- ^ @wakeAttached@
  -> IO ()
destroy :: JointId -> Bool -> IO ()
destroy JointId
a0 Bool
a1 =
  JointId -> CBool -> IO ()
c_b2DestroyJoint JointId
a0 (Bool -> CBool
forall a. Num a => Bool -> a
fromBool Bool
a1)

{- | Joint identifier validation. Provides validation for up to 64K allocations.

Binds @b2Joint_IsValid@.
-}
isValid
  :: JointId
  -> IO Bool
isValid :: JointId -> IO Bool
isValid JointId
a0 =
  CBool -> Bool
forall a. (Eq a, Num a) => a -> Bool
toBool (CBool -> Bool) -> IO CBool -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (JointId -> IO CBool
c_b2Joint_IsValid JointId
a0)

{- | Get the joint type

Binds @b2Joint_GetType@.
-}
getType
  :: JointId
  -> IO JointType
getType :: JointId -> IO JointType
getType JointId
a0 =
  CInt -> JointType
forall a b. Coercible a b => a -> b
coerce (CInt -> JointType) -> IO CInt -> IO JointType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (JointId -> IO CInt
c_b2Joint_GetType JointId
a0)

{- | Get body A id on a joint

Binds @b2Joint_GetBodyA@.
-}
getBodyA
  :: JointId
  -> IO BodyId
getBodyA :: JointId -> IO BodyId
getBodyA JointId
a0 =
  JointId -> IO BodyId
c_b2Joint_GetBodyA JointId
a0

{- | Get body B id on a joint

Binds @b2Joint_GetBodyB@.
-}
getBodyB
  :: JointId
  -> IO BodyId
getBodyB :: JointId -> IO BodyId
getBodyB JointId
a0 =
  JointId -> IO BodyId
c_b2Joint_GetBodyB JointId
a0

{- | Get the world that owns this joint

Binds @b2Joint_GetWorld@.
-}
getWorld
  :: JointId
  -> IO WorldId
getWorld :: JointId -> IO WorldId
getWorld JointId
a0 =
  JointId -> IO WorldId
c_b2Joint_GetWorld JointId
a0

{- | Set the local frame on bodyA

Binds @b2Joint_SetLocalFrameA@.
-}
setLocalFrameA
  :: JointId
  -> Transform
  -- ^ @localFrame@
  -> IO ()
setLocalFrameA :: JointId -> Transform -> IO ()
setLocalFrameA JointId
a0 Transform
a1 =
  Transform -> (Ptr Transform -> IO ()) -> IO ()
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Transform
a1 ((Ptr Transform -> IO ()) -> IO ())
-> (Ptr Transform -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Transform
p1 ->
  JointId -> Ptr Transform -> IO ()
c_b2Joint_SetLocalFrameA JointId
a0 Ptr Transform
p1

{- | Get the local frame on bodyA

Binds @b2Joint_GetLocalFrameA@.
-}
getLocalFrameA
  :: JointId
  -> IO Transform
getLocalFrameA :: JointId -> IO Transform
getLocalFrameA JointId
a0 =
  (Ptr Transform -> IO Transform) -> IO Transform
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Transform -> IO Transform) -> IO Transform)
-> (Ptr Transform -> IO Transform) -> IO Transform
forall a b. (a -> b) -> a -> b
$ \Ptr Transform
pOut -> JointId -> Ptr Transform -> IO ()
c_b2Joint_GetLocalFrameA JointId
a0 Ptr Transform
pOut IO () -> IO Transform -> IO Transform
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Ptr Transform -> IO Transform
forall a. Storable a => Ptr a -> IO a
peek Ptr Transform
pOut

-- | Like 'getLocalFrameA', but the result is written into a caller-supplied buffer.
getLocalFrameAInto
  :: JointId
  -> Ptr Transform
  -- ^ Result buffer.
  -> IO ()
getLocalFrameAInto :: JointId -> Ptr Transform -> IO ()
getLocalFrameAInto JointId
a0 Ptr Transform
out =
  JointId -> Ptr Transform -> IO ()
c_b2Joint_GetLocalFrameA JointId
a0 Ptr Transform
out

{- | Set the local frame on bodyB

Binds @b2Joint_SetLocalFrameB@.
-}
setLocalFrameB
  :: JointId
  -> Transform
  -- ^ @localFrame@
  -> IO ()
setLocalFrameB :: JointId -> Transform -> IO ()
setLocalFrameB JointId
a0 Transform
a1 =
  Transform -> (Ptr Transform -> IO ()) -> IO ()
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Transform
a1 ((Ptr Transform -> IO ()) -> IO ())
-> (Ptr Transform -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Transform
p1 ->
  JointId -> Ptr Transform -> IO ()
c_b2Joint_SetLocalFrameB JointId
a0 Ptr Transform
p1

{- | Get the local frame on bodyB

Binds @b2Joint_GetLocalFrameB@.
-}
getLocalFrameB
  :: JointId
  -> IO Transform
getLocalFrameB :: JointId -> IO Transform
getLocalFrameB JointId
a0 =
  (Ptr Transform -> IO Transform) -> IO Transform
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Transform -> IO Transform) -> IO Transform)
-> (Ptr Transform -> IO Transform) -> IO Transform
forall a b. (a -> b) -> a -> b
$ \Ptr Transform
pOut -> JointId -> Ptr Transform -> IO ()
c_b2Joint_GetLocalFrameB JointId
a0 Ptr Transform
pOut IO () -> IO Transform -> IO Transform
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Ptr Transform -> IO Transform
forall a. Storable a => Ptr a -> IO a
peek Ptr Transform
pOut

-- | Like 'getLocalFrameB', but the result is written into a caller-supplied buffer.
getLocalFrameBInto
  :: JointId
  -> Ptr Transform
  -- ^ Result buffer.
  -> IO ()
getLocalFrameBInto :: JointId -> Ptr Transform -> IO ()
getLocalFrameBInto JointId
a0 Ptr Transform
out =
  JointId -> Ptr Transform -> IO ()
c_b2Joint_GetLocalFrameB JointId
a0 Ptr Transform
out

{- | Toggle collision between connected bodies

Binds @b2Joint_SetCollideConnected@.
-}
setCollideConnected
  :: JointId
  -> Bool
  -- ^ @shouldCollide@
  -> IO ()
setCollideConnected :: JointId -> Bool -> IO ()
setCollideConnected JointId
a0 Bool
a1 =
  JointId -> CBool -> IO ()
c_b2Joint_SetCollideConnected JointId
a0 (Bool -> CBool
forall a. Num a => Bool -> a
fromBool Bool
a1)

{- | Is collision allowed between connected bodies?

Binds @b2Joint_GetCollideConnected@.
-}
getCollideConnected
  :: JointId
  -> IO Bool
getCollideConnected :: JointId -> IO Bool
getCollideConnected JointId
a0 =
  CBool -> Bool
forall a. (Eq a, Num a) => a -> Bool
toBool (CBool -> Bool) -> IO CBool -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (JointId -> IO CBool
c_b2Joint_GetCollideConnected JointId
a0)

{- | Set the user data on a joint

Binds @b2Joint_SetUserData@.
-}
setUserData
  :: JointId
  -> Ptr ()
  -- ^ @userData@
  -> IO ()
setUserData :: JointId -> Ptr () -> IO ()
setUserData JointId
a0 Ptr ()
a1 =
  JointId -> Ptr () -> IO ()
c_b2Joint_SetUserData JointId
a0 Ptr ()
a1

{- | Get the user data on a joint

Binds @b2Joint_GetUserData@.
-}
getUserData
  :: JointId
  -> IO (Ptr ())
getUserData :: JointId -> IO (Ptr ())
getUserData JointId
a0 =
  JointId -> IO (Ptr ())
c_b2Joint_GetUserData JointId
a0

{- | Wake the bodies connect to this joint

Binds @b2Joint_WakeBodies@.
-}
wakeBodies
  :: JointId
  -> IO ()
wakeBodies :: JointId -> IO ()
wakeBodies JointId
a0 =
  JointId -> IO ()
c_b2Joint_WakeBodies JointId
a0

{- | Get the current constraint force for this joint. Usually in Newtons.

Binds @b2Joint_GetConstraintForce@.
-}
getConstraintForce
  :: JointId
  -> IO Vec2
getConstraintForce :: JointId -> IO Vec2
getConstraintForce JointId
a0 =
  (Ptr Vec2 -> IO Vec2) -> IO Vec2
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Vec2 -> IO Vec2) -> IO Vec2)
-> (Ptr Vec2 -> IO Vec2) -> IO Vec2
forall a b. (a -> b) -> a -> b
$ \Ptr Vec2
pOut -> JointId -> Ptr Vec2 -> IO ()
c_b2Joint_GetConstraintForce JointId
a0 Ptr Vec2
pOut IO () -> IO Vec2 -> IO Vec2
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Ptr Vec2 -> IO Vec2
forall a. Storable a => Ptr a -> IO a
peek Ptr Vec2
pOut

-- | Like 'getConstraintForce', but the result is written into a caller-supplied buffer.
getConstraintForceInto
  :: JointId
  -> Ptr Vec2
  -- ^ Result buffer.
  -> IO ()
getConstraintForceInto :: JointId -> Ptr Vec2 -> IO ()
getConstraintForceInto JointId
a0 Ptr Vec2
out =
  JointId -> Ptr Vec2 -> IO ()
c_b2Joint_GetConstraintForce JointId
a0 Ptr Vec2
out

{- | Get the current constraint torque for this joint. Usually in Newton * meters.

Binds @b2Joint_GetConstraintTorque@.
-}
getConstraintTorque
  :: JointId
  -> IO Float
getConstraintTorque :: JointId -> IO Float
getConstraintTorque JointId
a0 =
  JointId -> IO Float
c_b2Joint_GetConstraintTorque JointId
a0

{- | Get the current linear separation error for this joint. Does not consider admissible movement. Usually in meters.

Binds @b2Joint_GetLinearSeparation@.
-}
getLinearSeparation
  :: JointId
  -> IO Float
getLinearSeparation :: JointId -> IO Float
getLinearSeparation JointId
a0 =
  JointId -> IO Float
c_b2Joint_GetLinearSeparation JointId
a0

{- | Get the current angular separation error for this joint. Does not consider admissible movement. Usually in meters.

Binds @b2Joint_GetAngularSeparation@.
-}
getAngularSeparation
  :: JointId
  -> IO Float
getAngularSeparation :: JointId -> IO Float
getAngularSeparation JointId
a0 =
  JointId -> IO Float
c_b2Joint_GetAngularSeparation JointId
a0

{- | Set the joint constraint tuning. Advanced feature.

Binds @b2Joint_SetConstraintTuning@.
-}
setConstraintTuning
  :: JointId
  -- ^ @jointId@: the joint
  -> Float
  -- ^ @hertz@: the stiffness in Hertz (cycles per second)
  -> Float
  -- ^ @dampingRatio@: the non-dimensional damping ratio (one for critical damping)
  -> IO ()
setConstraintTuning :: JointId -> Float -> Float -> IO ()
setConstraintTuning JointId
a0 Float
a1 Float
a2 =
  JointId -> Float -> Float -> IO ()
c_b2Joint_SetConstraintTuning JointId
a0 Float
a1 Float
a2

{- | Get the joint constraint tuning. Advanced feature.

Binds @b2Joint_GetConstraintTuning@.
-}
getConstraintTuning
  :: JointId
  -> Ptr Float
  -- ^ @hertz@
  -> Ptr Float
  -- ^ @dampingRatio@
  -> IO ()
getConstraintTuning :: JointId -> Ptr Float -> Ptr Float -> IO ()
getConstraintTuning JointId
a0 Ptr Float
a1 Ptr Float
a2 =
  JointId -> Ptr Float -> Ptr Float -> IO ()
c_b2Joint_GetConstraintTuning JointId
a0 Ptr Float
a1 Ptr Float
a2

{- | Set the force threshold for joint events (Newtons)

Binds @b2Joint_SetForceThreshold@.
-}
setForceThreshold
  :: JointId
  -> Float
  -- ^ @threshold@
  -> IO ()
setForceThreshold :: JointId -> Float -> IO ()
setForceThreshold JointId
a0 Float
a1 =
  JointId -> Float -> IO ()
c_b2Joint_SetForceThreshold JointId
a0 Float
a1

{- | Get the force threshold for joint events (Newtons)

Binds @b2Joint_GetForceThreshold@.
-}
getForceThreshold
  :: JointId
  -> IO Float
getForceThreshold :: JointId -> IO Float
getForceThreshold JointId
a0 =
  JointId -> IO Float
c_b2Joint_GetForceThreshold JointId
a0

{- | Set the torque threshold for joint events (N-m)

Binds @b2Joint_SetTorqueThreshold@.
-}
setTorqueThreshold
  :: JointId
  -> Float
  -- ^ @threshold@
  -> IO ()
setTorqueThreshold :: JointId -> Float -> IO ()
setTorqueThreshold JointId
a0 Float
a1 =
  JointId -> Float -> IO ()
c_b2Joint_SetTorqueThreshold JointId
a0 Float
a1

{- | Get the torque threshold for joint events (N-m)

Binds @b2Joint_GetTorqueThreshold@.
-}
getTorqueThreshold
  :: JointId
  -> IO Float
getTorqueThreshold :: JointId -> IO Float
getTorqueThreshold JointId
a0 =
  JointId -> IO Float
c_b2Joint_GetTorqueThreshold JointId
a0