packages feed

Box2D-0.1.0.0: src/Box2D/DistanceJoint.hsc

{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

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

module Box2D.DistanceJoint
  ( DistanceJointDef (..)
  , defaultDistanceJointDef
  , create
  , setRestLength
  , getRestLength
  , enableSpring
  , isSpringEnabled
  , setSpringForceRange
  , getSpringForceRange
  , setSpringHertz
  , setSpringDampingRatio
  , getSpringHertz
  , getSpringDampingRatio
  , getSpringForce
  , enableLimit
  , isLimitEnabled
  , setLimits
  , getLowerLimit
  , getUpperLimit
  , getCurrentLength
  , enableMotor
  , isMotorEnabled
  , setTargetMotorSpeed
  , getTargetMotorSpeed
  , setMaxMotorForce
  , getMaxMotorForce
  , getCurrentMotorForce
  )
  where

import Foreign
import Foreign.C.Types (CBool (..), CInt (..))
import Box2D.Internal (allocaOut)
import Box2D.Id (JointId (..), WorldId (..))
import Box2D.Joint (JointDef)

#include "box2d/box2d.h"


{- | Distance joint definition Connects a point on body A with a point on body B by a segment. Useful
for ropes and springs.
-}
data DistanceJointDef = DistanceJointDef
  { base :: JointDef
  -- ^ Base joint definition
  , length :: Float
  -- ^ The rest length of this joint. Clamped to a stable minimum value.
  , enableSpring :: CBool
  -- ^ Enable the distance constraint to behave like a spring. If false then the distance joint
  -- will be rigid, overriding the limit and motor.
  , lowerSpringForce :: Float
  -- ^ The lower spring force controls how much tension it can sustain.
  , upperSpringForce :: Float
  -- ^ The upper spring force controls how much compression it can sustain.
  , hertz :: Float
  -- ^ The spring linear stiffness Hertz, cycles per second.
  , dampingRatio :: Float
  -- ^ The spring linear damping ratio, non-dimensional
  , enableLimit :: CBool
  -- ^ Enable\/disable the joint limit
  , minLength :: Float
  -- ^ Minimum length for limit. Clamped to a stable minimum value.
  , maxLength :: Float
  -- ^ Maximum length for limit. Must be greater than or equal to the minimum length.
  , enableMotor :: CBool
  -- ^ Enable\/disable the joint motor
  , maxMotorForce :: Float
  -- ^ The maximum motor force, usually in newtons
  , motorSpeed :: Float
  -- ^ The desired motor speed, usually in meters per second
  , internalValue :: CInt
  -- ^ Used internally to detect a valid definition. DO NOT SET.
  }
  deriving (Eq, Show)

instance Storable DistanceJointDef where
  sizeOf _ = #{size b2DistanceJointDef}
  alignment _ = #{alignment b2DistanceJointDef}
  peek p =
    DistanceJointDef
      <$> #{peek b2DistanceJointDef, base} p
      <*> #{peek b2DistanceJointDef, length} p
      <*> #{peek b2DistanceJointDef, enableSpring} p
      <*> #{peek b2DistanceJointDef, lowerSpringForce} p
      <*> #{peek b2DistanceJointDef, upperSpringForce} p
      <*> #{peek b2DistanceJointDef, hertz} p
      <*> #{peek b2DistanceJointDef, dampingRatio} p
      <*> #{peek b2DistanceJointDef, enableLimit} p
      <*> #{peek b2DistanceJointDef, minLength} p
      <*> #{peek b2DistanceJointDef, maxLength} p
      <*> #{peek b2DistanceJointDef, enableMotor} p
      <*> #{peek b2DistanceJointDef, maxMotorForce} p
      <*> #{peek b2DistanceJointDef, motorSpeed} p
      <*> #{peek b2DistanceJointDef, internalValue} p
  poke p (DistanceJointDef f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14) = do
    #{poke b2DistanceJointDef, base} p f1
    #{poke b2DistanceJointDef, length} p f2
    #{poke b2DistanceJointDef, enableSpring} p f3
    #{poke b2DistanceJointDef, lowerSpringForce} p f4
    #{poke b2DistanceJointDef, upperSpringForce} p f5
    #{poke b2DistanceJointDef, hertz} p f6
    #{poke b2DistanceJointDef, dampingRatio} p f7
    #{poke b2DistanceJointDef, enableLimit} p f8
    #{poke b2DistanceJointDef, minLength} p f9
    #{poke b2DistanceJointDef, maxLength} p f10
    #{poke b2DistanceJointDef, enableMotor} p f11
    #{poke b2DistanceJointDef, maxMotorForce} p f12
    #{poke b2DistanceJointDef, motorSpeed} p f13
    #{poke b2DistanceJointDef, internalValue} p f14

foreign import ccall unsafe "hs_b2DefaultDistanceJointDef"
  c_b2DefaultDistanceJointDef :: Ptr DistanceJointDef -> IO ()

defaultDistanceJointDef :: IO DistanceJointDef
defaultDistanceJointDef = allocaOut c_b2DefaultDistanceJointDef


foreign import ccall unsafe "b2CreateDistanceJoint"
  c_b2CreateDistanceJoint :: WorldId -> Ptr DistanceJointDef -> IO JointId

foreign import ccall unsafe "b2DistanceJoint_SetRestLength"
  c_b2DistanceJoint_SetRestLength :: JointId -> Float -> IO ()

foreign import ccall unsafe "b2DistanceJoint_GetRestLength"
  c_b2DistanceJoint_GetRestLength :: JointId -> IO Float

foreign import ccall unsafe "b2DistanceJoint_EnableSpring"
  c_b2DistanceJoint_EnableSpring :: JointId -> CBool -> IO ()

foreign import ccall unsafe "b2DistanceJoint_IsSpringEnabled"
  c_b2DistanceJoint_IsSpringEnabled :: JointId -> IO CBool

foreign import ccall unsafe "b2DistanceJoint_SetSpringForceRange"
  c_b2DistanceJoint_SetSpringForceRange :: JointId -> Float -> Float -> IO ()

foreign import ccall unsafe "b2DistanceJoint_GetSpringForceRange"
  c_b2DistanceJoint_GetSpringForceRange :: JointId -> Ptr Float -> Ptr Float -> IO ()

foreign import ccall unsafe "b2DistanceJoint_SetSpringHertz"
  c_b2DistanceJoint_SetSpringHertz :: JointId -> Float -> IO ()

foreign import ccall unsafe "b2DistanceJoint_SetSpringDampingRatio"
  c_b2DistanceJoint_SetSpringDampingRatio :: JointId -> Float -> IO ()

foreign import ccall unsafe "b2DistanceJoint_GetSpringHertz"
  c_b2DistanceJoint_GetSpringHertz :: JointId -> IO Float

foreign import ccall unsafe "b2DistanceJoint_GetSpringDampingRatio"
  c_b2DistanceJoint_GetSpringDampingRatio :: JointId -> IO Float

foreign import ccall unsafe "b2DistanceJoint_GetSpringForce"
  c_b2DistanceJoint_GetSpringForce :: JointId -> IO Float

foreign import ccall unsafe "b2DistanceJoint_EnableLimit"
  c_b2DistanceJoint_EnableLimit :: JointId -> CBool -> IO ()

foreign import ccall unsafe "b2DistanceJoint_IsLimitEnabled"
  c_b2DistanceJoint_IsLimitEnabled :: JointId -> IO CBool

foreign import ccall unsafe "b2DistanceJoint_SetLimits"
  c_b2DistanceJoint_SetLimits :: JointId -> Float -> Float -> IO ()

foreign import ccall unsafe "b2DistanceJoint_GetLowerLimit"
  c_b2DistanceJoint_GetLowerLimit :: JointId -> IO Float

foreign import ccall unsafe "b2DistanceJoint_GetUpperLimit"
  c_b2DistanceJoint_GetUpperLimit :: JointId -> IO Float

foreign import ccall unsafe "b2DistanceJoint_GetCurrentLength"
  c_b2DistanceJoint_GetCurrentLength :: JointId -> IO Float

foreign import ccall unsafe "b2DistanceJoint_EnableMotor"
  c_b2DistanceJoint_EnableMotor :: JointId -> CBool -> IO ()

foreign import ccall unsafe "b2DistanceJoint_IsMotorEnabled"
  c_b2DistanceJoint_IsMotorEnabled :: JointId -> IO CBool

foreign import ccall unsafe "b2DistanceJoint_SetTargetMotorSpeed"
  c_b2DistanceJoint_SetTargetMotorSpeed :: JointId -> Float -> IO ()

foreign import ccall unsafe "b2DistanceJoint_GetTargetMotorSpeed"
  c_b2DistanceJoint_GetTargetMotorSpeed :: JointId -> IO Float

foreign import ccall unsafe "b2DistanceJoint_SetMaxMotorForce"
  c_b2DistanceJoint_SetMaxMotorForce :: JointId -> Float -> IO ()

foreign import ccall unsafe "b2DistanceJoint_GetMaxMotorForce"
  c_b2DistanceJoint_GetMaxMotorForce :: JointId -> IO Float

foreign import ccall unsafe "b2DistanceJoint_GetCurrentMotorForce"
  c_b2DistanceJoint_GetCurrentMotorForce :: JointId -> IO Float

{- | Create a distance joint

See also @b2DistanceJointDef@ for details.

Binds @b2CreateDistanceJoint@.
-}
create
  :: WorldId
  -> DistanceJointDef
  -> IO JointId
create a0 a1 =
  with a1 $ \p1 ->
  c_b2CreateDistanceJoint a0 p1

{- | Set the rest length of a distance joint

Binds @b2DistanceJoint_SetRestLength@.
-}
setRestLength
  :: JointId
  -- ^ @jointId@: The id for a distance joint
  -> Float
  -- ^ @length@: The new distance joint length
  -> IO ()
setRestLength a0 a1 =
  c_b2DistanceJoint_SetRestLength a0 a1

{- | Get the rest length of a distance joint

Binds @b2DistanceJoint_GetRestLength@.
-}
getRestLength
  :: JointId
  -> IO Float
getRestLength a0 =
  c_b2DistanceJoint_GetRestLength a0

{- | Enable\/disable the distance joint spring. When disabled the distance joint is rigid.

Binds @b2DistanceJoint_EnableSpring@.
-}
enableSpring
  :: JointId
  -> Bool
  -- ^ @enableSpring@
  -> IO ()
enableSpring a0 a1 =
  c_b2DistanceJoint_EnableSpring a0 (fromBool a1)

{- | Is the distance joint spring enabled?

Binds @b2DistanceJoint_IsSpringEnabled@.
-}
isSpringEnabled
  :: JointId
  -> IO Bool
isSpringEnabled a0 =
  toBool <$> (c_b2DistanceJoint_IsSpringEnabled a0)

{- | Set the force range for the spring.

Binds @b2DistanceJoint_SetSpringForceRange@.
-}
setSpringForceRange
  :: JointId
  -> Float
  -- ^ @lowerForce@
  -> Float
  -- ^ @upperForce@
  -> IO ()
setSpringForceRange a0 a1 a2 =
  c_b2DistanceJoint_SetSpringForceRange a0 a1 a2

{- | Get the force range for the spring.

Binds @b2DistanceJoint_GetSpringForceRange@.
-}
getSpringForceRange
  :: JointId
  -> Ptr Float
  -- ^ @lowerForce@
  -> Ptr Float
  -- ^ @upperForce@
  -> IO ()
getSpringForceRange a0 a1 a2 =
  c_b2DistanceJoint_GetSpringForceRange a0 a1 a2

{- | Set the spring stiffness in Hertz

Binds @b2DistanceJoint_SetSpringHertz@.
-}
setSpringHertz
  :: JointId
  -> Float
  -- ^ @hertz@
  -> IO ()
setSpringHertz a0 a1 =
  c_b2DistanceJoint_SetSpringHertz a0 a1

{- | Set the spring damping ratio, non-dimensional

Binds @b2DistanceJoint_SetSpringDampingRatio@.
-}
setSpringDampingRatio
  :: JointId
  -> Float
  -- ^ @dampingRatio@
  -> IO ()
setSpringDampingRatio a0 a1 =
  c_b2DistanceJoint_SetSpringDampingRatio a0 a1

{- | Get the spring Hertz

Binds @b2DistanceJoint_GetSpringHertz@.
-}
getSpringHertz
  :: JointId
  -> IO Float
getSpringHertz a0 =
  c_b2DistanceJoint_GetSpringHertz a0

{- | Get the spring damping ratio

Binds @b2DistanceJoint_GetSpringDampingRatio@.
-}
getSpringDampingRatio
  :: JointId
  -> IO Float
getSpringDampingRatio a0 =
  c_b2DistanceJoint_GetSpringDampingRatio a0

{- | Get the current spring force.

Binds @b2DistanceJoint_GetSpringForce@.
-}
getSpringForce
  :: JointId
  -> IO Float
getSpringForce a0 =
  c_b2DistanceJoint_GetSpringForce a0

{- | Enable joint limit. The limit only works if the joint spring is enabled. Otherwise the joint is
rigid and the limit has no effect.

Binds @b2DistanceJoint_EnableLimit@.
-}
enableLimit
  :: JointId
  -> Bool
  -- ^ @enableLimit@
  -> IO ()
enableLimit a0 a1 =
  c_b2DistanceJoint_EnableLimit a0 (fromBool a1)

{- | Is the distance joint limit enabled?

Binds @b2DistanceJoint_IsLimitEnabled@.
-}
isLimitEnabled
  :: JointId
  -> IO Bool
isLimitEnabled a0 =
  toBool <$> (c_b2DistanceJoint_IsLimitEnabled a0)

{- | Set the minimum and maximum length parameters of a distance joint

Binds @b2DistanceJoint_SetLimits@.
-}
setLimits
  :: JointId
  -> Float
  -- ^ @minLength@
  -> Float
  -- ^ @maxLength@
  -> IO ()
setLimits a0 a1 a2 =
  c_b2DistanceJoint_SetLimits a0 a1 a2

{- | Get the distance joint minimum length

Binds @b2DistanceJoint_GetLowerLimit@.
-}
getLowerLimit
  :: JointId
  -> IO Float
getLowerLimit a0 =
  c_b2DistanceJoint_GetLowerLimit a0

{- | Get the distance joint maximum length

Binds @b2DistanceJoint_GetUpperLimit@.
-}
getUpperLimit
  :: JointId
  -> IO Float
getUpperLimit a0 =
  c_b2DistanceJoint_GetUpperLimit a0

{- | Get the current length of a distance joint

Binds @b2DistanceJoint_GetCurrentLength@.
-}
getCurrentLength
  :: JointId
  -> IO Float
getCurrentLength a0 =
  c_b2DistanceJoint_GetCurrentLength a0

{- | Enable\/disable the distance joint motor

Binds @b2DistanceJoint_EnableMotor@.
-}
enableMotor
  :: JointId
  -> Bool
  -- ^ @enableMotor@
  -> IO ()
enableMotor a0 a1 =
  c_b2DistanceJoint_EnableMotor a0 (fromBool a1)

{- | Is the distance joint motor enabled?

Binds @b2DistanceJoint_IsMotorEnabled@.
-}
isMotorEnabled
  :: JointId
  -> IO Bool
isMotorEnabled a0 =
  toBool <$> (c_b2DistanceJoint_IsMotorEnabled a0)

{- | Set the distance joint motor speed, usually in meters per second

Binds @b2DistanceJoint_SetTargetMotorSpeed@.
-}
setTargetMotorSpeed
  :: JointId
  -> Float
  -- ^ @motorSpeed@
  -> IO ()
setTargetMotorSpeed a0 a1 =
  c_b2DistanceJoint_SetTargetMotorSpeed a0 a1

{- | Get the distance joint motor speed, usually in meters per second

Binds @b2DistanceJoint_GetTargetMotorSpeed@.
-}
getTargetMotorSpeed
  :: JointId
  -> IO Float
getTargetMotorSpeed a0 =
  c_b2DistanceJoint_GetTargetMotorSpeed a0

{- | Set the distance joint maximum motor force, usually in newtons

Binds @b2DistanceJoint_SetMaxMotorForce@.
-}
setMaxMotorForce
  :: JointId
  -> Float
  -- ^ @force@
  -> IO ()
setMaxMotorForce a0 a1 =
  c_b2DistanceJoint_SetMaxMotorForce a0 a1

{- | Get the distance joint maximum motor force, usually in newtons

Binds @b2DistanceJoint_GetMaxMotorForce@.
-}
getMaxMotorForce
  :: JointId
  -> IO Float
getMaxMotorForce a0 =
  c_b2DistanceJoint_GetMaxMotorForce a0

{- | Get the distance joint current motor force, usually in newtons

Binds @b2DistanceJoint_GetCurrentMotorForce@.
-}
getCurrentMotorForce
  :: JointId
  -> IO Float
getCurrentMotorForce a0 =
  c_b2DistanceJoint_GetCurrentMotorForce a0