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

A solid convex polygon. It is assumed that the interior of the polygon is to the left of each edge. Polygons have a maximum number of vertices equal to B2_MAX_POLYGON_VERTICES. In most cases you should not need many vertices for a convex polygon. Warning: DO NOT fill this out manually, instead use a helper function like MakePolygon or MakeBox. More...

Public Member Functions

 Polygon (ReadOnlySpan< Vec2 > points, float radius=0f)
 Construct a polygon shape with a set of vertices and an optional radius.
 
static Polygon MakePolygon (in Hull hull, float radius)
 Make a convex polygon from a convex hull. This will assert if the hull is not valid.
 
static Polygon MakeOffsetPolygon (in Hull hull, Vec2 position, Rotation rotation)
 Make an offset convex polygon from a convex hull. This will assert if the hull is not valid.
 
static Polygon MakeOffsetRoundedPolygon (in Hull hull, Vec2 position, Rotation rotation, float radius)
 Make an offset convex polygon from a convex hull. This will assert if the hull is not valid.
 
static Polygon MakeSquare (float halfWidth)
 Make a square polygon, bypassing the need for a convex hull.
 
static Polygon MakeBox (float halfWidth, float halfHeight)
 Make a box (rectangle) polygon, bypassing the need for a convex hull.
 
static Polygon MakeRoundedBox (float halfWidth, float halfHeight, float radius)
 Make a rounded box, bypassing the need for a convex hull.
 
static Polygon MakeOffsetBox (float halfWidth, float halfHeight, Vec2 center, Rotation rotation)
 Make an offset box, bypassing the need for a convex hull.
 
static Polygon MakeOffsetRoundedBox (float halfWidth, float halfHeight, Vec2 center, Rotation rotation, float radius)
 Make an offset rounded box, bypassing the need for a convex hull.
 
static Polygon TransformPolygon (Transform transform, in Polygon polygon)
 Transform a polygon. This is useful for transferring a shape from one body to another.
 
MassData ComputeMass (float density)
 Compute mass properties of this polygon.
 
AABB ComputeAABB (in Transform transform)
 Compute the bounding box of this transformed polygon.
 
bool TestPoint (in Vec2 point)
 Test this point for overlap with a convex polygon in local space.
 
CastOutput RayCast (in RayCastInput input)
 Ray cast versus this polygon shape in local space. Initial overlap is treated as a miss.
 
CastOutput ShapeCast (in ShapeCastInput input)
 Shape cast versus this convex polygon. Initial overlap is treated as a miss.
 

Static Public Member Functions

static Polygon MakePolygon (ReadOnlySpan< Vec2 > points, float radius)
 Make a convex polygon from a set of points. This will create a hull and assert if it is not valid.
 
static Polygon MakeOffsetPolygon (Span< Vec2 > points, Vec2 position, Rotation rotation)
 Make an offset convex polygon from a set of points. This will create a hull and assert if it is not valid.
 
static Polygon MakeOffsetRoundedPolygon (Span< Vec2 > points, Vec2 position, Rotation rotation, float radius)
 Make an offset convex polygon from a set of points. This will create a hull and assert if it is not valid.
 

Public Attributes

Vec2 Centroid
 The centroid of the polygon.
 
float Radius
 The external radius for rounded polygons.
 

Properties

ReadOnlySpan< Vec2 > Vertices [get]
 The polygon vertices.
 
ReadOnlySpan< Vec2 > Normals [get]
 The outward normal vectors of the polygon sides.
 

Detailed Description

A solid convex polygon. It is assumed that the interior of the polygon is to the left of each edge. Polygons have a maximum number of vertices equal to B2_MAX_POLYGON_VERTICES. In most cases you should not need many vertices for a convex polygon. Warning: DO NOT fill this out manually, instead use a helper function like MakePolygon or MakeBox.

Constructor & Destructor Documentation

◆ Polygon()

Box2D.Polygon.Polygon ( ReadOnlySpan< Vec2 >  points,
float  radius = 0f 
)
inline

Construct a polygon shape with a set of vertices and an optional radius.

This constructor implicitly creates a Hull from the points. The hull is computed in the order of the points. The hull is assumed to be convex.
A radius greater than 0 will create a rounded polygon. A negative radius is invalid.

Member Function Documentation

◆ MakeBox()

static Polygon Box2D.Polygon.MakeBox ( float  halfWidth,
float  halfHeight 
)

Make a box (rectangle) polygon, bypassing the need for a convex hull.

Parameters
halfWidththe half-width (x-axis)
halfHeightthe half-height (y-axis)

◆ MakeOffsetBox()

static Polygon Box2D.Polygon.MakeOffsetBox ( float  halfWidth,
float  halfHeight,
Vec2  center,
Rotation  rotation 
)

Make an offset box, bypassing the need for a convex hull.

Parameters
halfWidththe half-width (x-axis)
halfHeightthe half-height (y-axis)
centerthe local center of the box
rotationthe local rotation of the box

◆ MakeOffsetPolygon()

static Polygon Box2D.Polygon.MakeOffsetPolygon ( in Hull  hull,
Vec2  position,
Rotation  rotation 
)

Make an offset convex polygon from a convex hull. This will assert if the hull is not valid.

Warning: Do not manually fill in the hull data, it must come directly from b2ComputeHull

◆ MakeOffsetRoundedBox()

static Polygon Box2D.Polygon.MakeOffsetRoundedBox ( float  halfWidth,
float  halfHeight,
Vec2  center,
Rotation  rotation,
float  radius 
)

Make an offset rounded box, bypassing the need for a convex hull.

Parameters
halfWidththe half-width (x-axis)
halfHeightthe half-height (y-axis)
centerthe local center of the box
rotationthe local rotation of the box
radiusthe radius of the rounded extension

◆ MakeOffsetRoundedPolygon()

static Polygon Box2D.Polygon.MakeOffsetRoundedPolygon ( in Hull  hull,
Vec2  position,
Rotation  rotation,
float  radius 
)

Make an offset convex polygon from a convex hull. This will assert if the hull is not valid.

Warning: Do not manually fill in the hull data, it must come directly from b2ComputeHull

◆ MakePolygon()

static Polygon Box2D.Polygon.MakePolygon ( in Hull  hull,
float  radius 
)

Make a convex polygon from a convex hull. This will assert if the hull is not valid.

Warning: Do not manually fill in the hull data, it must come directly from b2ComputeHull

◆ MakeRoundedBox()

static Polygon Box2D.Polygon.MakeRoundedBox ( float  halfWidth,
float  halfHeight,
float  radius 
)

Make a rounded box, bypassing the need for a convex hull.

Parameters
halfWidththe half-width (x-axis)
halfHeightthe half-height (y-axis)
radiusthe radius of the rounded extension

◆ MakeSquare()

static Polygon Box2D.Polygon.MakeSquare ( float  halfWidth)

Make a square polygon, bypassing the need for a convex hull.

Parameters
halfWidththe half-width

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