Box3D
Safe HaskellNone
LanguageGHC2021

Box3D.Shape

Synopsis

Documentation

createSphere :: BodyId -> ShapeDef -> Sphere -> IO ShapeId Source #

Create a circle shape and attach it to a body. The shape definition and geometry are fully cloned. Contacts are not created until the next time step.

Returns: the shape id for accessing the shape

Binds b3CreateSphereShape.

createCapsule :: BodyId -> ShapeDef -> Capsule -> IO ShapeId Source #

Create a capsule shape and attach it to a body. The shape definition and geometry are fully cloned. Contacts are not created until the next time step.

Returns: the shape id for accessing the shape

Binds b3CreateCapsuleShape.

createHull :: BodyId -> ShapeDef -> Ptr HullData -> IO ShapeId Source #

Create a convex hull shape and attach it to a body. The shape definition is fully cloned. Contacts are not created until the next time step.

Returns: the shape id for accessing the shape

Binds b3CreateHullShape.

createTransformedHull Source #

Arguments

:: BodyId 
-> ShapeDef 
-> Ptr HullData 
-> Transform 
-> Vec3
scale
-> IO ShapeId 

Create a convex hull shape and attach it to a body. The hull is cloned then transformed with scale applied first. Use this for non-uniform or mirrored scale or a baked local transform. The baked result is shared through the world hull database. The shape definition and geometry are fully cloned. Contacts are not created until the next time step.

Returns: the shape id for accessing the shape

Binds b3CreateTransformedHullShape.

createMesh Source #

Arguments

:: BodyId 
-> ShapeDef 
-> Ptr MeshData 
-> Vec3
scale
-> IO ShapeId 

Create a mesh hull shape and attach it to a body. The shape definition is fully cloned but the mesh is not. Contacts are not created until the next time step. Mesh collision only creates contacts on static bodies. Warning: this holds reference to the input mesh data which must remain valid for the lifetime of this shape

Returns: the shape id for accessing the shape

Binds b3CreateMeshShape.

createHeightField :: BodyId -> ShapeDef -> Ptr HeightFieldData -> IO ShapeId Source #

Create a height-field shape and attach it to a body. The shape definition is fully cloned but the height field is not. Contacts are not created until the next time step. Height field is only allowed on static bodies. Warning: this holds reference to the input height field which must remain valid for the lifetime of this shape

Returns: the shape id for accessing the shape

Binds b3CreateHeightFieldShape.

createCompound :: BodyId -> Ptr ShapeDef -> Ptr CompoundData -> IO ShapeId Source #

Compound shapes are only allowed on static bodies.

Binds b3CreateCompoundShape.

destroy Source #

Arguments

:: ShapeId 
-> Bool
updateBodyMass
-> IO () 

Destroy a shape. You may defer the body mass update which can improve performance if several shapes on a body are destroyed at once. See also b3Body_ApplyMassFromShapes.

Binds b3DestroyShape.

isValid :: ShapeId -> IO Bool Source #

Shape identifier validation. Provides validation for up to 64K allocations.

Binds b3Shape_IsValid.

getType :: ShapeId -> IO ShapeType Source #

Get the type of a shape

Binds b3Shape_GetType.

getBody :: ShapeId -> IO BodyId Source #

Get the id of the body that a shape is attached to

Binds b3Shape_GetBody.

getWorld :: ShapeId -> IO WorldId Source #

Get the world that owns this shape

Binds b3Shape_GetWorld.

isSensor :: ShapeId -> IO Bool Source #

Returns true if the shape is a sensor

Binds b3Shape_IsSensor.

setUserData Source #

Arguments

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

Set the user data for a shape

Binds b3Shape_SetUserData.

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

Get the user data for a shape. This is useful when you get a shape id from an event or query.

Binds b3Shape_GetUserData.

setDensity Source #

Arguments

:: ShapeId 
-> Float
density
-> Bool
updateBodyMass
-> IO () 

Set the mass density of a shape, usually in kg/m^3. This will optionally update the mass properties on the parent body. See also b3ShapeDef::density, b3Body_ApplyMassFromShapes.

Binds b3Shape_SetDensity.

getDensity :: ShapeId -> IO Float Source #

Get the density of a shape, usually in kg/m^3

Binds b3Shape_GetDensity.

setFriction Source #

Arguments

:: ShapeId 
-> Float
friction
-> IO () 

Set the friction on a shape

Binds b3Shape_SetFriction.

getFriction :: ShapeId -> IO Float Source #

