org.jbox2d.collision.shapes
Class PolygonDef

java.lang.Object
  extended by org.jbox2d.collision.shapes.ShapeDef
      extended by org.jbox2d.collision.shapes.PolygonDef

public class PolygonDef
extends ShapeDef

Convex polygon. The vertices must be in CCW order for a right-handed coordinate system with the z-axis coming out of the screen. Add vertices using PolygonDef.add(Vec2), and create the polygon shape using Body::createShape(ShapeDef).


Field Summary
 List<Vec2> vertices
          The polygon vertices in local coordinates.
 
Fields inherited from class org.jbox2d.collision.shapes.ShapeDef
density, filter, friction, isSensor, restitution, type, userData
 
Constructor Summary
PolygonDef()
           
 
Method Summary
 void addVertex(Vec2 v)
          Add a vertex to the polygon.
 void clearVertices()
          Removes all vertices.
 Vec2[] getVertexArray()
          Return the vertex list as an array.
 int getVertexCount()
          Return the number of vertices.
 List<Vec2> getVertexList()
          Return the vertex list as a List.
 void set(PolygonDef copyMe)
           
 void setAsBox(float hx, float hy)
          Build vertices to represent an axis-aligned box.
 void setAsBox(float hx, float hy, Vec2 center, float angle)
          Build vertices to represent an oriented box.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

vertices

public List<Vec2> vertices
The polygon vertices in local coordinates.

Accessing this field is discouraged - it remains public for the moment, but that is likely to change. Please use addVertex(Vec2) and getVertexList/Array instead to add to or inspect the current vertices.

Constructor Detail

PolygonDef

public PolygonDef()
Method Detail

set

public void set(PolygonDef copyMe)

addVertex

public void addVertex(Vec2 v)
Add a vertex to the polygon.


clearVertices

public void clearVertices()
Removes all vertices.


getVertexArray

public Vec2[] getVertexArray()
Return the vertex list as an array.


getVertexList

public List<Vec2> getVertexList()
Return the vertex list as a List.


setAsBox

public 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 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.

getVertexCount

public int getVertexCount()
Return the number of vertices.