Package org.jbox2d.collision.shapes
Class PolygonShape
- java.lang.Object
-
- org.jbox2d.collision.shapes.Shape
-
- org.jbox2d.collision.shapes.PolygonShape
-
public class PolygonShape extends Shape
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.
-
-
Field Summary
Fields Modifier and Type Field Description Vec2m_centroidLocal position of the shape centroid in parent body frame.intm_countNumber of active vertices in the shape.private static booleanm_debugDump lots of debug information.Vec2[]m_normalsThe normals of the shape.Vec2[]m_verticesThe vertices of the shape.private Vec2pool1private Vec2pool2private Vec2pool3private Vec2pool4private Transformpoolt1
-
Constructor Summary
Constructors Constructor Description PolygonShape()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Vec2centroid(Transform xf)Get the centroid and apply the supplied transform.Vec2centroidToOut(Transform xf, Vec2 out)Get the centroid and apply the supplied transform.Shapeclone()voidcomputeAABB(AABB aabb, Transform xf, int childIndex)Given a transform, compute the associated axis aligned bounding box for a child shape.voidcomputeCentroidToOut(Vec2[] vs, int count, Vec2 out)voidcomputeMass(MassData massData, float density)Compute the mass properties of this shape using its dimensions and density.intgetChildCount()Get the number of child primitivesVec2[]getNormals()Get the edge normal vectors.Vec2getVertex(int index)Get a vertex by index.intgetVertexCount()Get the vertex count.Vec2[]getVertices()Get the vertices in local coordinates.booleanraycast(RayCastOutput output, RayCastInput input, Transform xf, int childIndex)Cast a ray against a child shape.voidset(Vec2[] vertices, int count)Create a convex hull from the given array of points.voidset(Vec2[] verts, int num, Vec2Array vecPool, IntArray intPool)Create a convex hull from the given array of points.voidsetAsBox(float hx, float hy)Build vertices to represent an axis-aligned box.voidsetAsBox(float hx, float hy, Vec2 center, float angle)Build vertices to represent an oriented box.booleantestPoint(Transform xf, Vec2 p)Test a point for containment in this shape.booleanvalidate()Validate convexity.
-
-
-
Field Detail
-
m_debug
private static final boolean m_debug
Dump lots of debug information.- See Also:
- Constant Field Values
-
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.
-
pool1
private final Vec2 pool1
-
pool2
private final Vec2 pool2
-
pool3
private final Vec2 pool3
-
pool4
private final Vec2 pool4
-
poolt1
private Transform poolt1
-
-
Method Detail
-
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].
-
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
-
setAsBox
public final void setAsBox(float hx, float hy)Build vertices to represent an axis-aligned box.- Parameters:
hx- the half-width.hy- 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- the half-width.hy- the half-height.center- the center of the box in local coordinates.angle- the rotation of the box in local coordinates.
-
getChildCount
public int getChildCount()
Description copied from class:ShapeGet the number of child primitives- Specified by:
getChildCountin classShape- Returns:
-
testPoint
public final boolean testPoint(Transform xf, Vec2 p)
Description copied from class:ShapeTest a point for containment in this shape. This only works for convex shapes.
-
computeAABB
public final void computeAABB(AABB aabb, Transform xf, int childIndex)
Description copied from class:ShapeGiven a transform, compute the associated axis aligned bounding box for a child shape.- Specified by:
computeAABBin classShape
-
getVertexCount
public final int getVertexCount()
Get the vertex count.- Returns:
-
getVertex
public final Vec2 getVertex(int index)
Get a vertex by index.- Parameters:
index-- Returns:
-
raycast
public final boolean raycast(RayCastOutput output, RayCastInput input, Transform xf, int childIndex)
Description copied from class:ShapeCast a ray against a child shape.
-
computeMass
public void computeMass(MassData massData, float density)
Description copied from class:ShapeCompute the mass properties of this shape using its dimensions and density. The inertia tensor is computed about the local origin.- Specified by:
computeMassin classShape- Parameters:
massData- returns the mass data for this shape.density- the density in kilograms per meter squared.
-
validate
public boolean validate()
Validate convexity. This is a very time consuming operation.- Returns:
-
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.
-
-