Box3D
Safe HaskellNone
LanguageGHC2021

Box3D.World

Synopsis

Documentation

create :: WorldDef -> IO WorldId Source #

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

Returns: the world id.

Binds b3CreateWorld.

destroy :: WorldId -> IO () Source #

Destroy a world

Binds b3DestroyWorld.

isValid :: WorldId -> IO Bool Source #

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

Binds b3World_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 b3World_Step.

draw Source #

Arguments

:: WorldId 
-> Ptr DebugDraw 
-> Word64
maskBits
-> IO () 

Call this to draw shapes and other debug draw data

Binds b3World_Draw.

getBounds :: WorldId -> IO AABB Source #

Get the world's bounds. This is the bounding box that covers the current simulation. May have a small amount of padding.

Binds b3World_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 b3World_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 b3World_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 b3World_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 b3World_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 
-> AABB 
-> QueryFilter 
-> FunPtr OverlapResultFcn 
-> Ptr ()
context
-> IO TreeStats 

Overlap test for all shapes that *potentially* overlap the provided AABB

Binds b3World_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 world origin, which lets the query stay precise far from the world origin.

Binds b3World_OverlapShape.

castRay Source #

Arguments

:: WorldId

worldId: The world to cast the ray against

-> Pos

origin: The start point of the ray

-> Vec3

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 b3World_CastRay.

castRayClosest Source #

Arguments

:: WorldId 
-> Pos
origin
-> Vec3
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 b3World_CastRay() and does not allow for custom filtering.

Binds b3World_CastRayClosest.

castShape Source #

Arguments

:: WorldId 
-> Pos
origin
-> Ptr ShapeProxy 
-> Vec3
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 and the hit points come back as world positions, so the cast stays precise far from the world origin. See also b3World_CastRay.

Binds b3World_CastShape.

castMover Source #

Arguments

:: WorldId

worldId: World to cast the mover against

-> Pos

origin: World position the mover capsule is relative to

-> Capsule

mover: Capsule mover, relative to the origin

-> Vec3

translation: Desired mover translation

-> QueryFilter

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

-> FunPtr MoverFilterFcn

fcn: Optional callback for custom shape filtering

-> Ptr ()

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

-> IO Float 

Cast a capsule mover through the world. This is a special shape cast that handles sliding along other shapes while reducing clipping. This is not a good source of information about what the mover is touching. Instead use the planes returned by b3World_CollideMover.

Returns: the translation fraction

Binds b3World_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 b3SolvePlanes. Useful for kinematic character movement. The mover and the returned planes are relative to the origin.

Binds b3World_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 b3WorldDef.

Binds b3World_EnableSleeping.

isSleepingEnabled :: WorldId -> IO Bool Source #

Is body sleeping enabled?

Binds b3World_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 b3WorldDef.

Binds b3World_EnableContinuous.

isContinuousEnabled :: WorldId -> IO Bool Source #

Is continuous collision enabled?

Binds b3World_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 b3WorldDef.

Binds b3World_SetRestitutionThreshold.

getRestitutionThreshold :: WorldId -> IO Float Source #

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

Binds b3World_GetRestitutionThreshold.

setHitEventThreshold Source #

Arguments

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

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

Binds b3World_SetHitEventThreshold.

getHitEventThreshold :: WorldId -> IO Float Source #

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

Binds b3World_GetHitEventThreshold.

setCustomFilterCallback Source #

Arguments

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

Register the custom filter callback. This is optional.

Binds b3World_SetCustomFilterCallback.

setPreSolveCallback Source #

Arguments

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

Register the pre-solve callback. This is optional.

Binds b3World_SetPreSolveCallback.

setGravity Source #

Arguments

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

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

Binds b3World_SetGravity.

getGravity :: WorldId -> IO Vec3 Source #

Get the gravity vector

Binds b3World_GetGravity.

getGravityInto Source #

Arguments

:: WorldId 
-> Ptr Vec3

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 b3World_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

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

-> IO () 

Adjust contact tuning parameters Note: Advanced feature

Binds b3World_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 b3World_SetContactRecycleDistance.

getContactRecycleDistance :: WorldId -> IO Float Source #

Get the contact point recycling distance. Usually in meters.

Binds b3World_GetContactRecycleDistance.

setMaximumLinearSpeed Source #

Arguments

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

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

Binds b3World_SetMaximumLinearSpeed.

getMaximumLinearSpeed :: WorldId -> IO Float Source #

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

Binds b3World_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 b3World_EnableWarmStarting.

isWarmStartingEnabled :: WorldId -> IO Bool Source #

Is constraint warm starting enabled?

Binds b3World_IsWarmStartingEnabled.

getAwakeBodyCount :: WorldId -> IO Int Source #

Get the number of awake bodies

Binds b3World_GetAwakeBodyCount.

getProfile Source #

Arguments

:: WorldId 
-> Ptr Profile

Result buffer.

-> IO () 

Get the current world performance profile

Binds b3World_GetProfile.

getCounters Source #

Arguments

:: WorldId 
-> Ptr Counters

Result buffer.

-> IO () 

Get world counters and sizes

Binds b3World_GetCounters.

getMaxCapacity :: WorldId -> IO Capacity Source #

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

Binds b3World_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 b3World_SetUserData.

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

Get the user data pointer.

Binds b3World_GetUserData.

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

Set the friction callback. Passing NULL resets to default.

Binds b3World_SetFrictionCallback.

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

Set the restitution callback. Passing NULL resets to default.

Binds b3World_SetRestitutionCallback.

setWorkerCount Source #

Arguments

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

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

Binds b3World_SetWorkerCount.

getWorkerCount :: WorldId -> IO Int Source #

Get the worker count.

Binds b3World_GetWorkerCount.

dumpMemoryStats :: WorldId -> IO () Source #

Dump memory stats to log.

Binds b3World_DumpMemoryStats.

dumpShapeBounds :: WorldId -> BodyType -> IO () Source #

Dump shape bounds to box3d_bounds.txt

Binds b3World_DumpShapeBounds.

rebuildStaticTree :: WorldId -> IO () Source #

This is for internal testing

Binds b3World_RebuildStaticTree.

enableSpeculative Source #

Arguments

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

This is for internal testing

Binds b3World_EnableSpeculative.

dumpAwake :: WorldId -> IO () Source #

Dump world to a text file. Saves only awake bodies and associated static bodies. Meshes are saved to binary b3m files.

Binds b3World_DumpAwake.

dump :: WorldId -> IO () Source #

Dump world to a text file. Meshes are saved to binary b3m files.

Binds b3World_Dump.

startRecording Source #

Arguments

:: WorldId

worldId: the world to record

-> Ptr Recording

recording: the recording handle to write into

-> IO () 

Begin recording world mutations into the provided buffer. The buffer is reset on each call so a single b3Recording can be reused for multiple sessions.

Binds b3World_StartRecording.

stopRecording Source #

Arguments

:: WorldId

worldId: the world currently being recorded

-> IO () 

End the current recording session. Writes the trailing geometry registry and backpatches the header. The buffer remains valid until the recording is destroyed.

Binds b3World_StopRecording.