Box2D
Safe HaskellNone
LanguageGHC2021

Box2D.Body

Synopsis

Documentation

create :: WorldId -> BodyDef -> IO BodyId Source #

Create a rigid body given a definition. No reference to the definition is retained. So you can create the definition on the stack and pass it as a pointer. b2BodyDef bodyDef = b2DefaultBodyDef(); b2BodyId myBodyId = b2CreateBody(myWorldId, &bodyDef); Warning: This function is locked during callbacks.

Binds b2CreateBody.

destroy :: BodyId -> IO () Source #

Destroy a rigid body given an id. This destroys all shapes and joints attached to the body. Do not keep references to the associated shapes and joints.

Binds b2DestroyBody.

isValid :: BodyId -> IO Bool Source #

Body identifier validation. A valid body exists in a world and is non-null. This can be used to detect orphaned ids. Provides validation for up to 64K allocations.

Binds b2Body_IsValid.

getType :: BodyId -> IO BodyType Source #

Get the body type: static, kinematic, or dynamic

Binds b2Body_GetType.

setType :: BodyId -> BodyType -> IO () Source #

Change the body type. This is an expensive operation. This automatically updates the mass properties regardless of the automatic mass setting.

Binds b2Body_SetType.

setName Source #

Arguments

:: BodyId 
-> CString
name
-> IO () 

Set the body name. Up to 31 characters excluding 0 termination.

Binds b2Body_SetName.

getName :: BodyId -> IO CString Source #

Get the body name.

Binds b2Body_GetName.

setUserData Source #

Arguments

:: BodyId 
-> Ptr ()
userData
-> IO () 

Set the user data for a body

Binds b2Body_SetUserData.

getUserData :: BodyId -> IO (Ptr ()) Source #

Get the user data stored in a body

Binds b2Body_GetUserData.

getPosition :: BodyId -> IO Pos Source #

Get the world position of a body. This is the location of the body origin.

Binds b2Body_GetPosition.

getPositionInto Source #

Arguments

:: BodyId 
-> Ptr Pos

Result buffer.

-> IO () 

Like getPosition, but the result is written into a caller-supplied buffer.

getRotation :: BodyId -> IO Rot Source #

Get the world rotation of a body as a cosine/sine pair (complex number)

Binds b2Body_GetRotation.

getRotationInto Source #

Arguments

:: BodyId 
-> Ptr Rot

Result buffer.

-> IO () 

Like getRotation, but the result is written into a caller-supplied buffer.

getTransform :: BodyId -> IO WorldTransform Source #

Get the world transform of a body.

Binds b2Body_GetTransform.

getTransformInto Source #

Arguments

:: BodyId 
-> Ptr WorldTransform

Result buffer.

-> IO () 

Like getTransform, but the result is written into a caller-supplied buffer.

setTransform Source #

Arguments

:: BodyId 
-> Pos
position
-> Rot
rotation
-> IO () 

Set the world transform of a body. This acts as a teleport and is fairly expensive. Note: Generally you should create a body with then intended transform. See also b2BodyDef::position and b2BodyDef::rotation.

Binds b2Body_SetTransform.

getLocalPoint Source #

Arguments

:: BodyId 
-> Pos
worldPoint
-> IO Vec2 

Get a local point on a body given a world point

Binds b2Body_GetLocalPoint.

getWorldPoint Source #

Arguments

:: BodyId 
-> Vec2
localPoint
-> IO Pos 

Get a world point on a body given a local point

Binds b2Body_GetWorldPoint.

getLocalVector Source #

Arguments

:: BodyId 
-> Vec2
worldVector
-> IO Vec2 

Get a local vector on a body given a world vector

Binds b2Body_GetLocalVector.

getWorldVector Source #

Arguments

:: BodyId 
-> Vec2
localVector
-> IO Vec2 

Get a world vector on a body given a local vector

Binds b2Body_GetWorldVector.

getLinearVelocity :: BodyId -> IO Vec2 Source #

Get the linear velocity of a body's center of mass. Usually in meters per second.

Binds b2Body_GetLinearVelocity.

getLinearVelocityInto Source #

Arguments

:: BodyId 
-> Ptr Vec2

Result buffer.

-> IO () 

Like getLinearVelocity, but the result is written into a caller-supplied buffer.

getAngularVelocity :: BodyId -> IO Float Source #

Get the angular velocity of a body in radians per second

Binds b2Body_GetAngularVelocity.

setLinearVelocity Source #

Arguments

:: BodyId 
-> Vec2
linearVelocity
-> IO () 

Set the linear velocity of a body. Usually in meters per second.

Binds b2Body_SetLinearVelocity.

setAngularVelocity Source #

Arguments

:: BodyId 
-> Float
angularVelocity
-> IO () 

Set the angular velocity of a body in radians per second

Binds b2Body_SetAngularVelocity.

setTargetTransform Source #

Arguments

:: BodyId

bodyId: The body id

-> WorldTransform

target: The target transform for the body

-> Float

timeStep: The time step of the next call to b2World_Step

-> Bool

wake: Option to wake the body or not

-> IO () 

Set the velocity to reach the given transform after a given time step. The result will be close but maybe not exact. This is meant for kinematic bodies. The target is not applied if the velocity would be below the sleep threshold and the body is currently asleep.

Binds b2Body_SetTargetTransform.

getLocalPointVelocity Source #

Arguments

:: BodyId 
-> Vec2
localPoint
-> IO Vec2 

Get the linear velocity of a local point attached to a body. Usually in meters per second.

Binds b2Body_GetLocalPointVelocity.

getWorldPointVelocity Source #

Arguments

:: BodyId 
-> Pos
worldPoint
-> IO Vec2 

Get the linear velocity of a world point attached to a body. Usually in meters per second.

Binds b2Body_GetWorldPointVelocity.

applyForce Source #

Arguments

:: BodyId

bodyId: The body id

-> Vec2

force: The world force vector, usually in newtons (N)

-> Pos

point: The world position of the point of application

-> Bool

wake: Option to wake up the body

-> IO () 

Apply a force at a world point. If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity. This optionally wakes up the body. The force is ignored if the body is not awake.

Binds b2Body_ApplyForce.

applyForceToCenter Source #

Arguments

:: BodyId

bodyId: The body id

-> Vec2

force: the world force vector, usually in newtons (N).

-> Bool

wake: also wake up the body

-> IO () 

Apply a force to the center of mass. This optionally wakes up the body. The force is ignored if the body is not awake.

Binds b2Body_ApplyForceToCenter.

applyTorque Source #

Arguments

:: BodyId

bodyId: The body id

-> Float

torque: about the z-axis (out of the screen), usually in N*m.

-> Bool

wake: also wake up the body

-> IO () 

Apply a torque. This affects the angular velocity without affecting the linear velocity. This optionally wakes the body. The torque is ignored if the body is not awake.

Binds b2Body_ApplyTorque.

clearForces Source #

Arguments

:: BodyId

bodyId: The body id

-> IO () 

Clear the force and torque on this body. Forces and torques are automatically cleared after each world step. So this only needs to be called if the application wants to remove the effect of previous calls to apply forces and torques before the world step is called.

Binds b2Body_ClearForces.

applyLinearImpulse Source #

Arguments

:: BodyId

bodyId: The body id

-> Vec2

impulse: the world impulse vector, usually in N*s or kg*m/s.

-> Pos

point: the world position of the point of application.

-> Bool

wake: also wake up the body

-> IO () 

Apply an impulse at a point. This immediately modifies the velocity. It also modifies the angular velocity if the point of application is not at the center of mass. This optionally wakes the body. The impulse is ignored if the body is not awake. Warning: This should be used for one-shot impulses. If you need a steady force, use a force instead, which will work better with the sub-stepping solver.

Binds b2Body_ApplyLinearImpulse.

applyLinearImpulseToCenter Source #

Arguments

:: BodyId

bodyId: The body id

-> Vec2

impulse: the world impulse vector, usually in N*s or kg*m/s.

-> Bool

wake: also wake up the body

-> IO () 

Apply an impulse to the center of mass. This immediately modifies the velocity. The impulse is ignored if the body is not awake. This optionally wakes the body. Warning: This should be used for one-shot impulses. If you need a steady force, use a force instead, which will work better with the sub-stepping solver.

Binds b2Body_ApplyLinearImpulseToCenter.

applyAngularImpulse Source #

Arguments

:: BodyId

bodyId: The body id

-> Float

impulse: the angular impulse, usually in units of kg*m*m/s

-> Bool

wake: also wake up the body

-> IO () 

Apply an angular impulse. The impulse is ignored if the body is not awake. This optionally wakes the body. Warning: This should be used for one-shot impulses. If you need a steady torque, use a torque instead, which will work better with the sub-stepping solver.

