Class ChainShape

java.lang.Object
org.jbox2d.collision.shapes.Shape
org.jbox2d.collision.shapes.ChainShape

public class ChainShape extends Shape
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. Connectivity information is used to create smooth collisions. WARNING: The chain will not collide properly if there are self-intersections.
Author:
Daniel Murphy
Repolink:
Github: erincatto/box2d src/collision/b2_chain_shape.cpp
  • Field Details

    • vertices

      public Vec2[] vertices
    • count

      public int count
    • prevVertex

      public final Vec2 prevVertex
    • nextVertex

      public final Vec2 nextVertex
    • hasPrevVertex

      public boolean hasPrevVertex
    • hasNextVertex

      public boolean hasNextVertex
  • Constructor Details

    • ChainShape

      public ChainShape()
  • Method Details

    • clear

      public void clear()
    • getChildCount

      public int getChildCount()
      Description copied from class: Shape
      Get the number of child primitives
      Specified by:
      getChildCount in class Shape
    • getChildEdge

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

      public float computeDistanceToOut(Transform xf, Vec2 p, int childIndex, Vec2 normalOut)
      Description copied from class: Shape
      Compute the distance from the current shape to the specified point. This only works for convex shapes.
      Specified by:
      computeDistanceToOut in class Shape
      Parameters:
      xf - The shape world transform.
      p - A point in world coordinates.
      normalOut - Returns the direction in which the distance increases.
      Returns:
      distance returns the distance from the current shape.
    • testPoint

      public boolean testPoint(Transform 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.
    • raycast

      public boolean raycast(RayCastOutput output, RayCastInput input, Transform xf, int childIndex)
      Description copied from class: Shape
      Cast a ray against a child shape.
      Specified by:
      raycast in class Shape
      Parameters:
      output - The ray-cast results.
      input - The ray-cast input parameters.
      xf - The transform to be applied to the shape.
      childIndex - The child shape index
      Returns:
      if hit
    • computeAABB

      public void computeAABB(AABB aabb, Transform xf, int childIndex)
      Description copied from class: Shape
      Given a transform, compute the associated axis aligned bounding box for a child shape.
      Specified by:
      computeAABB in class Shape
      Parameters:
      aabb - Returns the axis aligned box.
      xf - The world transform of the shape.
    • computeMass

      public void computeMass(MassData massData, float density)
      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.
      Specified by:
      computeMass in class Shape
      Parameters:
      massData - Returns the mass data for this shape.
      density - The density in kilograms per meter squared.
    • clone

      public Shape clone()
      Specified by:
      clone in class Shape
    • createLoop

      public void createLoop(Vec2[] vertices, int count)
      Create a loop. This automatically adjusts connectivity.
      Parameters:
      vertices - An array of vertices, these are copied.
      count - The vertex count.
    • createChain

      public void createChain(Vec2[] vertices, int count)
      Create a chain with isolated end vertices.
      Parameters:
      vertices - An array of vertices, these are copied.
      count - 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.