Package org.jbox2d.dynamics
Class Fixture
java.lang.Object
org.jbox2d.dynamics.Fixture
A fixture is used to attach a shape to a body for collision detection. A
fixture inherits its transform from its parent. Fixtures hold additional
non-geometric data such as friction, collision filters, etc. Fixtures are
created via Body::CreateFixture.
- Author:
- Daniel Murphy
- Warning:
- you cannot reuse fixtures.
-
Field Summary
FieldsModifier and TypeFieldDescriptionfloatThe density, usually in kg/m^2final FilterContact filtering data;floatThe friction coefficient, usually in the range [0,1].booleanA sensor shape collects contact information but never generates a collision response.intfloatThe restitution (elasticity) usually in the range [0,1].The shape, this must be set.Use this to store application specific fixture data. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfloatcomputeDistance(Vec2 p, int childIndex, Vec2 normalOut) Compute the distance from this fixture.voidcreate(Body body, FixtureDef def) voidcreateProxies(BroadPhase broadPhase, Transform xf) voiddestroy()voiddestroyProxies(BroadPhase broadPhase) Internal methodgetAABB(int childIndex) Get the fixture's AABB.getBody()Get the parent body of this fixture.floatGet the contact filtering data.floatGet the coefficient of friction.voidgetMassData(MassData massData) Get the mass data for this fixture.getNext()Get the next fixture in the parent body's fixture list.floatGet the coefficient of restitution.getShape()Get the child shape.getType()Get the type of the child shape.Get the user data that was assigned in the fixture definition.booleanisSensor()Is this fixture a sensor (non-solid)?booleanraycast(RayCastOutput output, RayCastInput input, int childIndex) Cast a ray against this shape.voidrefilter()Call this if you want to establish a collision that was previously disabled by ContactFilter::ShouldCollide.voidsetDensity(float density) voidsetFilterData(Filter filter) Set the contact filtering data.voidsetFriction(float friction) Set the coefficient of friction.voidsetRestitution(float restitution) Set the coefficient of restitution.voidsetSensor(boolean sensor) Set if this fixture is a sensor.voidsetUserData(Object data) Set the user data.protected voidsynchronize(BroadPhase broadPhase, Transform transform1, Transform transform2) Internal methodbooleanTest a point for containment in this fixture.
-
Field Details
-
next
-
body
-
shape
The shape, this must be set. The shape will be cloned, so you can create the shape on the stack. -
userData
Use this to store application specific fixture data. -
friction
public float frictionThe friction coefficient, usually in the range [0,1]. -
restitution
public float restitutionThe restitution (elasticity) usually in the range [0,1]. -
density
public float densityThe density, usually in kg/m^2 -
isSensor
public boolean isSensorA sensor shape collects contact information but never generates a collision response. -
filter
Contact filtering data; -
proxies
-
proxyCount
public int proxyCount
-
-
Constructor Details
-
Fixture
public Fixture()
-
-
Method Details
-
getType
Get the type of the child shape. You can use this to downcast to the concrete shape.- Returns:
- The shape type.
-
getShape
Get the child shape. You can modify the child shape, however, you should not change the number of vertices because this will crash some collision caching mechanisms. -
isSensor
public boolean isSensor()Is this fixture a sensor (non-solid)?- Returns:
- The true if the shape is a sensor.
-
setSensor
public void setSensor(boolean sensor) Set if this fixture is a sensor. -
setFilterData
Set the contact filtering data. This is an expensive operation and should not be called frequently. This will not update contacts until the next time step when either parent body is awake. This automatically calls refilter. -
getFilterData
Get the contact filtering data. -
refilter
public void refilter()Call this if you want to establish a collision that was previously disabled by ContactFilter::ShouldCollide. -
getBody
Get the parent body of this fixture. This is NULL if the fixture is not attached.- Returns:
- The parent body.
-
getNext
Get the next fixture in the parent body's fixture list.- Returns:
- The next shape.
-
setDensity
public void setDensity(float density) -
getDensity
public float getDensity() -
getUserData
Get the user data that was assigned in the fixture definition. Use this to store your application-specific data. -
setUserData
Set the user data. Use this to store your application-specific data. -
testPoint
Test a point for containment in this fixture. This only works for convex shapes.- Parameters:
p- A point in the world coordinates.
-
raycast
Cast a ray against this shape.- Parameters:
output- The ray-cast results.input- The ray-cast input parameters.
-
getMassData
Get the mass data for this fixture. The mass data is based on the density and the shape. The rotational inertia is about the shape's origin. -
getFriction
public float getFriction()Get the coefficient of friction. -
setFriction
public void setFriction(float friction) Set the coefficient of friction. This will _not_ change the friction of existing contacts. -
getRestitution
public float getRestitution()Get the coefficient of restitution. -
setRestitution
public void setRestitution(float restitution) Set the coefficient of restitution. This will _not_ change the restitution of existing contacts. -
getAABB
Get the fixture's AABB. This AABB may be enlarge and/or stale. If you need a more accurate AABB, compute it using the shape and the body transform. -
computeDistance
Compute the distance from this fixture.- Parameters:
p- A point in world coordinates.- Returns:
- distance
-
create
-
destroy
public void destroy() -
createProxies
-
destroyProxies
Internal method -
synchronize
Internal method
-