HughPH.Box2D
Organised dotnet bindings for Box2D 3.1.1
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Properties | List of all members
Box2D.Shape Struct Reference

A shape is a geometric object used for collision detection. More...

Inherits IEquatable< Shape >, and IComparable< Shape >.

Public Member Functions

 Shape (Body body, in ShapeDef def, in Circle circle)
 Create a shape on the specified body with the specified definition.
 
 Shape (Body body, in ShapeDef def, in Segment segment)
 Create a shape on the specified body with the specified definition.
 
 Shape (Body body, in ShapeDef def, in Capsule capsule)
 Create a shape on the specified body with the specified definition.
 
 Shape (Body body, in ShapeDef def, in Polygon polygon)
 Create a shape on the specified body with the specified definition.
 
bool Equals (Shape other)
 Checks if this Shape and another Shape refer to the same shape.
 
override bool Equals (object? obj)
 Checks if this Shape and another Shape refer to the same shape.
 
override int GetHashCode ()
 Returns a hash code for this shape.
 
unsafe void Destroy (bool updateBodyMass)
 Destroys this shape.
 
unsafe void SetDensity (float density, bool updateBodyMass)
 Sets the mass density of this shape.
 
unsafe bool TestPoint (Vec2 point)
 Tests a point for overlap with this shape.
 
unsafe CastOutput RayCast (in RayCastInput input)
 Ray casts this shape directly.
 
unsafe Circle GetCircle ()
 Gets a copy of the shape's circle.
 
unsafe Segment GetSegment ()
 Gets a copy of the shape's line segment.
 
unsafe ChainSegment GetChainSegment ()
 Gets a copy of the shape's chain segment.
 
unsafe Capsule GetCapsule ()
 Gets a copy of the shape's capsule.
 
unsafe Polygon GetPolygon ()
 Gets a copy of the shape's convex polygon.
 
unsafe void SetCircle (in Circle circle)
 Allows you to change this shape to be a circle or update the current circle.
 
unsafe void SetCapsule (in Capsule capsule)
 Allows you to change this shape to be a capsule or update the current capsule.
 
unsafe void SetSegment (in Segment segment)
 Allows you to change this shape to be a segment or update the current segment.
 
unsafe void SetPolygon (in Polygon polygon)
 Allows you to change this shape to be a polygon or update the current polygon.
 
unsafe ChainShape GetParentChain ()
 Gets the parent chain id if the shape type is a chain segment.
 
unsafe Vec2 GetClosestPoint (Vec2 target)
 Gets the closest point on this shape to a target point.
 

Static Public Member Functions

static bool operator== (Shape left, Shape right)
 Checks if this shape and another shape refer to the same shape.
 
static bool operator!= (Shape left, Shape right)
 Checks if this shape and another shape refer to different shapes.
 

Properties

static IComparer< ShapeDefaultComparer = ShapeComparer.Instance [get]
 Default comparer for Shape instances. This is used for sorting and comparing shapes. Using the default comparer is recommended to avoid boxing and unboxing overhead.
 
static IEqualityComparer< ShapeDefaultEqualityComparer = ShapeComparer.Instance [get]
 Default equality comparer for Shape instances. This is used for comparing shapes. Using the default equality comparer is recommended to avoid boxing and unboxing overhead.
 
unsafe bool Valid [get]
 Checks if this shape is valid.
 
unsafe ShapeType Type [get]
 Gets the type of this shape.
 
unsafe Body Body [get]
 Gets the body that this shape is attached to.
 
unsafe World World [get]
 Gets the world that this shape belongs to.
 
unsafe bool Sensor [get]
 Checks if this shape is a sensor.
 
unsafe? object UserData [get, set]
 The user data object for this shape.
 
unsafe float Density [get, set]
 The mass density of this shape.
 
unsafe float Friction [get, set]
 The friction on this shape.
 
unsafe float Restitution [get, set]
 Restitution of this shape.
 
unsafe int Material [get, set]
 Gets/sets the material ID for this shape - this does not affect the shape's physical properties.
 
