Box2D
Safe HaskellNone
LanguageGHC2021

Box2D.Shape

Synopsis

Documentation

createCircle :: BodyId -> ShapeDef -> Circle -> 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 b2CreateCircleShape.

createSegment :: BodyId -> ShapeDef -> Segment -> IO ShapeId Source #

Create a line segment 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 or b2_nullShapeId if the segment is too short.

Binds b2CreateSegmentShape.

createChainSegment :: BodyId -> ShapeDef -> Ptr ChainSegment -> IO ShapeId Source #

Create an orphaned chain segment shape and attach it to a body. The shape definition and geometry are fully cloned. The caller is responsible for the segment's ghost vertices and lifetime. The segment is not owned by any b2ChainShape (b2Shape_GetParentChain returns b2_nullChainId). Contacts are not created until the next time step.

Returns: the shape id, or b2_nullShapeId if the segment is too short.

Binds b2CreateChainSegmentShape.

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, this will be b2_nullShapeId if the length is too small.

Binds b2CreateCapsuleShape.

createPolygon :: BodyId -> ShapeDef -> Polygon -> IO ShapeId Source #

Create a polygon 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 b2CreatePolygonShape.

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

Binds b2DestroyShape.

isValid :: ShapeId -> IO Bool Source #

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

Binds b2Shape_IsValid.

getType :: ShapeId -> IO ShapeType Source #

Get the type of a shape

Binds b2Shape_GetType.

getBody :: ShapeId -> IO BodyId Source #

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

Binds b2Shape_GetBody.

getWorld :: ShapeId -> IO WorldId Source #

Get the world that owns this shape

Binds b2Shape_GetWorld.

isSensor :: ShapeId -> IO Bool Source #

Returns true if the shape is a sensor. It is not possible to change a shape from sensor to solid dynamically because this breaks the contract for sensor events.

Binds b2Shape_IsSensor.

setUserData Source #

Arguments

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

Set the user data for a shape

Binds b2Shape_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 b2Shape_GetUserData.

setDensity Source #

Arguments

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

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

Binds b2Shape_SetDensity.

getDensity :: ShapeId -> IO Float Source #

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

Binds b2Shape_GetDensity.

setFriction Source #

Arguments

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

Set the friction on a shape

Binds b2Shape_SetFriction.

getFriction :: ShapeId -> IO Float Source #

Get the friction of a shape

Binds b2Shape_GetFriction.

setRestitution Source #

Arguments

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

Set the shape restitution (bounciness)

Binds b2Shape_SetRestitution.

getRestitution :: ShapeId -> IO Float Source #

Get the shape restitution

Binds b2Shape_GetRestitution.

setUserMaterial Source #

Arguments

:: ShapeId 
-> Word64
material
-> IO () 

Set the user material identifier

Binds b2Shape_SetUserMaterial.

getUserMaterial :: ShapeId -> IO Word64 Source #

Get the user material identifier

Binds b2Shape_GetUserMaterial.

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

Set the shape surface material

Binds b2Shape_SetSurfaceMaterial.

getSurfaceMaterial :: ShapeId -> IO SurfaceMaterial Source #

Get the shape surface material

Binds b2Shape_GetSurfaceMaterial.

getSurfaceMaterialInto Source #

Arguments

:: ShapeId 
-> Ptr SurfaceMaterial

Result buffer.

-> IO () 

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

getFilter :: ShapeId -> IO Filter Source #

Get the shape filter

Binds b2Shape_GetFilter.

getFilterInto Source #

Arguments

:: ShapeId 
-> Ptr Filter

Result buffer.

-> IO () 

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

setFilter :: ShapeId -> Filter -> IO () Source #

Set the current filter. This is almost as expensive as recreating the shape. This may cause contacts to be immediately destroyed. However contacts are not created until the next world step. Sensor overlap state is also not updated until the next world step. See also b2ShapeDef::filter.

Binds b2Shape_SetFilter.

enableSensorEvents Source #

Arguments

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

Enable sensor events for this shape. See also b2ShapeDef::enableSensorEvents.

Binds b2Shape_EnableSensorEvents.

areSensorEventsEnabled :: ShapeId -> IO Bool Source #

Returns true if sensor events are enabled.

