Class CollisionMath

java.lang.Object
com.hypixel.hytale.server.core.modules.collision.CollisionMath

public class CollisionMath extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Result code for intersection of two boxes neither touching nor overlapping
    static final ThreadLocal<org.joml.Vector2d>
     
    static final int
    Combination of all box intersection result OVERLAP_ flags
    static final int
    Mask of all box intersection result OVERLAP_ flags
    static final int
    Result flag for intersection of two boxes overlapping in x direction
    static final int
    Result flag for intersection of two boxes overlapping in y direction
    static final int
    Result flag for intersection of two boxes overlapping in z direction
    static final int
    Mask/combination of all box intersection result TOUCH_ flags
    static final int
    Result flag for intersection of two boxes touching in x direction
    static final int
    Result flag for intersection of two boxes touching in y direction
    static final int
    Result flag for intersection of two boxes touching in z direction
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    intersect1D(double p, double pMin, double pMax, double q, double qMin, double qMax)
    1D helper class for Rect/AABB intersection computation.
    static int
    intersect1D(double p, double pMin, double pMax, double q, double qMin, double qMax, double thickness)
    1D helper class for Rect/AABB intersection computation with thickness parameters.
    static boolean
    intersect1D(double p, double s, double min, double max, org.joml.Vector2d minMax)
    Helper routine for AABB ray cast.
    static int
    intersectAABBs(double px, double py, double pz, Box bbP, double qx, double qy, double qz, Box bbQ)
    Test if two AABBs intersect or touch
    static int
    intersectAABBs(double px, double py, double pz, Box bbP, double qx, double qy, double qz, Box bbQ, double thickness)
    Test if two AABBs intersect or touch with thickness parameter.
    static int
    intersectAABBs(org.joml.Vector3d p, Box bbP, org.joml.Vector3d q, Box bbQ)
    Test if two AABBs intersect or touch
    static boolean
    intersectRayAABB(org.joml.Vector3d pos, org.joml.Vector3d ray, double x, double y, double z, double radius, double height, org.joml.Vector2d minMax)
    Find intersection between (infinite) ray starting at pos with given length and AABB
    static double
    intersectRayAABB(org.joml.Vector3d pos, org.joml.Vector3d ray, double x, double y, double z, Box box)
    Find intersection between (infinite) ray starting at pos with given length and AABB
    static boolean
    intersectRayAABB(org.joml.Vector3d pos, org.joml.Vector3d ray, double x, double y, double z, Box box, org.joml.Vector2d minMax)
    Find intersection between (infinite) ray starting at pos with given length and AABB
    static boolean
    intersectSweptAABBs(org.joml.Vector3d posP, org.joml.Vector3d vP, Box p, double qx, double qy, double qz, Box q, org.joml.Vector2d minMax, Box temp)
    Find collision between an AABB swept along a ray with another AABB
    static boolean
    intersectSweptAABBs(org.joml.Vector3d posP, org.joml.Vector3d vP, Box p, org.joml.Vector3d posQ, Box q, org.joml.Vector2d minMax, Box temp)
    Find collision between an AABB swept along a ray with another AABB
    static boolean
    intersectVectorAABB(org.joml.Vector3d pos, org.joml.Vector3d vec, double x, double y, double z, double radius, double height, org.joml.Vector2d minMax)
    Find intersection between vector starting at pos and AABB
    static boolean
    intersectVectorAABB(org.joml.Vector3d pos, org.joml.Vector3d vec, double x, double y, double z, Box box, org.joml.Vector2d minMax)
    Find intersection between vector starting at pos and AABB
    static boolean
    isDisjoint(int code)
    Test intersection code for disjoint boxes.
    static boolean
    isOverlapping(int code)
    Test intersection code for overlapping boxes.
    static boolean
    isTouching(int code)
    Test intersection code for touching boxes.

    Methods inherited from class Object

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

    • MIN_MAX

      public static final ThreadLocal<org.joml.Vector2d> MIN_MAX
    • DISJOINT

      public static final int DISJOINT
      Result code for intersection of two boxes neither touching nor overlapping
      See Also:
    • TOUCH_X

      public static final int TOUCH_X
      Result flag for intersection of two boxes touching in x direction
      See Also:
    • TOUCH_Y

      public static final int TOUCH_Y
      Result flag for intersection of two boxes touching in y direction
      See Also:
    • TOUCH_Z

      public static final int TOUCH_Z
      Result flag for intersection of two boxes touching in z direction
      See Also:
    • TOUCH_ANY

      public static final int TOUCH_ANY
      Mask/combination of all box intersection result TOUCH_ flags
      See Also:
    • OVERLAP_X

      public static final int OVERLAP_X
      Result flag for intersection of two boxes overlapping in x direction
      See Also:
    • OVERLAP_Y

      public static final int OVERLAP_Y
      Result flag for intersection of two boxes overlapping in y direction
      See Also:
    • OVERLAP_Z

      public static final int OVERLAP_Z
      Result flag for intersection of two boxes overlapping in z direction
      See Also:
    • OVERLAP_ANY

      public static final int OVERLAP_ANY
      Mask of all box intersection result OVERLAP_ flags
      See Also:
    • OVERLAP_ALL

      public static final int OVERLAP_ALL
      Combination of all box intersection result OVERLAP_ flags
      See Also:
  • Constructor Details

    • CollisionMath

      public CollisionMath()
  • Method Details

    • intersectVectorAABB

      public static boolean intersectVectorAABB(@Nonnull org.joml.Vector3d pos, @Nonnull org.joml.Vector3d vec, double x, double y, double z, @Nonnull Box box, @Nonnull org.joml.Vector2d minMax)
      Find intersection between vector starting at pos and AABB
      Parameters:
      pos - start point of vector
      vec - direction of vector
      x - footpoint of AABB
      y - footpoint of AABB
      z - footpoint of AABB
      box - AABB
      minMax - result values for collision point
      Returns:
      true if collision. minMax.x will then hold nearest collision vector scale, minMax.y farthest collision scale.
    • intersectRayAABB

      public static boolean intersectRayAABB(@Nonnull org.joml.Vector3d pos, @Nonnull org.joml.Vector3d ray, double x, double y, double z, @Nonnull Box box, @Nonnull org.joml.Vector2d minMax)
      Find intersection between (infinite) ray starting at pos with given length and AABB
      Parameters:
      pos - start point of vector
      ray - direction with length of ray
      x - footpoint of AABB
      y - footpoint of AABB
      z - footpoint of AABB
      box - AABB
      minMax - result values for collision point
      Returns:
      true if collision. minMax.x will then hold nearest collision vector scale, minMax.y farthest collision scale.
    • intersectRayAABB

      public static double intersectRayAABB(@Nonnull org.joml.Vector3d pos, @Nonnull org.joml.Vector3d ray, double x, double y, double z, @Nonnull Box box)
      Find intersection between (infinite) ray starting at pos with given length and AABB

      Variant uses a thread local minMax value instead of passing it as argument if only the minimum value is required.

      Parameters:
      pos - start point of vector
      ray - direction with length of ray
      x - footpoint of AABB
      y - footpoint of AABB
      z - footpoint of AABB
      box - AABB
      Returns:
      Return nearest distance of ray intersection or -Double.MAX_VALUE
    • intersectVectorAABB

      public static boolean intersectVectorAABB(@Nonnull org.joml.Vector3d pos, @Nonnull org.joml.Vector3d vec, double x, double y, double z, double radius, double height, @Nonnull org.joml.Vector2d minMax)
      Find intersection between vector starting at pos and AABB
      Parameters:
      pos - start point of vector
      vec - direction of vector
      x - footpoint of AABB
      y - footpoint of AABB
      z - footpoint of AABB
      radius - radius of AABB
      height - height of AABB
      minMax - result values for collision point
      Returns:
      true if collision. minMax.x will then hold nearest collision vector scale, minMax.y farthest collision scale.
    • intersectRayAABB

      public static boolean intersectRayAABB(@Nonnull org.joml.Vector3d pos, @Nonnull org.joml.Vector3d ray, double x, double y, double z, double radius, double height, @Nonnull org.joml.Vector2d minMax)
      Find intersection between (infinite) ray starting at pos with given length and AABB
      Parameters:
      pos - start point of vector
      ray - direction with length of ray
      x - footpoint of AABB
      y - footpoint of AABB
      z - footpoint of AABB
      radius - radius of AABB
      height - height of AABB
      minMax - result values for collision point
      Returns:
      true if collision. minMax.x will then hold nearest collision vector scale, minMax.y farthest collision scale.
    • intersectSweptAABBs

      public static boolean intersectSweptAABBs(@Nonnull org.joml.Vector3d posP, @Nonnull org.joml.Vector3d vP, @Nonnull Box p, @Nonnull org.joml.Vector3d posQ, @Nonnull Box q, @Nonnull org.joml.Vector2d minMax, @Nonnull Box temp)
      Find collision between an AABB swept along a ray with another AABB
      Parameters:
      posP - initial position of swept AABB
      vP - sweep direction
      p - swept box
      posQ - position of other AABB
      q - other AABB
      minMax - result values for collision point
      temp - box used for temporary computations
      Returns:
      true if collision. minMax.x will then hold nearest collision vector scale, minMax.y farthest collision scale.
    • intersectSweptAABBs

      public static boolean intersectSweptAABBs(@Nonnull org.joml.Vector3d posP, @Nonnull org.joml.Vector3d vP, @Nonnull Box p, double qx, double qy, double qz, @Nonnull Box q, @Nonnull org.joml.Vector2d minMax, @Nonnull Box temp)
      Find collision between an AABB swept along a ray with another AABB
      Parameters:
      posP - initial position of swept AABB
      vP - sweep direction
      p - swept box
      qx - position of other AABB
      qy - position of other AABB
      qz - position of other AABB
      q - other AABB
      minMax - result values for collision point
      temp - box used for temporary computations
      Returns:
      true if collision. minMax.x will then hold nearest collision vector scale, minMax.y farthest collision scale.
    • intersect1D

      public static boolean intersect1D(double p, double s, double min, double max, @Nonnull org.joml.Vector2d minMax)
      Helper routine for AABB ray cast. Test for each dimension.

      The minMax value must be initialized with { 0, Double.MaxValue } before first test. *

      Parameters:
      p - ray position
      s - ray length
      min - min box coordinate
      max - max box coordinate
      minMax - resulting collision distance x for minimum, y for maximum
      Returns:
      true if intersection possible
    • isDisjoint

      public static boolean isDisjoint(int code)
      Test intersection code for disjoint boxes.
      Parameters:
      code - Intersection code
      Returns:
      true if boxes are disjoint, false if overlap or touching
    • isOverlapping

      public static boolean isOverlapping(int code)
      Test intersection code for overlapping boxes.
      Parameters:
      code - Intersection code
      Returns:
      true if boxes are overlapping, false if boxes are touching or disjoint
    • isTouching

      public static boolean isTouching(int code)
      Test intersection code for touching boxes.
      Parameters:
      code - Intersection code
      Returns:
      true if boxes are touching, false if boxes are overlapping or disjoint
    • intersectAABBs

      public static int intersectAABBs(@Nonnull org.joml.Vector3d p, @Nonnull Box bbP, @Nonnull org.joml.Vector3d q, @Nonnull Box bbQ)
      Test if two AABBs intersect or touch

      Intervals are assumed to touch when the distance between them is less than MOVEMENT_THRESHOLD to compensate for computational inaccuracies.

      Parameters:
      p - origin of box
      bbP - box
      q - origin of other box
      bbQ - other box
      Returns:
      Either DISJOINT or combination or TOUCH_ and OVERLAP_ bits (intersection code)
    • intersectAABBs

      public static int intersectAABBs(double px, double py, double pz, @Nonnull Box bbP, double qx, double qy, double qz, @Nonnull Box bbQ)
      Test if two AABBs intersect or touch

      Intervals are assumed to touch when the distance between them is less than MOVEMENT_THRESHOLD to compensate for computational inaccuracies.

      Parameters:
      px - origin of box
      py - origin of box
      pz - origin of box
      bbP - box
      qx - origin of other box
      qy - origin of other box
      qz - origin of other box
      bbQ - other box
      Returns:
      Either DISJOINT or combination or TOUCH_ and OVERLAP_ bits (intersection code)
    • intersect1D

      public static int intersect1D(double p, double pMin, double pMax, double q, double qMin, double qMax)
      1D helper class for Rect/AABB intersection computation.

      Intervals are assumed to touch when the distance between them is less than MOVEMENT_THRESHOLD to compensate for computational inaccuracies.

      Parameters:
      p - interval position
      pMin - interval extent
      pMax - interval extent
      q - other interval position
      qMin - other interval extent
      qMax - other interval extent
      Returns:
      OVERLAP_ANY when intervals overlap, TOUCH_ANY when intervals sit (closely) side by side, else DISJOINT
    • intersectAABBs

      public static int intersectAABBs(double px, double py, double pz, @Nonnull Box bbP, double qx, double qy, double qz, @Nonnull Box bbQ, double thickness)
      Test if two AABBs intersect or touch with thickness parameter.

      Intervals are assumed to touch when the distance between them is less than thickness to compensate for computational inaccuracies.

      Parameters:
      px - origin of box
      py - origin of box
      pz - origin of box
      bbP - box
      qx - origin of other box
      qy - origin of other box
      qz - origin of other box
      bbQ - other box
      thickness - overlap distance which is still considered as touching
      Returns:
      Either DISJOINT or combination or TOUCH_ and OVERLAP_ bits (intersection code)
    • intersect1D

      public static int intersect1D(double p, double pMin, double pMax, double q, double qMin, double qMax, double thickness)
      1D helper class for Rect/AABB intersection computation with thickness parameters.

      Intervals are assumed to touch when the distance between them is less than thickness to compensate for computational inaccuracies.

      Parameters:
      p - interval position
      pMin - interval extent
      pMax - interval extent
      q - other interval position
      qMin - other interval extent
      qMax - other interval extent
      thickness - overlap distance which is still considered as touching
      Returns:
      OVERLAP_ANY when intervals overlap, TOUCH_ANY when intervals sit (closely) side by side, else DISJOINT