unsafe SurfaceMaterial SurfaceMaterial [get, set]
 Gets/sets the surface material for this shape.
 
unsafe Filter Filter [get, set]
 The filter for this shape.
 
unsafe bool ContactEventsEnabled [get, set]
 Contact enabled state for this shape.
 
unsafe bool PreSolveEventsEnabled [get, set]
 The pre-solve contact enabled state for this shape.
 
unsafe bool HitEventsEnabled [get, set]
 Hit events enabled state for this shape.
 
unsafe ReadOnlySpan< ContactDataContactData [get]
 Gets the contact data for this shape.
 
unsafe ReadOnlySpan< ShapeSensorOverlaps [get]
 Gets the overlapped shapes for this sensor shape.
 
unsafe AABB AABB [get]
 Gets the current world AABB.
 
unsafe MassData MassData [get]
 Gets the mass data for this shape.
 
ReadOnlySpan< Vec2 > LocalVertices [get]
 Gets the local vertices of this shape.
 
ReadOnlySpan< Vec2 > WorldVertices [get]
 Gets the world vertices of this shape.
 

Detailed Description

A shape is a geometric object used for collision detection.

Constructor & Destructor Documentation

◆ Shape() [1/4]

Box2D.Shape.Shape ( Body  body,
in ShapeDef  def,
in Circle  circle 
)
inline

Create a shape on the specified body with the specified definition.

Parameters
bodyThe body on which to create the shape
defThe shape definition
circleThe shape to create

◆ Shape() [2/4]

Box2D.Shape.Shape ( Body  body,
in ShapeDef  def,
in Segment  segment 
)
inline

Create a shape on the specified body with the specified definition.

Parameters
bodyThe body on which to create the shape
defThe shape definition
segmentThe shape to create

◆ Shape() [3/4]

Box2D.Shape.Shape ( Body  body,
in ShapeDef  def,
in Capsule  capsule 
)
inline

Create a shape on the specified body with the specified definition.

Parameters
bodyThe body on which to create the shape
defThe shape definition
capsuleThe shape to create

◆ Shape() [4/4]

Box2D.Shape.Shape ( Body  body,
in ShapeDef  def,
in Polygon  polygon 
)
inline

Create a shape on the specified body with the specified definition.

Parameters
bodyThe body on which to create the shape
defThe shape definition
polygonThe shape to create

Member Function Documentation

◆ Destroy()

unsafe void Box2D.Shape.Destroy ( bool  updateBodyMass)
inline

Destroys this shape.

Parameters
updateBodyMassOption to defer the body mass update

You may defer the body mass update which can improve performance if several shapes on a body are destroyed at once

◆ GetCapsule()

unsafe Capsule Box2D.Shape.GetCapsule ( )

Gets a copy of the shape's capsule.

Returns
The capsule

Asserts the type is correct

◆ GetChainSegment()

unsafe ChainSegment Box2D.Shape.GetChainSegment ( )

Gets a copy of the shape's chain segment.

Returns
The chain segment

These come from chain shapes. Asserts the type is correct

◆ GetCircle()

unsafe Circle Box2D.Shape.GetCircle ( )

Gets a copy of the shape's circle.

Returns
The circle

Asserts the type is correct

◆ GetClosestPoint()

unsafe Vec2 Box2D.Shape.GetClosestPoint ( Vec2  target)
inline

Gets the closest point on this shape to a target point.

Parameters
targetThe target point
Returns
The closest point on this shape to the target point

Target and result are in world space

◆ GetParentChain()

unsafe ChainShape Box2D.Shape.GetParentChain ( )

Gets the parent chain id if the shape type is a chain segment.

Returns
The parent chain id if the shape type is a chain segment, otherwise returns 0

◆ GetPolygon()

unsafe Polygon Box2D.Shape.GetPolygon ( )

Gets a copy of the shape's convex polygon.

Returns
The polygon

Asserts the type is correct

◆ GetSegment()

unsafe Segment Box2D.Shape.GetSegment ( )