Binds b2Shape_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 b2ShapeDef::enableContactEvents. Warning: changing this at run-time may lead to lost begin/end events

Binds b2Shape_EnableContactEvents.

areContactEventsEnabled :: ShapeId -> IO Bool Source #

Returns true if contact events are enabled

Binds b2Shape_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 b2PreSolveFcn.

Binds b2Shape_EnablePreSolveEvents.

arePreSolveEventsEnabled :: ShapeId -> IO Bool Source #

Returns true if pre-solve events are enabled

Binds b2Shape_ArePreSolveEventsEnabled.

enableHitEvents Source #

Arguments

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

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

Binds b2Shape_EnableHitEvents.

areHitEventsEnabled :: ShapeId -> IO Bool Source #

Returns true if hit events are enabled

Binds b2Shape_AreHitEventsEnabled.

testPoint Source #

Arguments

:: ShapeId 
-> Pos
point
-> IO Bool 

Test a world point for overlap with a shape

Binds b2Shape_TestPoint.

rayCast Source #

Arguments

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

Ray cast a single shape. The ray starts at the origin and extends by the translation. The output point is a world position.

Binds b2Shape_RayCast.

getCircle :: ShapeId -> IO Circle Source #

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

Binds b2Shape_GetCircle.

getCircleInto Source #

Arguments

:: ShapeId 
-> Ptr Circle

Result buffer.

-> IO () 

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

getSegment :: ShapeId -> IO Segment Source #

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

Binds b2Shape_GetSegment.

getSegmentInto Source #

Arguments

:: ShapeId 
-> Ptr Segment

Result buffer.

-> IO () 

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

getChainSegment Source #

Arguments

:: ShapeId 
-> Ptr ChainSegment

Result buffer.

-> IO () 

Get a copy of the shape's chain segment. These come from chain shapes. Asserts the type is correct.

Binds b2Shape_GetChainSegment.

getCapsule :: ShapeId -> IO Capsule Source #

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

Binds b2Shape_GetCapsule.

getCapsuleInto Source #

Arguments

:: ShapeId 
-> Ptr Capsule

Result buffer.

-> IO () 

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

getPolygon :: ShapeId -> IO Polygon Source #

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

Binds b2Shape_GetPolygon.

getPolygonInto Source #

Arguments

:: ShapeId 
-> Ptr Polygon

Result buffer.

-> IO () 

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

setCircle :: ShapeId -> Circle -> IO () Source #

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

Binds b2Shape_SetCircle.

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

Binds b2Shape_SetCapsule.

setSegment :: ShapeId -> Segment -> IO () Source #

Allows you to change a shape to be a segment or update the current segment.

Binds b2Shape_SetSegment.

setPolygon :: ShapeId -> Polygon -> IO () Source #

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

Binds b2Shape_SetPolygon.

setChainSegment :: ShapeId -> Ptr ChainSegment -> IO () Source #

Allows you to change a shape to be an orphaned chain segment or update the current chain segment, including its ghost vertices. The chainId on the input is ignored. The resulting shape is always orphaned. Asserts if the shape is already a chain segment owned by a b2ChainShape (chainId != B2_NULL_INDEX).

Binds b2Shape_SetChainSegment.

getParentChain :: ShapeId -> IO ChainId Source #

Get the parent chain id if the shape type is a chain segment, otherwise returns b2_nullChainId.

Binds b2Shape_GetParentChain.

getContactCapacity :: ShapeId -> IO Int Source #

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

Binds b2Shape_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: 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 b2Shape_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 b2Shape_GetSensorData

Binds b2Shape_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 computed the previous world step. Warning: do not ignore the return value, it specifies the valid number of elements Warning: overlaps may contain destroyed shapes so use b2Shape_IsValid to confirm each overlap

Returns: the number of elements filled in the provided array

Binds b2Shape_GetSensorData.

getAABB :: ShapeId -> IO AABB Source #

Get the current world AABB

Binds b2Shape_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 b2Shape_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 
-> Pos
target
-> IO Pos 

Get the closest point on a shape to a target point. Target and result are world positions. todo need sample

Binds b2Shape_GetClosestPoint.

applyWind Source #

Arguments

:: ShapeId

shapeId: the shape id

-> Vec2

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

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