Get the friction of a shape

Binds b3Shape_GetFriction.

setRestitution Source #

Arguments

:: ShapeId 
-> Float
restitution
-> IO () 

Set the shape restitution (bounciness)

Binds b3Shape_SetRestitution.

getRestitution :: ShapeId -> IO Float Source #

Get the shape restitution

Binds b3Shape_GetRestitution.

setSurfaceMaterial :: ShapeId -> SurfaceMaterial -> IO () Source #

Set the shape base surface material. Does not change per triangle materials.

Binds b3Shape_SetSurfaceMaterial.

getSurfaceMaterial :: ShapeId -> IO SurfaceMaterial Source #

Get the base shape surface material.

Binds b3Shape_GetSurfaceMaterial.

getSurfaceMaterialInto Source #

Arguments

:: ShapeId 
-> Ptr SurfaceMaterial

Result buffer.

-> IO () 

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

getMeshMaterialCount :: ShapeId -> IO Int Source #

Get the number of mesh surface materials.

Binds b3Shape_GetMeshMaterialCount.

setMeshMaterial Source #

Arguments

:: ShapeId 
-> SurfaceMaterial 
-> Int
index
-> IO () 

Set a surface material for a mesh shape.

Binds b3Shape_SetMeshMaterial.

getMeshSurfaceMaterial Source #

Arguments

:: ShapeId 
-> Int
index
-> IO SurfaceMaterial 

Get a surface material for a mesh shape

Binds b3Shape_GetMeshSurfaceMaterial.

getMeshSurfaceMaterialInto Source #

Arguments

:: ShapeId 
-> Int
index
-> Ptr SurfaceMaterial

Result buffer.

-> IO () 

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

getFilter :: ShapeId -> IO Filter Source #

Get the shape filter

Binds b3Shape_GetFilter.

getFilterInto Source #

Arguments

:: ShapeId 
-> Ptr Filter

Result buffer.

-> IO () 

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

setFilter Source #

Arguments

:: ShapeId

shapeId: the shape

-> Filter

filter: the new filter

-> Bool

invokeContacts: if true then the shape will have all contacts recomputed the next time step (expensive)

-> IO () 

Set the current filter. This is almost as expensive as recreating the shape. See also b3ShapeDef::filter.

Binds b3Shape_SetFilter.

enableSensorEvents Source #

Arguments

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

Enable sensor events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors. See also b3ShapeDef::isSensor.

Binds b3Shape_EnableSensorEvents.

areSensorEventsEnabled :: ShapeId -> IO Bool Source #

Returns true if sensor events are enabled

Binds b3Shape_AreSensorEventsEnabled.

enableContactEvents Source #

Arguments

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

Enable contact events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors. See also b3ShapeDef::enableContactEvents.

Binds b3Shape_EnableContactEvents.

areContactEventsEnabled :: ShapeId -> IO Bool Source #

Returns true if contact events are enabled

Binds b3Shape_AreContactEventsEnabled.

enablePreSolveEvents Source #

Arguments

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

Enable pre-solve contact events for this shape. Only applies to dynamic bodies. These are expensive and must be carefully handled due to multithreading. Ignored for sensors. See also b3PreSolveFcn.

Binds b3Shape_EnablePreSolveEvents.

arePreSolveEventsEnabled :: ShapeId -> IO Bool Source #

Returns true if pre-solve events are enabled

Binds b3Shape_ArePreSolveEventsEnabled.

enableHitEvents Source #

Arguments

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

Enable contact hit events for this shape. Ignored for sensors. See also b3WorldDef.hitEventThreshold.

Binds b3Shape_EnableHitEvents.

areHitEventsEnabled :: ShapeId -> IO Bool Source #

Returns true if hit events are enabled

Binds b3Shape_AreHitEventsEnabled.

rayCast Source #

Arguments

:: ShapeId 
-> Pos
origin
-> Vec3
translation
-> IO WorldCastOutput 

Ray cast a shape directly. The ray runs from origin to origin + translation and the hit point comes back as a world position, so the cast stays precise far from the world origin.

Binds b3Shape_RayCast.

getSphere :: ShapeId -> IO Sphere Source #

Get a copy of the shape's sphere. Asserts the type is correct.

Binds b3Shape_GetSphere.

getSphereInto Source #

Arguments

:: ShapeId 
-> Ptr Sphere

Result buffer.

-> IO () 

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

getCapsule :: ShapeId -> IO Capsule Source #