Binds b2Body_ApplyAngularImpulse.

getMass :: BodyId -> IO Float Source #

Get the mass of the body, usually in kilograms

Binds b2Body_GetMass.

getRotationalInertia :: BodyId -> IO Float Source #

Get the rotational inertia of the body, usually in kg*m^2

Binds b2Body_GetRotationalInertia.

getLocalCenter :: BodyId -> IO Vec2 Source #

Get the center of mass position of the body in local space.

Binds b2Body_GetLocalCenter.

getLocalCenterInto Source #

Arguments

:: BodyId 
-> Ptr Vec2

Result buffer.

-> IO () 

Like getLocalCenter, but the result is written into a caller-supplied buffer.

getWorldCenter :: BodyId -> IO Pos Source #

Get the center of mass position of the body in world space.

Binds b2Body_GetWorldCenter.

getWorldCenterInto Source #

Arguments

:: BodyId 
-> Ptr Pos

Result buffer.

-> IO () 

Like getWorldCenter, but the result is written into a caller-supplied buffer.

setMassData :: BodyId -> MassData -> IO () Source #

Override the body's mass properties. Normally this is computed automatically using the shape geometry and density. This information is lost if a shape is added or removed or if the body type changes.

Binds b2Body_SetMassData.

getMassData :: BodyId -> IO MassData Source #

Get the mass data for a body

Binds b2Body_GetMassData.

getMassDataInto Source #

Arguments

:: BodyId 
-> Ptr MassData

Result buffer.

-> IO () 

Like getMassData, but the result is written into a caller-supplied buffer.

applyMassFromShapes :: BodyId -> IO () Source #

This updates the mass properties to the sum of the mass properties of the shapes. This normally does not need to be called unless you called SetMassData to override the mass and you later want to reset the mass. You may also use this when automatic mass computation has been disabled. You should call this regardless of body type. Note that sensor shapes may have mass.

Binds b2Body_ApplyMassFromShapes.

setLinearDamping Source #

Arguments

:: BodyId 
-> Float
linearDamping
-> IO () 

Adjust the linear damping. Normally this is set in b2BodyDef before creation.

Binds b2Body_SetLinearDamping.

getLinearDamping :: BodyId -> IO Float Source #

Get the current linear damping.

Binds b2Body_GetLinearDamping.

setAngularDamping Source #

Arguments

:: BodyId 
-> Float
angularDamping
-> IO () 

Adjust the angular damping. Normally this is set in b2BodyDef before creation.

Binds b2Body_SetAngularDamping.

getAngularDamping :: BodyId -> IO Float Source #

Get the current angular damping.

Binds b2Body_GetAngularDamping.

setGravityScale Source #

Arguments

:: BodyId 
-> Float
gravityScale
-> IO () 

Adjust the gravity scale. Normally this is set in b2BodyDef before creation. See also b2BodyDef::gravityScale.

Binds b2Body_SetGravityScale.

getGravityScale :: BodyId -> IO Float Source #

Get the current gravity scale

Binds b2Body_GetGravityScale.

isAwake :: BodyId -> IO Bool Source #

Returns: true if this body is awake

Binds b2Body_IsAwake.

setAwake Source #

Arguments

:: BodyId 
-> Bool
awake
-> IO () 

Wake a body from sleep. This wakes the entire island the body is touching. Warning: Putting a body to sleep will put the entire island of bodies touching this body to sleep, which can be expensive and possibly unintuitive.

Binds b2Body_SetAwake.

wakeTouching :: BodyId -> IO () Source #

Wake bodies touching this body. Works for static bodies.

Binds b2Body_WakeTouching.

enableSleep Source #

Arguments

:: BodyId 
-> Bool
enableSleep
-> IO () 

Enable or disable sleeping for this body. If sleeping is disabled the body will wake (and the entire island).

Binds b2Body_EnableSleep.

isSleepEnabled :: BodyId -> IO Bool Source #

Returns true if sleeping is enabled for this body

Binds b2Body_IsSleepEnabled.

setSleepThreshold Source #

Arguments

:: BodyId 
-> Float
sleepThreshold
-> IO () 

Set the sleep threshold, usually in meters per second

Binds b2Body_SetSleepThreshold.

getSleepThreshold :: BodyId -> IO Float Source #

Get the sleep threshold, usually in meters per second.

Binds b2Body_GetSleepThreshold.

isEnabled :: BodyId -> IO Bool Source #

Returns true if this body is enabled

Binds b2Body_IsEnabled.

disable :: BodyId -> IO () Source #

Disable a body by removing it completely from the simulation. This is expensive.

Binds b2Body_Disable.

enable :: BodyId -> IO () Source #

Enable a body by adding it to the simulation. This is expensive.

Binds b2Body_Enable.

setMotionLocks :: BodyId -> MotionLocks -> IO () Source #

Set the motion locks on this body.

Binds b2Body_SetMotionLocks.

getMotionLocks :: BodyId -> IO MotionLocks Source #

Get the motion locks for this body.

Binds b2Body_GetMotionLocks.

getMotionLocksInto Source #

Arguments

:: BodyId 
-> Ptr MotionLocks

Result buffer.

-> IO () 

Like getMotionLocks, but the result is written into a caller-supplied buffer.

setBullet Source #

Arguments

:: BodyId 
-> Bool
flag
-> IO () 

Set this body to be a bullet. A bullet does continuous collision detection against dynamic bodies (but not other bullets).

Binds b2Body_SetBullet.

isBullet :: BodyId -> IO Bool Source #

Is this body a bullet?

Binds b2Body_IsBullet.

enableContactRecycling Source #

Arguments

:: BodyId 
-> Bool
flag
-> IO () 

Enable or disable contact recycling for this body. Contact recycling is a performance optimization that reuses contact manifolds when bodies move slightly. Disabling it can avoid ghost collisions on characters at the cost of higher per-step work. Existing contacts retain their prior setting; only contacts created after this call see the new value. See also b2BodyDef::enableContactRecycling.

Binds b2Body_EnableContactRecycling.

isContactRecyclingEnabled :: BodyId -> IO Bool Source #

Is contact recycling enabled on this body?

Binds b2Body_IsContactRecyclingEnabled.

enableContactEvents Source #

Arguments

:: BodyId 
-> Bool
flag
-> IO () 

Enable/disable contact events on all shapes. See also b2ShapeDef::enableContactEvents. Warning: changing this at runtime may cause mismatched begin/end touch events

Binds b2Body_EnableContactEvents.

enableHitEvents Source #

Arguments

:: BodyId 
-> Bool
flag
-> IO () 

Enable/disable hit events on all shapes See also b2ShapeDef::enableHitEvents.

Binds b2Body_EnableHitEvents.

getWorld :: BodyId -> IO WorldId Source #

Get the world that owns this body

Binds b2Body_GetWorld.

getShapeCount :: BodyId -> IO Int Source #

Get the number of shapes on this body

Binds b2Body_GetShapeCount.

getShapes Source #

Arguments

:: BodyId 
-> Ptr ShapeId
shapeArray
-> Int
capacity
-> IO Int 

Get the shape ids for all shapes on this body, up to the provided capacity.

Returns: the number of shape ids stored in the user array

Binds b2Body_GetShapes.

getJointCount :: BodyId -> IO Int Source #

Get the number of joints on this body

Binds b2Body_GetJointCount.

getJoints Source #

Arguments

:: BodyId 
-> Ptr JointId
jointArray
-> Int
capacity
-> IO Int 

Get the joint ids for all joints on this body, up to the provided capacity

Returns: the number of joint ids stored in the user array

Binds b2Body_GetJoints.

getContactCapacity :: BodyId -> IO Int Source #

Get the maximum capacity required for retrieving all the touching contacts on a body

Binds b2Body_GetContactCapacity.

getContactData Source #

Arguments

:: BodyId 
-> Ptr ContactData 
-> Int
capacity
-> IO Int 

Get the touching contact data for a body. Note: Box2D uses speculative collision so some contact points may be separated. Warning: do not ignore the return value, it specifies the valid number of elements

Returns: the number of elements filled in the provided array

Binds b2Body_GetContactData.

computeAABB :: BodyId -> IO AABB Source #

Get the current world AABB that contains all the attached shapes. Note that this may not encompass the body origin. If there are no shapes attached then the returned AABB is empty and centered on the body origin.

Binds b2Body_ComputeAABB.

computeAABBInto Source #

Arguments

:: BodyId 
-> Ptr AABB

Result buffer.

-> IO () 

Like computeAABB, but the result is written into a caller-supplied buffer.