Box2D 2.4.1
A 2D physics engine for games
b2PolygonShape Class Reference

#include <b2_polygon_shape.h>

Inheritance diagram for b2PolygonShape:
b2Shape

Public Member Functions

b2ShapeClone (b2BlockAllocator *allocator) const override
 Implement b2Shape. More...
 
int32 GetChildCount () const override
 
void Set (const b2Vec2 *points, int32 count)
 
void SetAsBox (float hx, float hy)
 
void SetAsBox (float hx, float hy, const b2Vec2 &center, float angle)
 
bool TestPoint (const b2Transform &transform, const b2Vec2 &p) const override
 
bool RayCast (b2RayCastOutput *output, const b2RayCastInput &input, const b2Transform &transform, int32 childIndex) const override
 
void ComputeAABB (b2AABB *aabb, const b2Transform &transform, int32 childIndex) const override
 
void ComputeMass (b2MassData *massData, float density) const override
 
bool Validate () const
 
- Public Member Functions inherited from b2Shape
virtual b2ShapeClone (b2BlockAllocator *allocator) const =0
 Clone the concrete shape using the provided allocator. More...
 
Type GetType () const
 
virtual int32 GetChildCount () const =0
 Get the number of child primitives. More...
 
virtual bool TestPoint (const b2Transform &xf, const b2Vec2 &p) const =0
 
virtual bool RayCast (b2RayCastOutput *output, const b2RayCastInput &input, const b2Transform &transform, int32 childIndex) const =0
 
virtual void ComputeAABB (b2AABB *aabb, const b2Transform &xf, int32 childIndex) const =0
 
virtual void ComputeMass (b2MassData *massData, float density) const =0
 

Public Attributes

b2Vec2 m_centroid
 
b2Vec2 m_vertices [b2_maxPolygonVertices]
 
b2Vec2 m_normals [b2_maxPolygonVertices]
 
int32 m_count
 
- Public Attributes inherited from b2Shape
Type m_type
 
float m_radius
 

Additional Inherited Members

- Public Types inherited from b2Shape
enum  Type {
  e_circle = 0 , e_edge = 1 , e_polygon = 2 , e_chain = 3 ,
  e_typeCount = 4
}
 

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_maxPolygonVertices. In most cases you should not need many vertices for a convex polygon.

Member Function Documentation

◆ Clone()

b2Shape * b2PolygonShape::Clone ( b2BlockAllocator allocator) const
overridevirtual

Implement b2Shape.

Implements b2Shape.

◆ ComputeAABB()

void b2PolygonShape::ComputeAABB ( b2AABB aabb,
const b2Transform transform,
int32  childIndex 
) const
overridevirtual
See also
b2Shape::ComputeAABB

Implements b2Shape.

◆ ComputeMass()

void b2PolygonShape::ComputeMass ( b2MassData massData,
float  density 
) const
overridevirtual
See also
b2Shape::ComputeMass

Implements b2Shape.

◆ GetChildCount()

int32 b2PolygonShape::GetChildCount ( ) const
overridevirtual
See also
b2Shape::GetChildCount

Implements b2Shape.

◆ RayCast()

bool b2PolygonShape::RayCast ( b2RayCastOutput output,
const b2RayCastInput input,
const b2Transform transform,
int32  childIndex 
) const
overridevirtual

Implement b2Shape.

Note
because the polygon is solid, rays that start inside do not hit because the normal is not defined.

Implements b2Shape.

◆ Set()

void b2PolygonShape::Set ( const b2Vec2 points,
int32  count 
)

Create a convex hull from the given array of local points. The count must be in the range [3, b2_maxPolygonVertices].

Warning
the points may be re-ordered, even if they form a convex polygon
collinear points are handled but not removed. Collinear points may lead to poor stacking behavior.

◆ SetAsBox() [1/2]

void b2PolygonShape::SetAsBox ( float  hx,
float  hy 
)

Build vertices to represent an axis-aligned box centered on the local origin.

Parameters
hxthe half-width.
hythe half-height.

◆ SetAsBox() [2/2]

void b2PolygonShape::SetAsBox ( float  hx,
float  hy,
const b2Vec2 center,
float  angle 
)

Build vertices to represent an oriented box.

Parameters
hxthe half-width.
hythe half-height.
centerthe center of the box in local coordinates.
anglethe rotation of the box in local coordinates.

◆ TestPoint()

bool b2PolygonShape::TestPoint ( const b2Transform transform,
const b2Vec2 p 
) const
overridevirtual
See also
b2Shape::TestPoint

Implements b2Shape.

◆ Validate()

bool b2PolygonShape::Validate ( ) const

Validate convexity. This is a very time consuming operation.

Returns
true if valid

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