org.jbox2d.collision
Class PolygonShape

java.lang.Object
  extended by org.jbox2d.collision.Shape
      extended by org.jbox2d.collision.PolygonShape
All Implemented Interfaces:
SupportsGenericDistance

public class PolygonShape
extends Shape
implements SupportsGenericDistance

A convex polygon shape. Create using Body.createShape(ShapeDef), not the constructor here.


Field Summary
 Vec2 m_centroid
          Local position of the shape centroid in parent body frame.
 Vec2[] m_coreVertices
          The normals of the shape.
 Vec2[] m_normals
          The normals of the shape.
 OBB m_obb
          The oriented bounding box of the shape.
 int m_vertexCount
          Number of active vertices in the shape.
 Vec2[] m_vertices
          The vertices of the shape.
 
Fields inherited from class org.jbox2d.collision.Shape
m_body, m_density, m_filter, m_friction, m_isSensor, m_next, m_proxyId, m_restitution, m_sweepRadius, m_type, m_userData, uid
 
Constructor Summary
PolygonShape(ShapeDef def)
           
 
Method Summary
 Vec2 centroid(XForm xf)
          Get the centroid and apply the supplied transform.
 void computeAABB(AABB aabb, XForm xf)
          Given a transform, compute the associated axis aligned bounding box for this shape.
static Vec2 computeCentroid(java.util.List<Vec2> vs)
           
 void computeMass(MassData massData)
          Compute the mass properties of this shape using its dimensions and density.
static void computeOBB(OBB obb, Vec2[] vs)
           
 void computeSweptAABB(AABB aabb, XForm transform1, XForm transform2)
          Given two transforms, compute the associated swept axis aligned bounding box for this shape.
 Vec2 getCentroid()
          Get the local centroid relative to the parent body.
 Vec2[] getCoreVertices()
          Get the core vertices in local coordinates.
 Vec2 getFirstVertex(XForm xf)
          Get the first vertex and apply the supplied transform.
 Vec2[] getNormals()
          Get the edge normal vectors.
 OBB getOBB()
          Get the oriented bounding box relative to the parent body.
 int getVertexCount()
          Get the number of vertices.
 Vec2[] getVertices()
          Get the vertices in local coordinates.
 Vec2 support(XForm xf, Vec2 d)
          Get the support point in the given world direction.
 boolean testPoint(XForm xf, Vec2 p)
          Test a point for containment in this shape.
 void updateSweepRadius(Vec2 center)
          Internal
 
Methods inherited from class org.jbox2d.collision.Shape
create, createProxy, destroy, destroyProxy, destructor, getBody, getFilterData, getFriction, getNext, getRestitution, getSweepRadius, getType, getUserData, isSensor, refilterProxy, setFilterData, setFriction, setRestitution, setUserData, synchronize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_centroid

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


m_obb

public OBB m_obb
The oriented bounding box of the shape.


m_vertices

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


m_normals

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


m_coreVertices

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


m_vertexCount

public int m_vertexCount
Number of active vertices in the shape.

Constructor Detail

PolygonShape

public PolygonShape(ShapeDef def)
Method Detail

updateSweepRadius

public void updateSweepRadius(Vec2 center)
Description copied from class: Shape
Internal

Specified by:
updateSweepRadius in class Shape

testPoint

public boolean testPoint(XForm xf,
                         Vec2 p)
Description copied from class: Shape
Test a point for containment in this shape. This only works for convex shapes.

Specified by:
testPoint in class Shape
Parameters:
xf - the shape world transform.
p - a point in world coordinates.
Returns:
true if the point is within the shape

support

public Vec2 support(XForm xf,
                    Vec2 d)
Get the support point in the given world direction. Use the supplied transform.

Specified by:
support in interface SupportsGenericDistance

computeCentroid

public static Vec2 computeCentroid(java.util.List<Vec2> vs)

computeOBB

public static void computeOBB(OBB obb,
                              Vec2[] vs)

computeAABB

public void computeAABB(AABB aabb,
                        XForm xf)
Description copied from class: Shape
Given a transform, compute the associated axis aligned bounding box for this shape.

Specified by:
computeAABB in class Shape
Parameters:
aabb - returns the axis aligned box.
xf - the world transform of the shape.

computeSweptAABB

public void computeSweptAABB(AABB aabb,
                             XForm transform1,
                             XForm transform2)
Description copied from class: Shape
Given two transforms, compute the associated swept axis aligned bounding box for this shape.

Specified by:
computeSweptAABB in class Shape
Parameters:
aabb - returns the axis aligned box. (return parameter)
transform1 - the starting shape world transform.
transform2 - the ending shape world transform.

computeMass

public void computeMass(MassData massData)
Description copied from class: Shape
Compute the mass properties of this shape using its dimensions and density. The inertia tensor is computed about the local origin, not the centroid.

Specified by:
computeMass in class Shape
Parameters:
massData - returns the mass data for this shape. (return parameter)

getFirstVertex

public Vec2 getFirstVertex(XForm xf)
Get the first vertex and apply the supplied transform.

Specified by:
getFirstVertex in interface SupportsGenericDistance

getOBB

public OBB getOBB()
Get the oriented bounding box relative to the parent body.


getCentroid

public Vec2 getCentroid()
Get the local centroid relative to the parent body.


getVertexCount

public int getVertexCount()
Get the number of vertices.


getVertices

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


getCoreVertices

public Vec2[] getCoreVertices()
Get the core vertices in local coordinates. These vertices represent a smaller polygon that is used for time of impact computations.


getNormals

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


centroid

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