| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Box2D.World
Synopsis
- create :: WorldDef -> IO WorldId
- destroy :: WorldId -> IO ()
- isValid :: WorldId -> IO Bool
- step :: WorldId -> Float -> Int -> IO ()
- draw :: WorldId -> Ptr DebugDraw -> IO ()
- getBounds :: WorldId -> IO AABB
- getBoundsInto :: WorldId -> Ptr AABB -> IO ()
- getBodyEvents :: WorldId -> IO BodyEvents
- getBodyEventsInto :: WorldId -> Ptr BodyEvents -> IO ()
- getSensorEvents :: WorldId -> IO SensorEvents
- getSensorEventsInto :: WorldId -> Ptr SensorEvents -> IO ()
- getContactEvents :: WorldId -> IO ContactEvents
- getContactEventsInto :: WorldId -> Ptr ContactEvents -> IO ()
- getJointEvents :: WorldId -> IO JointEvents
- getJointEventsInto :: WorldId -> Ptr JointEvents -> IO ()
- overlapAABB :: WorldId -> Pos -> AABB -> QueryFilter -> FunPtr OverlapResultFcn -> Ptr () -> IO TreeStats
- overlapShape :: WorldId -> Pos -> Ptr ShapeProxy -> QueryFilter -> FunPtr OverlapResultFcn -> Ptr () -> IO TreeStats
- castRay :: WorldId -> Pos -> Vec2 -> QueryFilter -> FunPtr CastResultFcn -> Ptr () -> IO TreeStats
- castRayClosest :: WorldId -> Pos -> Vec2 -> QueryFilter -> IO RayResult
- castShape :: WorldId -> Pos -> Ptr ShapeProxy -> Vec2 -> QueryFilter -> FunPtr CastResultFcn -> Ptr () -> IO TreeStats
- castMover :: WorldId -> Pos -> Capsule -> Vec2 -> QueryFilter -> IO Float
- collideMover :: WorldId -> Pos -> Capsule -> QueryFilter -> FunPtr PlaneResultFcn -> Ptr () -> IO ()
- enableSleeping :: WorldId -> Bool -> IO ()
- isSleepingEnabled :: WorldId -> IO Bool
- enableContinuous :: WorldId -> Bool -> IO ()
- isContinuousEnabled :: WorldId -> IO Bool
- setRestitutionThreshold :: WorldId -> Float -> IO ()
- getRestitutionThreshold :: WorldId -> IO Float
- setHitEventThreshold :: WorldId -> Float -> IO ()
- getHitEventThreshold :: WorldId -> IO Float
- setCustomFilterCallback :: WorldId -> FunPtr CustomFilterFcn -> Ptr () -> IO ()
- setPreSolveCallback :: WorldId -> FunPtr PreSolveFcn -> Ptr () -> IO ()
- setGravity :: WorldId -> Vec2 -> IO ()
- getGravity :: WorldId -> IO Vec2
- getGravityInto :: WorldId -> Ptr Vec2 -> IO ()
- explode :: WorldId -> ExplosionDef -> IO ()
- setContactTuning :: WorldId -> Float -> Float -> Float -> IO ()
- setContactRecycleDistance :: WorldId -> Float -> IO ()
- getContactRecycleDistance :: WorldId -> IO Float
- setMaximumLinearSpeed :: WorldId -> Float -> IO ()
- getMaximumLinearSpeed :: WorldId -> IO Float
- enableWarmStarting :: WorldId -> Bool -> IO ()
- isWarmStartingEnabled :: WorldId -> IO Bool
- getAwakeBodyCount :: WorldId -> IO Int
- getProfile :: WorldId -> Ptr Profile -> IO ()
- getCounters :: WorldId -> Ptr Counters -> IO ()
- getMaxCapacity :: WorldId -> IO Capacity
- getMaxCapacityInto :: WorldId -> Ptr Capacity -> IO ()
- setUserData :: WorldId -> Ptr () -> IO ()
- getUserData :: WorldId -> IO (Ptr ())
- setFrictionCallback :: WorldId -> FunPtr FrictionCallback -> IO ()
- setRestitutionCallback :: WorldId -> FunPtr RestitutionCallback -> IO ()
- setWorkerCount :: WorldId -> Int -> IO ()
- getWorkerCount :: WorldId -> IO Int
- dumpMemoryStats :: WorldId -> IO ()
- rebuildStaticTree :: WorldId -> IO ()
- enableSpeculative :: WorldId -> Bool -> IO ()
- startRecording :: WorldId -> Ptr Recording -> IO ()
- stopRecording :: WorldId -> IO ()
- snapshot :: WorldId -> Ptr Word8 -> Int -> IO Int
- restore :: WorldId -> Ptr Word8 -> Int -> IO Bool
- createFromSnapshot :: Ptr Word8 -> Int -> Int -> IO WorldId
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.
isValid :: WorldId -> IO Bool Source #
World id validation. Provides validation for up to 64K allocations.
Binds b2World_IsValid.
Arguments
| :: WorldId |
|
| -> Float |
|
| -> Int |
|
| -> 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.
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.
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.
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.
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.
Arguments
| :: WorldId | |
| -> Ptr JointEvents | Result buffer. |
| -> IO () |
Like getJointEvents, but the result is written into a caller-supplied buffer.
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.
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.
Arguments
| :: WorldId |
|
| -> Pos |
|
| -> Vec2 |
|
| -> QueryFilter |
|
| -> FunPtr CastResultFcn |
|
| -> Ptr () |
|
| -> 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.
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.
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.
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.
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.
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.
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 #
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.
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.
Arguments
| :: WorldId | |
| -> FunPtr PreSolveFcn | |
| -> Ptr () | context |
| -> IO () |
Register the pre-solve callback. This is optional.
Binds b2World_SetPreSolveCallback.
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.
Like getGravity, but the result is written into a caller-supplied buffer.
Arguments
| :: WorldId |
|
| -> ExplosionDef |
|
| -> IO () |
Apply a radial explosion
Binds b2World_Explode.
Arguments
| :: WorldId |
|
| -> Float |
|
| -> Float |
|
| -> Float |
|
| -> IO () |
Adjust contact tuning parameters Note: Advanced feature
Binds b2World_SetContactTuning.
setContactRecycleDistance Source #
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 #
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.
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.
Get the current world performance profile
Binds b2World_GetProfile.
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.
Like getMaxCapacity, but the result is written into a caller-supplied buffer.
Set the user data pointer.
Binds b2World_SetUserData.
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.
Set the worker count. Must be between in the range \[1, B2_MAX_WORKERS\]
Binds b2World_SetWorkerCount.
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.
This is for internal testing
Binds b2World_EnableSpeculative.
Arguments
| :: WorldId |
|
| -> Ptr Recording |
|
| -> 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.
Stop recording. The recording buffer keeps its bytes. Save and destroy it yourself.
Binds b2World_StopRecording.
Arguments
| :: WorldId |
|
| -> Ptr Word8 |
|
| -> Int |
|
| -> 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.
Arguments
| :: WorldId |
|
| -> Ptr Word8 |
|
| -> Int |
|
| -> 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.
Arguments
| :: Ptr Word8 |
|
| -> Int |
|
| -> Int |
|
| -> 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.