Class PolygonShape
java.lang.Object
org.jbox2d.collision.shapes.Shape
org.jbox2d.collision.shapes.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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal Vec2Local position of the shape centroid in parent body frame.intNumber of active vertices in the shape.private static final booleanDump lots of debug information.final Vec2[]The normals of the shape.final Vec2[]The vertices of the shape.private final Vec2private final Vec2private final Vec2private final Vec2private Transform -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet the centroid and apply the supplied transform.centroidToOut(Transform xf, Vec2 out) Get the centroid and apply the supplied transform.final Shapeclone()final voidcomputeAABB(AABB aabb, Transform xf, int childIndex) Given a transform, compute the associated axis aligned bounding box for a child shape.final voidcomputeCentroidToOut(Vec2[] vs, int count, Vec2 out) voidcomputeMass(MassData massData, float density) Compute the mass properties of this shape using its dimensions and density.intGet the number of child primitivesVec2[]Get the edge normal vectors.final Vec2getVertex(int index) Get a vertex by index.final intGet the vertex count.Vec2[]Get the vertices in local coordinates.final booleanraycast(RayCastOutput output, RayCastInput input, Transform xf, int childIndex) Cast a ray against a child shape.final voidCreate a convex hull from the given array of points.final voidCreate a convex hull from the given array of points.final voidsetAsBox(float hx, float hy) Build vertices to represent an axis-aligned box.final voidBuild vertices to represent an oriented box.final booleanTest a point for containment in this shape.booleanvalidate()Validate convexity.Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
m_debug
private static final boolean m_debugDump lots of debug information.- See Also:
-
m_centroid
Local position of the shape centroid in parent body frame. -
m_vertices
The vertices of the shape. Note: use getVertexCount(), not m_vertices.length, to get number of active vertices. -
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_countNumber of active vertices in the shape. -
pool1
-
pool2
-
pool3
-
pool4
-
poolt1
-
-
Constructor Details
-
PolygonShape
public PolygonShape()
-
-
Method Details
-
clone
-
set
Create a convex hull from the given array of points. The count must be in the range [3, Settings.maxPolygonVertices]. -
set
-
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
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
-
computeAABB
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
-
raycast
public final boolean raycast(RayCastOutput output, RayCastInput input, Transform xf, int childIndex) Description copied from class:ShapeCast a ray against a child shape. -
computeCentroidToOut
-
computeMass
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
Get the vertices in local coordinates. -
getNormals
Get the edge normal vectors. There is one for each vertex. -
centroid
-
centroidToOut
-