public class ChainShape

  1. Object
  2. Shape
  3. ChainShape
A chain shape is a free form sequence of line segments. The chain has two-sided collision, so you can use inside and outside collision. Therefore, you may use any winding order. Since there may be many vertices, they are allocated using Alloc. Connectivity information is used to create smooth collisions. WARNING The chain will not collide properly if there are self-intersections.

Fields

public Vec2[] m_vertices
public int m_count
public final Vec2 m_prevVertex
public final Vec2 m_nextVertex
public boolean m_hasPrevVertex
public boolean m_hasNextVertex

Constructors

public ChainShape()

Methods

public int getChildCount()Get the number of child primitives
public void getChildEdge(EdgeShape edge, int index)Get a child edge.
public boolean testPoint(Transform xf, Vec2 p)Test a point for containment in this shape.
public boolean raycast(RayCastOutput output, RayCastInput input, Transform xf, int childIndex)Cast a ray against a child shape.
public void computeAABB(AABB aabb, Transform xf, int childIndex)Given a transform, compute the associated axis aligned bounding box for a child shape.
public void computeMass(MassData massData, float density)Compute the mass properties of this shape using its dimensions and density.
public Shape clone()
public void createLoop(Vec2[] vertices, int count)Create a loop.
public void createChain(Vec2[] vertices, int count)Create a chain with isolated end vertices.
public void setPrevVertex(Vec2 prevVertex)Establish connectivity to a vertex that precedes the first vertex.
public void setNextVertex(Vec2 nextVertex)Establish connectivity to a vertex that follows the last vertex.

Inherited fields

Inherited methods

Field details

m_vertices

public Vec2[] m_vertices

m_count

public int m_count

m_prevVertex

public final Vec2 m_prevVertex

m_nextVertex

public final Vec2 m_nextVertex

m_hasPrevVertex

public boolean m_hasPrevVertex

m_hasNextVertex

public boolean m_hasNextVertex

Constructor details

ChainShape

public ChainShape()

Method details

getChildCount

public int getChildCount()
Get the number of child primitives

getChildEdge

public void getChildEdge(EdgeShape edge, int index)
Get a child edge.

testPoint

public 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 boolean raycast(RayCastOutput output, RayCastInput input, Transform xf, int childIndex)
Cast a ray against a child shape.

Returns

if hit

computeAABB

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

computeMass

public 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 Shape clone()

createLoop

public void createLoop(Vec2[] vertices, int count)
Create a loop. This automatically adjusts connectivity.

Parameters

vertices Vec2[]
an array of vertices, these are copied
count int
the vertex count

createChain

public void createChain(Vec2[] vertices, int count)
Create a chain with isolated end vertices.

Parameters

vertices Vec2[]
an array of vertices, these are copied
count int
the vertex count

setPrevVertex

public void setPrevVertex(Vec2 prevVertex)
Establish connectivity to a vertex that precedes the first vertex. Don’t call this for loops.

setNextVertex

public void setNextVertex(Vec2 nextVertex)
Establish connectivity to a vertex that follows the last vertex. Don’t call this for loops.