Get a copy of the shape's capsule. Asserts the type is correct.

Binds b3Shape_GetCapsule.

getCapsuleInto Source #

Arguments

:: ShapeId 
-> Ptr Capsule

Result buffer.

-> IO () 

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

getHull :: ShapeId -> IO (Ptr HullData) Source #

Get the shape's convex hull. Asserts the type is correct.

Binds b3Shape_GetHull.

getMesh Source #

Arguments

:: ShapeId 
-> Ptr Mesh

Result buffer.

-> IO () 

Get the shape's mesh. Asserts the type is correct.

Binds b3Shape_GetMesh.

getHeightField :: ShapeId -> IO (Ptr HeightFieldData) Source #

Get the shape's height field. Asserts the type is correct.

Binds b3Shape_GetHeightField.

setSphere :: ShapeId -> Sphere -> IO () Source #

Allows you to change a shape to be a sphere or update the current sphere. This does not modify the mass properties. See also b3Body_ApplyMassFromShapes.

Binds b3Shape_SetSphere.

setCapsule :: ShapeId -> Capsule -> IO () Source #

Allows you to change a shape to be a capsule or update the current capsule. This does not modify the mass properties. See also b3Body_ApplyMassFromShapes.

Binds b3Shape_SetCapsule.

setHull :: ShapeId -> Ptr HullData -> IO () Source #

Allows you to change a shape to be a hull or update the current hull. This does not modify the mass properties. See also b3Body_ApplyMassFromShapes.

Binds b3Shape_SetHull.

setMesh Source #

Arguments

:: ShapeId 
-> Ptr MeshData 
-> Vec3
scale
-> IO () 

Allows you to change a shape to be a mesh or update the current mesh. This does not modify the mass properties. See also b3Body_ApplyMassFromShapes.

Binds b3Shape_SetMesh.

getContactCapacity :: ShapeId -> IO Int Source #

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

Binds b3Shape_GetContactCapacity.

getContactData Source #

Arguments

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

Get the touching contact data for a shape. The provided shapeId will be either shapeIdA or shapeIdB on the contact data. Note: Box3D 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 b3Shape_GetContactData.

getSensorCapacity Source #

Arguments

:: ShapeId

shapeId: the id of a sensor shape

-> IO Int 

Get the maximum capacity required for retrieving all the overlapped shapes on a sensor shape. This returns 0 if the provided shape is not a sensor.

Returns: the required capacity to get all the overlaps in b3Shape_GetSensorOverlaps

Binds b3Shape_GetSensorCapacity.

getSensorData Source #

Arguments

:: ShapeId

shapeId: the id of a sensor shape

-> Ptr ShapeId

visitorIds: a user allocated array that is filled with the overlapping shapes (visitors)

-> Int

capacity: the capacity of overlappedShapes

-> IO Int 

Get the overlap data for a sensor shape. Warning: do not ignore the return value, it specifies the valid number of elements Warning: overlaps may contain destroyed shapes so use b3Shape_IsValid to confirm each overlap

Returns: the number of elements filled in the provided array

Binds b3Shape_GetSensorData.

getAABB :: ShapeId -> IO AABB Source #

Get the current world AABB

Binds b3Shape_GetAABB.

getAABBInto Source #

Arguments

:: ShapeId 
-> Ptr AABB

Result buffer.

-> IO () 

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

computeMassData :: ShapeId -> IO MassData Source #

Compute the mass data for a shape

Binds b3Shape_ComputeMassData.

computeMassDataInto Source #

Arguments

:: ShapeId 
-> Ptr MassData

Result buffer.

-> IO () 

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

getClosestPoint Source #

Arguments

:: ShapeId 
-> Vec3
target
-> IO Vec3 

Get the closest point on a shape to a target point. Target and result are in world space.

Binds b3Shape_GetClosestPoint.

applyWind Source #

Arguments

:: ShapeId

shapeId: the shape id

-> Vec3

wind: the wind velocity in world space

-> Float

drag: the drag coefficient, the force that opposes the relative velocity

-> Float

lift: the lift coefficient, the force that is perpendicular to the relative velocity

-> Float

maxSpeed: the maximum relative speed. Speed cap is necessary for stability. Typically 10m/s or less.

-> Bool

wake: should this wake the body

-> IO () 

Apply a wind force to the body for this shape using the density of air. This considers the projected area of the shape in the wind direction. This also considers the relative velocity of the shape.

Binds b3Shape_ApplyWind.