public abstract class Shape

  1. Object
  2. Shape

Known subtypesChainShape, CircleShape, EdgeShape, PolygonShape

A shape is used for collision detection. You can create a shape however you like. Shapes used for simulation in World are created automatically when a Fixture is created. Shapes may encapsulate a one or more child shapes.

Fields

public final ShapeType m_type
public float m_radius

Constructors

public Shape(ShapeType type)

Methods

public ShapeType getType()Get the type of this shape.
public float getRadius()The radius of the underlying shape.
public void setRadius(float radius)Sets the radius of the underlying shape.
public abstract int getChildCount()Get the number of child primitives
public abstract boolean testPoint(Transform xf, Vec2 p)Test a point for containment in this shape.
public abstract boolean raycast(RayCastOutput output, RayCastInput input, Transform transform, int childIndex)Cast a ray against a child shape.
public abstract void computeAABB(AABB aabb, Transform xf, int childIndex)Given a transform, compute the associated axis aligned bounding box for a child shape.
public abstract void computeMass(MassData massData, float density)Compute the mass properties of this shape using its dimensions and density.
public abstract Shape clone()

Inherited methods

Field details

m_type

public final ShapeType m_type

m_radius

public float m_radius

Constructor details

Shape

public Shape(ShapeType type)

Method details

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.

getRadius

public float getRadius()
The radius of the underlying shape. This can refer to different things depending on the shape implementation

setRadius

public void setRadius(float radius)
Sets the radius of the underlying shape. This can refer to different things depending on the implementation

getChildCount

public abstract int getChildCount()
Get the number of child primitives

testPoint

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

Parameters

xf Transform
the shape world transform.
p Vec2
a point in world coordinates.

raycast

public abstract boolean raycast(RayCastOutput output, RayCastInput input, Transform transform, int childIndex)
Cast a ray against a child shape.

Returns

if hit

computeAABB

public abstract void computeAABB(AABB aabb, Transform xf, int childIndex)
Given a transform, compute the associated axis aligned bounding box for a child shape.

computeMass

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

Parameters

massData MassData
returns the mass data for this shape.
density float
the density in kilograms per meter squared.

clone

public abstract Shape clone()