Class PrimitiveShape

java.lang.Object
physics.collision.shape.PrimitiveShape
Direct Known Subclasses:
Circle, ConvexPolygon, Line, Point, Quadrilateral, Triangle

public abstract class PrimitiveShape extends Object
The PrimitiveShape is implicitly described by all its support vectors. A support vector is a point on the convex hull of a shape, that is furthest in the direction of a specified vector v. This class may contain information about explicit points on the edge too.
Since:
18.06.2021
Author:
Juyas
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected org.joml.Vector2f
    The centroid of the shape - the absolute vector (position is already added to it)
    protected final org.joml.Vector2f[]
    The coordinates of the shape - absolute coordinates (position is already added to it)
    protected Circle
    The boundingSphere of this shape represented by a Circle.
    protected final Face[]
    All faces of the shape
    protected org.joml.Vector2f
    The centroid of the shape - the relative vector to an imaginary origin near the shape
    protected final org.joml.Vector2f[]
    The coordinates of the shape - relative to an imaginary origin near the shape
    protected final int
    The amount of vertices of the shape
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    PrimitiveShape(org.joml.Vector2f... relatives)
    Create a polygon of the given coordinates.
    protected
    PrimitiveShape(ShapeType type, org.joml.Vector2f... relatives)
    Create a shape.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Will be called by setPosition(Vector2f) after the new position was set.
    final Circle
    A minimal sphere that contains the original shape.
    final org.joml.Vector2f
    The center point or weight point of the shape.
    final Face[]
     
    final org.joml.Vector2f[]
     
    protected final void
    Requires the relativeCentroid to be set.
    protected final void
    Calculates a relative centroid and the boundingSphere for the shape.
    final org.joml.Vector2f
     
    final boolean
    rotateShape(float radianAngle, RotationType type, org.joml.Vector2f point)
    Rotate a shape around a specific point and a given radianAngle.
    final void
    setPosition(float x, float y)
     
    final void
    setPosition(org.joml.Vector2f position)
    Update the shapes position due to external changes, e.g.
    org.joml.Vector2f
    supportPoint(org.joml.Vector2f v)
    According to GJKSM this method is supposed to calculate the point of the shape, that is most in direction of v.
    final ShapeType
    A clean description for this shape.
    final int
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • relatives

      protected final org.joml.Vector2f[] relatives
      The coordinates of the shape - relative to an imaginary origin near the shape
    • absolutes

      protected final org.joml.Vector2f[] absolutes
      The coordinates of the shape - absolute coordinates (position is already added to it)
      See Also:
    • faces

      protected final Face[] faces
      All faces of the shape
      See Also:
    • vertices

      protected final int vertices
      The amount of vertices of the shape
      See Also:
    • relativeCentroid

      protected org.joml.Vector2f relativeCentroid
      The centroid of the shape - the relative vector to an imaginary origin near the shape
    • absoluteCentroid

      protected org.joml.Vector2f absoluteCentroid
      The centroid of the shape - the absolute vector (position is already added to it)
      See Also:
    • boundingSphere

      protected Circle boundingSphere
      The boundingSphere of this shape represented by a Circle. This sphere is used as broadphase for collision detection, since circle intersection checks does cost way less
      See Also:
  • Constructor Details

    • PrimitiveShape

      protected PrimitiveShape(org.joml.Vector2f... relatives)
      Create a polygon of the given coordinates.
      Parameters:
      relatives - all relative points on the shape
    • PrimitiveShape

      protected PrimitiveShape(ShapeType type, org.joml.Vector2f... relatives)
      Create a shape. Generally only used as super call from other shape classes.
      Parameters:
      type - the type of the target shape
      relatives - the points defining this shape
  • Method Details

    • setPosition

      public final void setPosition(org.joml.Vector2f position)
      Update the shapes position due to external changes, e.g. the related object has moved
      Parameters:
      position - the new position of the related object
    • setPosition

      public final void setPosition(float x, float y)
      Parameters:
      x - the x coord
      y - the y coord
      See Also:
    • position

      public final org.joml.Vector2f position()
    • getAbsolutePoints

      public final org.joml.Vector2f[] getAbsolutePoints()
    • faces

      public final Face[] faces()
    • vertices

      public final int vertices()
    • initSphere

      protected final void initSphere()
      Calculates a relative centroid and the boundingSphere for the shape. In some special cases this might be done quicker in a different way.
    • init

      protected final void init()
      Requires the relativeCentroid to be set. Calculates all relative faces and relative diagonals for a defined shape
    • adjust

      public void adjust()
      Will be called by setPosition(Vector2f) after the new position was set. Used to recalculate the absolute coordinates.
    • rotateShape

      public final boolean rotateShape(float radianAngle, RotationType type, org.joml.Vector2f point)
      Rotate a shape around a specific point and a given radianAngle.
      Parameters:
      radianAngle - the radian angle to rotate the shape
      type - the type of rotation
      point - the optional point to rotate around; if type is not RotationType.AROUND_POINT, the point can be null
      Returns:
      true, if the rotation was successful
      See Also:
    • centroid

      public final org.joml.Vector2f centroid()
      The center point or weight point of the shape.
      Returns:
      centroid of the shape
      See Also:
    • boundingSphere

      public final Circle boundingSphere()
      A minimal sphere that contains the original shape. The inner shape is supposed to be fixed inside the sphere and share the same centroid.
      Returns:
      the minimal sphere containing this shape
    • supportPoint

      public org.joml.Vector2f supportPoint(org.joml.Vector2f v)
      According to GJKSM this method is supposed to calculate the point of the shape, that is most in direction of v. The general rule is, the more primitive the shape is, the more efficient this method can be. This method may be described as max{v*x,x element of Shape} for any complex shape.
      Parameters:
      v - the direction
      Returns:
      the point of the shape that is most in the direction of v
    • type

      public final ShapeType type()
      A clean description for this shape.
      Returns:
      the ShapeType matching this PrimitiveShape