public class PolygonShape

  1. Object
  2. Shape
  3. PolygonShape
A convex polygon shape. Polygons have a maximum number of vertices equal to _maxPolygonVertices. In most cases you should not need many vertices for a convex polygon.

Fields

public final Vec2 m_centroidLocal position of the shape centroid in parent body frame.
public final Vec2[] m_verticesThe vertices of the shape.
public final Vec2[] m_normalsThe normals of the shape.
public int m_countNumber of active vertices in the shape.

Constructors

public PolygonShape()

Methods

public final Shape clone()
public final void set(Vec2[] vertices, int count)Create a convex hull from the given array of points.
public final void set(Vec2[] verts, int num, Vec2Array vecPool, IntArray intPool)Create a convex hull from the given array of points.
public final void setAsBox(float hx, float hy)Build vertices to represent an axis-aligned box.
public final void setAsBox(float hx, float hy, Vec2 center, float angle)Build vertices to represent an oriented box.
public int getChildCount()Get the number of child primitives
public final boolean testPoint(Transform xf, Vec2 p)Test a point for containment in this shape.
public final void computeAABB(AABB aabb, Transform xf, int childIndex)Given a transform, compute the associated axis aligned bounding box for a child shape.
public final int getVertexCount()Get the vertex count.
public final Vec2 getVertex(int index)Get a vertex by index.
public final boolean raycast(RayCastOutput output, RayCastInput input, Transform xf, int childIndex)Cast a ray against a child shape.
public final void computeCentroidToOut(Vec2[] vs, int count, Vec2 out)
public void computeMass(MassData massData, float density)Compute the mass properties of this shape using its dimensions and density.
public boolean validate()Validate convexity.
public Vec2[] getVertices()Get the vertices in local coordinates.
public Vec2[] getNormals()Get the edge normal vectors.
public Vec2 centroid(Transform xf)Get the centroid and apply the supplied transform.
public Vec2 centroidToOut(Transform xf, Vec2 out)Get the centroid and apply the supplied transform.

Inherited fields

Inherited methods

Field details

m_centroid

public final Vec2 m_centroid
Local position of the shape centroid in parent body frame.

m_vertices

public final Vec2[] m_vertices
The vertices of the shape. Note: use getVertexCount(), not m_vertices.length, to get number of active vertices.

m_normals

public final Vec2[] m_normals
The normals of the shape. Note: use getVertexCount(), not m_normals.length, to get number of active normals.

m_count

public int m_count
Number of active vertices in the shape.

Constructor details

PolygonShape

public PolygonShape()

Method details

clone

public final Shape clone()

set

public final void set(Vec2[] vertices, int count)
Create a convex hull from the given array of points. The count must be in the range [3, Settings.maxPolygonVertices].
Warning. the points may be re-ordered, even if they form a convex polygon
Warning. collinear points are handled but not removed. Collinear points may lead to poor stacking behavior.

set

public final void set(Vec2[] verts, int num, Vec2Array vecPool, IntArray intPool)
Create a convex hull from the given array of points. The count must be in the range [3, Settings.maxPolygonVertices]. This method takes an arraypool for pooling
Warning. the points may be re-ordered, even if they form a convex polygon
Warning. collinear points are handled but not removed. Collinear points may lead to poor stacking behavior.

setAsBox

public final void setAsBox(float hx, float hy)
Build vertices to represent an axis-aligned box.

Parameters

hx float
the half-width.
hy float
the half-height.

setAsBox

public final void setAsBox(float hx, float hy, Vec2 center, float angle)
Build vertices to represent an oriented box.

Parameters

hx float
the half-width.
hy float
the half-height.
center Vec2
the center of the box in local coordinates.
angle float
the rotation of the box in local coordinates.

getChildCount

public int getChildCount()
Get the number of child primitives

testPoint

public final boolean testPoint(Transform xf, Vec2 p)
Test a point for containment in this shape. This only works for convex shapes.

Parameters

xf Transform
the shape world transform.
p Vec2
a point in world coordinates.

computeAABB

public final void computeAABB(AABB aabb, Transform xf, int childIndex)
Given a transform, compute the associated axis aligned bounding box for a child shape.

getVertexCount

public final int getVertexCount()
Get the vertex count.

getVertex

public final Vec2 getVertex(int index)
Get a vertex by index.

raycast

public final boolean raycast(RayCastOutput output, RayCastInput input, Transform xf, int childIndex)
Cast a ray against a child shape.

Returns

if hit

computeCentroidToOut

public final void computeCentroidToOut(Vec2[] vs, int count, Vec2 out)

computeMass

public void computeMass(MassData massData, float density)
Compute the mass properties of this shape using its dimensions and density. The inertia tensor is computed about the local origin.

Parameters

massData MassData
returns the mass data for this shape.
density float
the density in kilograms per meter squared.

validate

public boolean validate()
Validate convexity. This is a very time consuming operation.

getVertices

public Vec2[] getVertices()
Get the vertices in local coordinates.

getNormals

public Vec2[] getNormals()
Get the edge normal vectors. There is one for each vertex.

centroid

public Vec2 centroid(Transform xf)
Get the centroid and apply the supplied transform.

centroidToOut

public Vec2 centroidToOut(Transform xf, Vec2 out)
Get the centroid and apply the supplied transform.