HughPH.Box2D
Organised dotnet bindings for Box2D 3.1.0
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 >.

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.
 
void Destroy (bool updateBodyMass)
 Destroys this shape.
 
void SetDensity (float density, bool updateBodyMass)
 Sets the mass density of this shape.
 
bool TestPoint (Vec2 point)
 Tests a point for overlap with this shape.
 
CastOutput RayCast (in RayCastInput input)
 Ray casts this shape directly.
 
Circle GetCircle ()
 Gets a copy of the shape's circle.
 
Segment GetSegment ()
 Gets a copy of the shape's line segment.
 
ChainSegment GetChainSegment ()
 Gets a copy of the shape's chain segment.
 
Capsule GetCapsule ()
 Gets a copy of the shape's capsule.
 
Polygon GetPolygon ()
 Gets a copy of the shape's convex polygon.
 
void SetCircle (in Circle circle)
 Allows you to change this shape to be a circle or update the current circle.
 
void SetCapsule (in Capsule capsule)
 Allows you to change this shape to be a capsule or update the current capsule.
 
void SetSegment (in Segment segment)
 Allows you to change this shape to be a segment or update the current segment.
 
void SetPolygon (in Polygon polygon)
 Allows you to change this shape to be a polygon or update the current polygon.
 
ChainShape GetParentChain ()
 Gets the parent chain id if the shape type is a chain segment.
 
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.
 
bool Valid [get]
 Checks if this shape is valid.
 
ShapeType Type [get]
 Gets the type of this shape.
 
Body Body [get]
 Gets the body that this shape is attached to.
 
World World [get]
 Gets the world that this shape belongs to.
 
bool Sensor [get]
 Checks if this shape is a sensor.
 
object? UserData [get, set]
 The user data object for this shape.
 
float Density [get, set]
 The mass density of this shape.
 
float Friction [get, set]
 The friction on this shape.
 
float Restitution [get, set]
 Restitution of this shape.
 
int Material [get, set]
 The material for this shape.
 
Filter Filter [get, set]
 The filter for this shape.
 
bool ContactEventsEnabled [get, set]
 Contact enabled state for this shape.
 
bool PreSolveEventsEnabled [get, set]
 The pre-solve contact enabled state for this shape.
 
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.
 
AABB AABB [get]
 Gets the current world AABB.
 
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()

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()

Capsule Box2D.Shape.GetCapsule ( )

Gets a copy of the shape's capsule.

Returns
The capsule

Asserts the type is correct

◆ GetChainSegment()

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()

Circle Box2D.Shape.GetCircle ( )

Gets a copy of the shape's circle.

Returns
The circle

Asserts the type is correct

◆ GetClosestPoint()

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()

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()

Polygon Box2D.Shape.GetPolygon ( )

Gets a copy of the shape's convex polygon.

Returns
The polygon

Asserts the type is correct

◆ GetSegment()

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()

CastOutput Box2D.Shape.RayCast ( in RayCastInput  input)

Ray casts this shape directly.

Parameters
inputThe ray cast input
Returns
The ray cast output

◆ SetCapsule()

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()

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()

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()

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()

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()

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

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

Body Box2D.Shape.Body
get

Gets the body that this shape is attached to.

Returns
The body that this shape is attached to

◆ Density

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

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

int Box2D.Shape.Material
getset

The material for this shape.

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

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

float Box2D.Shape.Restitution
getset

Restitution of this shape.

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

◆ Sensor

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

ShapeType Box2D.Shape.Type
get

Gets the type of this shape.

Returns
The type of this shape

◆ Valid

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 file: