Box2D
Safe HaskellNone
LanguageGHC2021

Box2D.World

Synopsis

Documentation

create :: WorldDef -> IO WorldId Source #

Create a world for rigid body simulation. A world contains bodies, shapes, and constraints. You make create up to 128 worlds. Each world is completely independent and may be simulated in parallel.

Returns: the world id.

Binds b2CreateWorld.

destroy :: WorldId -> IO () Source #

Destroy a world

Binds b2DestroyWorld.

isValid :: WorldId -> IO Bool Source #

World id validation. Provides validation for up to 64K allocations.

Binds b2World_IsValid.

step Source #

Arguments

:: WorldId

worldId: The world to simulate

-> Float

timeStep: The amount of time to simulate, this should be a fixed number. Usually 1/60.

-> Int

subStepCount: The number of sub-steps, increasing the sub-step count can increase accuracy. Usually 4.

-> IO () 

Simulate a world for one time step. This performs collision detection, integration, and constraint solution.

Binds b2World_Step.

draw :: WorldId -> Ptr DebugDraw -> IO () Source #

Call this to draw shapes and other debug draw data

Binds b2World_Draw.

getBounds :: WorldId -> IO AABB Source #

Call this to get the world bounds based on the union of all shape bounds.

Binds b2World_GetBounds.

getBoundsInto Source #

Arguments

:: WorldId 
-> Ptr AABB

Result buffer.

-> IO () 

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

getBodyEvents :: WorldId -> IO BodyEvents Source #

Get the body events for the current time step. The event data is transient. Do not store a reference to this data.

Binds b2World_GetBodyEvents.

getBodyEventsInto Source #

Arguments

:: WorldId 
-> Ptr BodyEvents

Result buffer.

-> IO () 

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

getSensorEvents :: WorldId -> IO SensorEvents Source #

Get sensor events for the current time step. The event data is transient. Do not store a reference to this data.

Binds b2World_GetSensorEvents.

getSensorEventsInto Source #

Arguments

:: WorldId 
-> Ptr SensorEvents

Result buffer.

-> IO () 

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

getContactEvents :: WorldId -> IO ContactEvents Source #

Get contact events for this current time step. The event data is transient. Do not store a reference to this data.

Binds b2World_GetContactEvents.

getContactEventsInto Source #

Arguments

:: WorldId 
-> Ptr ContactEvents

Result buffer.

-> IO () 

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

getJointEvents :: WorldId -> IO JointEvents Source #

Get the joint events for the current time step. The event data is transient. Do not store a reference to this data.

Binds b2World_GetJointEvents.

getJointEventsInto Source #

Arguments

:: WorldId 
-> Ptr JointEvents

Result buffer.

-> IO () 

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

overlapAABB Source #

Arguments

:: WorldId 
-> Pos
origin
-> AABB 
-> QueryFilter 
-> FunPtr OverlapResultFcn 
-> Ptr ()
context
-> IO TreeStats 

Overlap test for all shapes that *potentially* overlap the provided AABB. The AABB is relative to the origin, which keeps the test precise far from the world origin in large world mode. Near the origin pass b2Pos_zero and a world AABB.

Binds b2World_OverlapAABB.

overlapShape Source #

Arguments

:: WorldId 
-> Pos
origin
-> Ptr ShapeProxy 
-> QueryFilter 
-> FunPtr OverlapResultFcn 
-> Ptr ()
context
-> IO TreeStats 

Overlap test for all shapes that overlap the provided shape proxy. The proxy points are relative to the origin. Near the origin pass b2Pos_zero and world points.

Binds b2World_OverlapShape.

castRay Source #

Arguments

:: WorldId

worldId: The world to cast the ray against

-> Pos

origin: The start point of the ray

-> Vec2

translation: The translation of the ray from the start point to the end point

-> QueryFilter

filter: Contains bit flags to filter unwanted shapes from the results

-> FunPtr CastResultFcn

fcn: A user implemented callback function

-> Ptr ()

context: A user context that is passed along to the callback function

-> IO TreeStats 

Cast a ray into the world to collect shapes in the path of the ray. Your callback function controls whether you get the closest point, any point, or n-points. Note: The callback function may receive shapes in any order

Returns: traversal performance counters

Binds b2World_CastRay.

castRayClosest Source #

Arguments

:: WorldId 
-> Pos
origin
-> Vec2
translation
-> QueryFilter 
-> IO RayResult 

Cast a ray into the world to collect the closest hit. This is a convenience function. Ignores initial overlap. This is less general than b2World_CastRay() and does not allow for custom filtering.

Binds b2World_CastRayClosest.

castShape Source #

Arguments

:: WorldId 
-> Pos
origin
-> Ptr ShapeProxy 
-> Vec2
translation
-> QueryFilter 
-> FunPtr CastResultFcn 
-> Ptr ()
context
-> IO TreeStats 

Cast a shape through the world. Similar to a cast ray except that a shape is cast instead of a point. The proxy points are relative to the origin. Callback points are world positions. See also b2World_CastRay.

