Package ecs

Class PolygonCollider

java.lang.Object
ecs.Component
ecs.PolygonCollider
All Implemented Interfaces:
Comparable<Component>, Collider

public class PolygonCollider extends Component implements Collider
A polygon collider for a GameObject. Collision detection uses GJK in MathUtils.gjksmCollision(PrimitiveShape, PrimitiveShape). Must not be mixed with other colliders.
Since:
06.12.2021
Author:
Juyas
  • Constructor Details

    • PolygonCollider

      public PolygonCollider(PrimitiveShape shape, boolean passive)
    • PolygonCollider

      public PolygonCollider(PrimitiveShape shape)
  • Method Details

    • layer

      public PolygonCollider layer(int... layers)
      Sets multiple layers at once for handy usage.
      Parameters:
      layers - all layers that should be set.
      Returns:
      the collider itself, to chain the call.
    • mask

      public PolygonCollider mask(int... masks)
      Sets multiple masks at once for handy usage.
      Parameters:
      masks - all layers that should be set.
      Returns:
      the collider itself, to chain the call.
    • setShape

      public void setShape(PrimitiveShape shape)
      Overwrite the shape of the collider. Use with caution.
      Parameters:
      shape - the new shape.
    • start

      public void start()
      Description copied from class: Component
      Called once on Component initialization.
      Overrides:
      start in class Component
    • getShape

      public PrimitiveShape getShape()
      Description copied from interface: Collider
      The shape of the collider.
      Specified by:
      getShape in interface Collider
      Returns:
      the shape of the collider
    • detectCollision

      public CollisionInformation detectCollision(Collider collider)
      Description copied from interface: Collider
      Determines whether a collider intersects with another collider IGNORING the collision layers.
      Specified by:
      detectCollision in interface Collider
      Parameters:
      collider - the other collider
      Returns:
      an object containing the result of collision detection
    • canCollideWith

      public boolean canCollideWith(Collider other)
      Description copied from interface: Collider
      Determines whether a collider could potentially intersect with another collider ONLY by their collision layers. This method can be considered part of the broad phase of collision detection.
      Specified by:
      canCollideWith in interface Collider
      Parameters:
      other - the other collider
      Returns:
      true if and only if both objects could potentially collide
    • layers

      public short layers()
      Description copied from interface: Collider
      A short containing all enabled layers encoded as bit mask. Should be usable to compare different masks with each other to check for intersection.
      Specified by:
      layers in interface Collider
      Returns:
      a short with all layer encoded
    • mask

      public short mask()
      Description copied from interface: Collider
      A short containing all enabled masks encoded as bit mask. Should be usable to compare different masks with each other to check for intersection.
      Specified by:
      mask in interface Collider
      Returns:
      a short with all masks encoded
    • hasMask

      public boolean hasMask(int layer)
      Description copied from interface: Collider
      Determines whether a collision mask for a specified layer is enabled.
      Specified by:
      hasMask in interface Collider
      Parameters:
      layer - the layer from 0 to TOTAL_LAYER-1, the behaviour for layers outside the range is undefined
      Returns:
      true if and only if the mask for the specified layer is enabled
    • isOnLayer

      public boolean isOnLayer(int layer)
      Description copied from interface: Collider
      Determines whether the collider exists in a specified layer.
      Specified by:
      isOnLayer in interface Collider
      Parameters:
      layer - the layer from 0 to TOTAL_LAYER-1, the behaviour for layers outside the range is undefined
      Returns:
      true if and only if the collider exists in the specified layer
    • setLayer

      public void setLayer(int layer, boolean active)
      Description copied from interface: Collider
      Change the colliders presence in a specified layer. Making a collider present in a specified layer will it enable to collide with all collider including the specified layer in their collision mask.
      Specified by:
      setLayer in interface Collider
      Parameters:
      layer - the layer from 0 to TOTAL_LAYER-1, the behaviour for layers outside the range is undefined
      active - whether the collider should be present (true) or not (false)
    • setMask

      public void setMask(int layer, boolean active)
      Description copied from interface: Collider
      Changes the collision mask entry for a specified layer. Enabling the mask for layer n will allow this collider to collide with any other collider set in the target layer n vise versa.
      Specified by:
      setMask in interface Collider
      Parameters:
      layer - the layer from 0 to TOTAL_LAYER-1, the behaviour for layers outside the range is undefined
      active - whether the mask should enabled (true) or disabled (false)
    • passive

      public boolean passive()
      Description copied from interface: Collider
      Defines the behaviour of this collider. A passive collider will never get checked against others colliders, however any collider might get checked against it.
      Specified by:
      passive in interface Collider
      Returns:
      whether this collider is passive
    • update

      public void update(float dt)
      Description copied from class: Component
      Called once per frame for each Component
      Overrides:
      update in class Component
      Parameters:
      dt - Engine.deltaTime