org.jbox2d.collision
Class Shape

java.lang.Object
  extended by org.jbox2d.collision.Shape
Direct Known Subclasses:
CircleShape, PolygonShape

public abstract class Shape
extends java.lang.Object

A shape is used for collision detection. Shapes are created in World. You can use shape for collision detection before they are attached to the world.

Warning: you cannot reuse shapes on different bodies, they must be re-created or copied.


Field Summary
 Body m_body
           
 float m_density
           
 FilterData m_filter
           
 float m_friction
           
 boolean m_isSensor
           
 Shape m_next
           
 int m_proxyId
           
 float m_restitution
           
 float m_sweepRadius
          Sweep radius relative to the parent body's center of mass.
 ShapeType m_type
           
 java.lang.Object m_userData
           
 int uid
          Unique id for shape for sorting (C++ version uses memory address)
 
Constructor Summary
Shape(ShapeDef def)
           
 
Method Summary
abstract  void computeAABB(AABB aabb, XForm xf)
          Given a transform, compute the associated axis aligned bounding box for this shape.
abstract  void computeMass(MassData massData)
          Compute the mass properties of this shape using its dimensions and density.
abstract  void computeSweptAABB(AABB aabb, XForm xf1, XForm xf2)
          Given two transforms, compute the associated swept axis aligned bounding box for this shape.
static Shape create(ShapeDef def)
          Internal
 void createProxy(BroadPhase broadPhase, XForm transform)
          Internal
static void destroy(Shape s)
          Internal
 void destroyProxy(BroadPhase broadPhase)
          Internal
 void destructor()
          Internal
 Body getBody()
          Get the parent body of this shape.
 FilterData getFilterData()
          Get the collision filtering data.
 float getFriction()
          Get the coefficient of friction.
 Shape getNext()
          Get the next shape in the parent body's shape list.
 float getRestitution()
          Get the coefficient of restitution.
 float getSweepRadius()
          Get the sweep radius of the shape.
 ShapeType getType()
          Get the type of this shape.
 java.lang.Object getUserData()
          Get the user data that was assigned in the shape definition.
 boolean isSensor()
          Is this shape a sensor (non-solid)?
 void refilterProxy(BroadPhase broadPhase, XForm transform)
          Internal
 void setFilterData(FilterData filter)
          Set the collision filtering data.
 void setFriction(float friction)
          Set the coefficient of friction.
 void setRestitution(float restitution)
          Set the coefficient of restitution.
 void setUserData(java.lang.Object o)
          Set the user data associated with the object.
 boolean synchronize(BroadPhase broadPhase, XForm transform1, XForm transform2)
          Internal
abstract  boolean testPoint(XForm xf, Vec2 p)
          Test a point for containment in this shape.
abstract  void updateSweepRadius(Vec2 center)
          Internal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

uid

public int uid
Unique id for shape for sorting (C++ version uses memory address)


m_type

public ShapeType m_type

m_next

public Shape m_next

m_body

public Body m_body

m_sweepRadius

public float m_sweepRadius
Sweep radius relative to the parent body's center of mass.


m_density

public float m_density

m_friction

public float m_friction

m_restitution

public float m_restitution

m_proxyId

public int m_proxyId

m_filter

public FilterData m_filter

m_isSensor

public boolean m_isSensor

m_userData

public java.lang.Object m_userData
Constructor Detail

Shape

public Shape(ShapeDef def)
Method Detail

getFriction

public float getFriction()
Get the coefficient of friction.


setFriction

public void setFriction(float friction)
Set the coefficient of friction.


getRestitution

public float getRestitution()
Get the coefficient of restitution.


setRestitution

public void setRestitution(float restitution)
Set the coefficient of restitution.


setFilterData

public void setFilterData(FilterData filter)
Set the collision filtering data.


getFilterData

public FilterData getFilterData()
Get the collision filtering data.


getType

public ShapeType getType()
Get the type of this shape. You can use this to down cast to the concrete shape.

Returns:
the shape type.

isSensor

public boolean isSensor()
Is this shape a sensor (non-solid)?

Returns:
the true if the shape is a sensor.

getUserData

public java.lang.Object getUserData()
Get the user data that was assigned in the shape definition. Use this to store your application specific data.


setUserData

public void setUserData(java.lang.Object o)
Set the user data associated with the object.

Parameters:
o - User data to set

getBody

public Body getBody()
Get the parent body of this shape. This is NULL if the shape is not attached.

Returns:
the parent body.

getNext

public Shape getNext()
Get the next shape in the parent body's shape list.

Returns:
the next shape.

getSweepRadius

public float getSweepRadius()
Get the sweep radius of the shape.

Returns:
the sweep radius

testPoint

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

Parameters:
xf - the shape world transform.
p - a point in world coordinates.
Returns:
true if the point is within the shape

computeAABB

public abstract void computeAABB(AABB aabb,
                                 XForm xf)
Given a transform, compute the associated axis aligned bounding box for this shape.

Parameters:
aabb - returns the axis aligned box.
xf - the world transform of the shape.

computeSweptAABB

public abstract void computeSweptAABB(AABB aabb,
                                      XForm xf1,
                                      XForm xf2)
Given two transforms, compute the associated swept axis aligned bounding box for this shape.

Parameters:
aabb - returns the axis aligned box. (return parameter)
xf1 - the starting shape world transform.
xf2 - the ending shape world transform.

computeMass

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

Parameters:
massData - returns the mass data for this shape. (return parameter)

updateSweepRadius

public abstract void updateSweepRadius(Vec2 center)
Internal


synchronize

public boolean synchronize(BroadPhase broadPhase,
                           XForm transform1,
                           XForm transform2)
Internal


refilterProxy

public void refilterProxy(BroadPhase broadPhase,
                          XForm transform)
Internal


create

public static Shape create(ShapeDef def)
Internal


destroy

public static void destroy(Shape s)
Internal


destructor

public void destructor()
Internal


createProxy

public void createProxy(BroadPhase broadPhase,
                        XForm transform)
Internal


destroyProxy

public void destroyProxy(BroadPhase broadPhase)
Internal