Binds b2World_CastShape.

castMover Source #

Arguments

:: WorldId 
-> Pos
origin
-> Capsule
mover
-> Vec2
translation
-> QueryFilter 
-> IO Float 

Cast a capsule mover through the world. This is a special shape cast that handles sliding along other shapes while reducing clipping. The mover capsule is relative to the origin. Near the origin pass b2Pos_zero and a world capsule.

Binds b2World_CastMover.

collideMover Source #

Arguments

:: WorldId 
-> Pos
origin
-> Capsule
mover
-> QueryFilter 
-> FunPtr PlaneResultFcn 
-> Ptr ()
context
-> IO () 

Collide a capsule mover with the world, gathering collision planes that can be fed to b2SolvePlanes. Useful for kinematic character movement. The mover capsule and the resulting planes are relative to the origin.

Binds b2World_CollideMover.

enableSleeping Source #

Arguments

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

Enable/disable sleep. If your application does not need sleeping, you can gain some performance by disabling sleep completely at the world level. See also b2WorldDef.

Binds b2World_EnableSleeping.

isSleepingEnabled :: WorldId -> IO Bool Source #

Is body sleeping enabled?

Binds b2World_IsSleepingEnabled.

enableContinuous Source #

Arguments

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

Enable/disable continuous collision between dynamic and static bodies. Generally you should keep continuous collision enabled to prevent fast moving objects from going through static objects. The performance gain from disabling continuous collision is minor. See also b2WorldDef.

Binds b2World_EnableContinuous.

isContinuousEnabled :: WorldId -> IO Bool Source #

Is continuous collision enabled?

Binds b2World_IsContinuousEnabled.

setRestitutionThreshold Source #

Arguments

:: WorldId 
-> Float
value
-> IO () 

Adjust the restitution threshold. It is recommended not to make this value very small because it will prevent bodies from sleeping. Usually in meters per second. See also b2WorldDef.

Binds b2World_SetRestitutionThreshold.

getRestitutionThreshold :: WorldId -> IO Float Source #

Get the the restitution speed threshold. Usually in meters per second.

Binds b2World_GetRestitutionThreshold.

setHitEventThreshold Source #

Arguments

:: WorldId 
-> Float
value
-> IO () 

Adjust the hit event threshold. This controls the collision speed needed to generate a b2ContactHitEvent. Usually in meters per second. See also b2WorldDef::hitEventThreshold.

Binds b2World_SetHitEventThreshold.

getHitEventThreshold :: WorldId -> IO Float Source #

Get the the hit event speed threshold. Usually in meters per second.

Binds b2World_GetHitEventThreshold.

setCustomFilterCallback Source #

Arguments

:: WorldId 
-> FunPtr CustomFilterFcn 
-> Ptr ()
context
-> IO () 

Register the custom filter callback. This is optional.

Binds b2World_SetCustomFilterCallback.

setPreSolveCallback Source #

Arguments

:: WorldId 
-> FunPtr PreSolveFcn 
-> Ptr ()
context
-> IO () 

Register the pre-solve callback. This is optional.

Binds b2World_SetPreSolveCallback.

setGravity Source #

Arguments

:: WorldId 
-> Vec2
gravity
-> IO () 

Set the gravity vector for the entire world. Box2D has no concept of an up direction and this is left as a decision for the application. Usually in m/s^2. See also b2WorldDef.

Binds b2World_SetGravity.

getGravity :: WorldId -> IO Vec2 Source #

Get the gravity vector

Binds b2World_GetGravity.

getGravityInto Source #

Arguments

:: WorldId 
-> Ptr Vec2

Result buffer.

-> IO () 

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

explode Source #

Arguments

:: WorldId

worldId: The world id

-> ExplosionDef

explosionDef: The explosion definition

-> IO () 

Apply a radial explosion

Binds b2World_Explode.

setContactTuning Source #

Arguments

:: WorldId

worldId: The world id

-> Float

hertz: The contact stiffness (cycles per second)

-> Float

dampingRatio: The contact bounciness with 1 being critical damping (non-dimensional)

-> Float

pushSpeed: The maximum contact constraint push out speed (meters per second)

-> IO () 

Adjust contact tuning parameters Note: Advanced feature

Binds b2World_SetContactTuning.

setContactRecycleDistance Source #

Arguments

:: WorldId 
-> Float
recycleDistance
-> IO () 

Set the contact point recycling distance. Setting this to zero disables contact point recycling. Usually in meters.

Binds b2World_SetContactRecycleDistance.

getContactRecycleDistance :: WorldId -> IO Float Source #

Get the contact point recycling distance. Usually in meters.

Binds b2World_GetContactRecycleDistance.

setMaximumLinearSpeed Source #

Arguments

:: WorldId 
-> Float
maximumLinearSpeed
-> IO () 

Set the maximum linear speed. Usually in m/s.

Binds b2World_SetMaximumLinearSpeed.

getMaximumLinearSpeed :: WorldId -> IO Float Source #

Get the maximum linear speed. Usually in m/s.

Binds b2World_GetMaximumLinearSpeed.

enableWarmStarting Source #

Arguments

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

Enable/disable constraint warm starting. Advanced feature for testing. Disabling warm starting greatly reduces stability and provides no performance gain.

Binds b2World_EnableWarmStarting.

isWarmStartingEnabled :: WorldId -> IO Bool Source #

Is constraint warm starting enabled?

Binds b2World_IsWarmStartingEnabled.

getAwakeBodyCount :: WorldId -> IO Int Source #

Get the number of awake bodies.

Binds b2World_GetAwakeBodyCount.

getProfile Source #

Arguments

:: WorldId 
-> Ptr Profile

Result buffer.

-> IO () 

Get the current world performance profile

Binds b2World_GetProfile.

getCounters Source #

Arguments

:: WorldId 
-> Ptr Counters

Result buffer.

-> IO () 

Get world counters and sizes

Binds b2World_GetCounters.

getMaxCapacity :: WorldId -> IO Capacity Source #

Get max capacity. This can be used with b2WorldDef to avoid run-time allocations and copies

Binds b2World_GetMaxCapacity.

getMaxCapacityInto Source #

Arguments

:: WorldId 
-> Ptr Capacity

Result buffer.

-> IO () 

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

setUserData Source #

Arguments

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

Set the user data pointer.

Binds b2World_SetUserData.

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

Get the user data pointer.

Binds b2World_GetUserData.

setFrictionCallback :: WorldId -> FunPtr FrictionCallback -> IO () Source #

Set the friction callback. Passing NULL resets to default.

Binds b2World_SetFrictionCallback.

setRestitutionCallback :: WorldId -> FunPtr RestitutionCallback -> IO () Source #

Set the restitution callback. Passing NULL resets to default.

Binds b2World_SetRestitutionCallback.

setWorkerCount Source #

Arguments

:: WorldId 
-> Int
count
-> IO () 

Set the worker count. Must be between in the range \[1, B2_MAX_WORKERS\]

Binds b2World_SetWorkerCount.

getWorkerCount :: WorldId -> IO Int Source #

Get the worker count.

Binds b2World_GetWorkerCount.

dumpMemoryStats :: WorldId -> IO () Source #

Dump memory stats to box2d_memory.txt

Binds b2World_DumpMemoryStats.

rebuildStaticTree :: WorldId -> IO () Source #

This is for internal testing

Binds b2World_RebuildStaticTree.

enableSpeculative Source #

Arguments

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

This is for internal testing

Binds b2World_EnableSpeculative.

startRecording Source #

Arguments

:: WorldId

worldId: The world to record

-> Ptr Recording

recording: A recording buffer from b2CreateRecording

-> IO () 

Begin recording the world into @p recording. Serializes a snapshot of the current world as the seed, then logs every mutating call. Call at a step boundary, before or after creating bodies. Start before the first step to capture the whole session. No effect if already recording or if the world is locked.

Binds b2World_StartRecording.

stopRecording Source #

Arguments

:: WorldId

worldId: The world being recorded

-> IO () 

Stop recording. The recording buffer keeps its bytes. Save and destroy it yourself.

Binds b2World_StopRecording.

snapshot Source #

Arguments

:: WorldId

worldId: The world to snapshot

-> Ptr Word8

image: Destination buffer, or NULL to query the size

-> Int

capacity: Size of image in bytes, ignored when querying

-> IO Int 

Write a snapshot of the world's simulation state into a caller-owned buffer. Call once with image == NULL to get the required size, then again with a buffer of at least that size. Must be called at a step boundary.

Returns: The number of bytes the snapshot needs. If it exceeds capacity nothing is written. Returns 0 if the world is mid-step.

Binds b2World_Snapshot.

restore Source #

Arguments

:: WorldId

worldId: The world to restore into

-> Ptr Word8

image: A snapshot image produced by b2World_Snapshot

-> Int

size: Size of image in bytes

-> IO Bool 

Restore a world's simulation state from a snapshot image, in place. The world keeps its slot and generation, so this b2WorldId and any ids held from this same world stay valid for objects that existed at the snapshot instant. Host wiring is preserved. Restore into the same world the snapshot came from to keep held ids valid. Must be called at a step boundary.

Returns: true on success. On a rejected image (bad magic, version, or layout) the world is left unchanged. A corrupt payload detected after the rebuild begins returns false and leaves the world unusable, so the caller must destroy it.

Binds b2World_Restore.

createFromSnapshot Source #

Arguments

:: Ptr Word8

image: A snapshot image produced by b2World_Snapshot

-> Int

size: Size of image in bytes

-> Int

workerCount: Worker count for the new world. 0 uses the serial single-worker fallback.

-> IO WorldId 

Create a new world from a snapshot image. Use this to load a saved world when there is no existing world to restore into. The new world gets a fresh slot and id, so ids held from the origin world will not match it. Host wiring is reset to defaults.

Returns: The new world id, or b2_nullWorldId on failure.

Binds b2CreateWorldFromSnapshot.