HughPH.Box2D
Organised dotnet bindings for Box2D 3.1.0
|
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< Shape > | DefaultComparer = 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< Shape > | DefaultEqualityComparer = 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< ContactData > | ContactData [get] |
Gets the contact data for this shape. | |
unsafe ReadOnlySpan< Shape > | SensorOverlaps [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. | |
A shape is a geometric object used for collision detection.
Create a shape on the specified body with the specified definition.
body | The body on which to create the shape |
def | The shape definition |
circle | The shape to create |
Create a shape on the specified body with the specified definition.
body | The body on which to create the shape |
def | The shape definition |
segment | The shape to create |
Create a shape on the specified body with the specified definition.
body | The body on which to create the shape |
def | The shape definition |
capsule | The shape to create |
Create a shape on the specified body with the specified definition.
body | The body on which to create the shape |
def | The shape definition |
polygon | The shape to create |
|
inline |
Destroys this shape.
updateBodyMass | Option 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
Capsule Box2D.Shape.GetCapsule | ( | ) |
Gets a copy of the shape's capsule.
Asserts the type is correct
ChainSegment Box2D.Shape.GetChainSegment | ( | ) |
Gets a copy of the shape's chain segment.
These come from chain shapes. Asserts the type is correct
Circle Box2D.Shape.GetCircle | ( | ) |
Gets a copy of the shape's circle.
Asserts the type is correct
|
inline |
Gets the closest point on this shape to a target point.
target | The target point |
Target and result are in world space
ChainShape Box2D.Shape.GetParentChain | ( | ) |
Gets the parent chain id if the shape type is a chain segment.
Polygon Box2D.Shape.GetPolygon | ( | ) |
Gets a copy of the shape's convex polygon.
Asserts the type is correct
Segment Box2D.Shape.GetSegment | ( | ) |
Gets a copy of the shape's line segment.
Asserts the type is correct
Checks if this shape and another shape refer to different shapes.
Checks if this shape and another shape refer to the same shape.
CastOutput Box2D.Shape.RayCast | ( | in RayCastInput | input | ) |
Ray casts this shape directly.
input | The ray cast input |
void Box2D.Shape.SetCapsule | ( | in Capsule | capsule | ) |
Allows you to change this shape to be a capsule or update the current capsule.
capsule | The capsule |
This does not modify the mass properties
void Box2D.Shape.SetCircle | ( | in Circle | circle | ) |
Allows you to change this shape to be a circle or update the current circle.
circle | The circle |
This does not modify the mass properties
void Box2D.Shape.SetDensity | ( | float | density, |
bool | updateBodyMass | ||
) |
Sets the mass density of this shape.
density | The mass density |
updateBodyMass | Option to update the mass properties on the parent body |
This will optionally update the mass properties on the parent body
void Box2D.Shape.SetPolygon | ( | in Polygon | polygon | ) |
Allows you to change this shape to be a polygon or update the current polygon.
polygon | The polygon |
This does not modify the mass properties
void Box2D.Shape.SetSegment | ( | in Segment | segment | ) |
Allows you to change this shape to be a segment or update the current segment.
segment | The segment |
bool Box2D.Shape.TestPoint | ( | Vec2 | point | ) |
Tests a point for overlap with this shape.
point | The point |
|
get |
Gets the current world AABB.
This is the axis-aligned bounding box in world coordinates
|
get |
Gets the body that this shape is attached to.
|
getset |
The mass density of this shape.
This will update the mass properties on the parent body. To avoid this, use SetDensity(float,bool)
|
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.
|
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.
|
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
|
getset |
Restitution of this shape.
This is the coefficient of restitution (bounce) usually in the range [0,1].
|
get |
Checks 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.
|
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
|
get |
Gets the type of this shape.
|
get |
Checks if this shape is valid.
Provides validation for up to 64K allocations