Gets a copy of the shape's line segment.

Returns
The segment

Asserts the type is correct

◆ operator!=()

static bool Box2D.Shape.operator!= ( Shape  left,
Shape  right 
)
static

Checks if this shape and another shape refer to different shapes.

Returns
true if this shape and the other shape refer to different shapes

◆ operator==()

static bool Box2D.Shape.operator== ( Shape  left,
Shape  right 
)
static

Checks if this shape and another shape refer to the same shape.

Returns
true if this shape and the other shape refer to the same shape

◆ RayCast()

unsafe CastOutput Box2D.Shape.RayCast ( in RayCastInput  input)

Ray casts this shape directly.

Parameters
inputThe ray cast input
Returns
The ray cast output

◆ SetCapsule()

unsafe void Box2D.Shape.SetCapsule ( in Capsule  capsule)

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

Parameters
capsuleThe capsule

This does not modify the mass properties

◆ SetCircle()

unsafe void Box2D.Shape.SetCircle ( in Circle  circle)

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

Parameters
circleThe circle

This does not modify the mass properties

◆ SetDensity()

unsafe void Box2D.Shape.SetDensity ( float  density,
bool  updateBodyMass 
)

Sets the mass density of this shape.

Parameters
densityThe mass density
updateBodyMassOption to update the mass properties on the parent body

This will optionally update the mass properties on the parent body

◆ SetPolygon()

unsafe void Box2D.Shape.SetPolygon ( in Polygon  polygon)

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

Parameters
polygonThe polygon

This does not modify the mass properties

◆ SetSegment()

unsafe void Box2D.Shape.SetSegment ( in Segment  segment)

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

Parameters
segmentThe segment

◆ TestPoint()

unsafe bool Box2D.Shape.TestPoint ( Vec2  point)

Tests a point for overlap with this shape.

Parameters
pointThe point
Returns
true if the point overlaps with this shape

Property Documentation

◆ AABB

unsafe AABB Box2D.Shape.AABB
get

Gets the current world AABB.

Returns
The current world AABB

This is the axis-aligned bounding box in world coordinates

◆ Body

unsafe Body Box2D.Shape.Body
get

Gets the body that this shape is attached to.

Returns
The body that this shape is attached to

◆ Density

unsafe float Box2D.Shape.Density
getset

The mass density of this shape.

This will update the mass properties on the parent body. To avoid this, use SetDensity(float,bool)

◆ Filter

unsafe Filter Box2D.Shape.Filter
getset

The filter for this 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.

◆ Material

unsafe int Box2D.Shape.Material
getset

Gets/sets the material ID for this shape - this does not affect the shape's physical properties.

This is just for convenience. It is not used in the Box2D engine. There is no register of materials, and modifying this property does not modify the behaviour of the shape.

◆ PreSolveEventsEnabled

unsafe bool Box2D.Shape.PreSolveEventsEnabled
getset

The pre-solve contact enabled state for this shape.

Only applies to dynamic bodies.

Warning: These are expensive and must be carefully handled due to multithreading.

Ignored for sensors

◆ Restitution

unsafe float Box2D.Shape.Restitution
getset

Restitution of this shape.

This is the coefficient of restitution (bounce) usually in the range [0,1].

◆ Sensor

unsafe bool Box2D.Shape.Sensor
get

Checks if this shape is a sensor.

Returns
true if this 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.

◆ SensorOverlaps

unsafe ReadOnlySpan<Shape> Box2D.Shape.SensorOverlaps
get

Gets the overlapped shapes for this sensor shape.

Overlaps may contain destroyed shapes so use Valid to confirm each overlap.

Warning: Do not fetch this property during the contact callbacks

◆ Type

unsafe ShapeType Box2D.Shape.Type
get

Gets the type of this shape.

Returns
The type of this shape

◆ Valid

unsafe bool Box2D.Shape.Valid
get

Checks if this shape is valid.

Returns
true if this shape is valid

Provides validation for up to 64K allocations


The documentation for this struct was generated from the following files: