Class NPCPhysicsMath

java.lang.Object
com.hypixel.hytale.server.npc.util.NPCPhysicsMath

public class NPCPhysicsMath extends Object
Math helper for world calculations or alternative implementations of existing functions requiring no memory allocations.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
     
    static final double
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    accelerate(double v, double a, double t, double limitSpeed)
     
    static double
    accelerateDrag(double v, double a, double t, double terminalVelocity)
     
    static double
    accelerateDrag(double v, double a, double t, double terminalVelocity, double p)
     
    static double
    accelerateDragCapped(double v, double a, double t, double terminalVelocity)
     
    static double
    accelerateDragCapped(double v, double a, double t, double terminalVelocity, double p)
     
    static double
    accelerateToTargetSpeed(double vCurrent, double vTarget, double dt, double accel, double vMax)
     
    static double
    accelerateToTargetSpeed(double vCurrent, double vTarget, double dt, double accel, double decel, double vMax)
     
    static double
    accelerateToTargetSpeed(double vCurrent, double vTarget, double dt, double accel, double decel, double vMin, double vMax)
     
    static org.joml.Vector3d
    addDifference(org.joml.Vector3d result, org.joml.Vector3d p, org.joml.Vector3d q)
     
    static double
    blockBottom(BlockType blockType, int rotation)
    Compute bottom hitbox height of block.
    static double
    blockEmptySpace(BlockType blockType, int rotation, NPCPhysicsMath.Direction direction)
    Return space along a block type when approaching from a direction along coordinate axis.
    static double
    blockHeight(BlockType blockType, int rotation)
    Compute top hitbox height of block.
    static float
    clampRotation(float rotation, float maxAngle)
    Clamp a rotation angle to interval [-maxAngle, +maxAngle]
    static double
    collisionSphereRadius(double boxWidth, double boxDepth, double boxHeight)
     
    static double
     
    static double
     
    static double
    cosAngleBetweenUnitVectors(org.joml.Vector3d v, org.joml.Vector3d w)
     
    static double
    cosAngleBetweenVectors(org.joml.Vector3d v, double vLen, org.joml.Vector3d w, double wLen)
     
    static double
    cosAngleBetweenVectors(org.joml.Vector3d v, org.joml.Vector3d w)
     
    static org.joml.Vector3d
    createOrthogonalvector(org.joml.Vector3d in, org.joml.Vector3d out)
     
    static double
    deccelerateToStop(double v, double a, double t)
     
    static org.joml.Vector3d
    deccelerateToStop(org.joml.Vector3d v, double a, double t)
     
    static double
    distanceSquaredWithSelector(org.joml.Vector3d p, org.joml.Vector3d q, org.joml.Vector3d componentSelector)
    Compute squared distance between two points with component selector
    static double
    distanceWithSelector(org.joml.Vector3d p, org.joml.Vector3d q, org.joml.Vector3d componentSelector)
    Compute distance between two points with component selector
    static double
    dotProduct(double dx, double dy, double dz)
     
    static double
    dotProduct(double px, double py, double pz, double qx, double qy, double qz)
     
    static double
    dotProduct(double px, double py, double pz, double qx, double qy, double qz, org.joml.Vector3d componentSelector)
    Compute dot product of two vectors component selector
    static double
    dotProduct(double x, double y, double z, org.joml.Vector3d componentSelector)
    Compute dot product of vector with itself with component selector
    static double
    dotProduct(float dx, float dy, float dz)
     
    static double
    dotProduct(float px, float py, float pz, float qx, float qy, float qz)
     
    static double
    dotProduct(org.joml.Vector3d base, org.joml.Vector3d p, org.joml.Vector3d q)
    Compute dot product between a ray and a point.
    static double
    dotProduct(org.joml.Vector3d base, org.joml.Vector3d p, org.joml.Vector3d q, org.joml.Vector3d componentSelector)
    Compute dot product between a ray and a point using component selector.
    static double
    dotProductWithSelector(org.joml.Vector3d p, org.joml.Vector3d q, org.joml.Vector3d componentSelector)
    Compute dot product of two vectors with component selector
    static double
    getBoundingBoxCenterToCornerDistance(Box box, org.joml.Vector3dc componentSelector)
     
    static double
    getMaxBoundingBoxExtent(Box box, org.joml.Vector3dc componentSelector)
     
    static double
    getMinBoundingBoxDistance(Box box, Box box2, org.joml.Vector3dc componentSelector)
     
    static double
    getMinBoundingBoxExtent(Box box, org.joml.Vector3dc componentSelector)
     
    static double
    getProjectedDifference(org.joml.Vector3d p, org.joml.Vector3d q, org.joml.Vector3d componentSelector)
     
    static org.joml.Vector3d
    getViewDirection(Rotation3f rotation, org.joml.Vector3d outDirection)
    Compute view direction (not necessarily normalized) of an entity.
    static double
    gravityDrag(double v, double a, double t, double terminalVelocity)
     
    static double
    gravityDrag(double v, double a, double t, double terminalVelocity, double p)
     
    static float
    headingFromDirection(double x, double z, float def)
    Get heading from x/z directional vector using game coordinate system.
    static double
    heightOverGround(World world, double x, double z)
    Compute height considering block height at position.
    static double
    heightOverGround(World world, double x, double y, double z)
    Compute height over ground for a given position.
    static double
    heightOverGround(World world, double x, double y, double z, int maxSearchHeight)
    Compute height over ground by searching upward for an empty block.
    static int
    intersectLineSphere(org.joml.Vector3d center, double radius, org.joml.Vector3d p, org.joml.Vector3d q, org.joml.Vector3d x1, org.joml.Vector3d x2, boolean segmentOnly)
    Intersect a sphere with a line between two points and return collision points.
    static double
    intersectLineSphereLerp(org.joml.Vector3d center, double radius, org.joml.Vector3d p, org.joml.Vector3d q, org.joml.Vector3d componentSelector)
    Intersect a sphere with a line between and return collision lerp factor.
    static double
    intersectLineSphereLerp(org.joml.Vector3d center, double radius, org.joml.Vector3d p, org.joml.Vector3d q, org.joml.Vector3d t1, org.joml.Vector3d t2, org.joml.Vector3d componentSelector)
    Intersect a sphere with a line between and return collision lerp factor.
    static int
    intersectSweptSpheres(double p1x, double p1y, double p1z, double velocity1x, double velocity1y, double velocity1z, double p2x, double p2y, double p2z, double velocity2x, double velocity2y, double velocity2z, double radius, org.joml.Vector3dc componentSelector, double[] results)
     
    static int
    intersectSweptSpheres(org.joml.Vector3d p1, org.joml.Vector3d velocity1, org.joml.Vector3d p2, org.joml.Vector3d velocity2, double radius, org.joml.Vector3d componentSelector, double[] results)
    Compute collision between two swept spheres with given position and speed.
    static int
    intersectSweptSpheresFootpoint(org.joml.Vector3d p1, org.joml.Vector3d velocity1, double radius1, org.joml.Vector3d p2, org.joml.Vector3d velocity2, double radius2, org.joml.Vector3dc componentSelector, double[] results)
     
    static boolean
    inViewSector(double xViewer, double zViewer, float heading, float coneAngle, double xObject, double zObject)
    2D view sector test.
    static boolean
    isInvalid(double v)
     
    static boolean
    isInvalid(org.joml.Vector3d v)
     
    static boolean
    isInViewCone(double xViewer, double yViewer, double zViewer, double xViewDirection, double yViewDirection, double zViewDirection, float cosConeHalfAngle, double xObject, double yObject, double zObject)
    Test if object is within view cone of viewer.
    static boolean
    isInViewCone(double xViewDirection, double yViewDirection, double zViewDirection, float cosConeHalfAngle, double xObject, double yObject, double zObject)
    Test if object is within view cone of viewer with relative object position.
    static boolean
    isInViewCone(org.joml.Vector3d viewer, org.joml.Vector3d viewDirection, float cosConeHalfAngle, org.joml.Vector3d object)
    Test if object is within view cone of viewer.
    static boolean
    isInViewCone(org.joml.Vector3d viewer, org.joml.Vector3d viewDirection, float cosConeHalfAngle, org.joml.Vector3d object, org.joml.Vector3d componentSelector)
    Test if object is within view cone of viewer.
    static boolean
    isValid(double v)
     
    static boolean
    isValid(org.joml.Vector3d v)
     
    static double
    jumpParameters(org.joml.Vector3d position, org.joml.Vector3d targetPosition, double gravity, org.joml.Vector3d velocity)
     
    static double
    lerp(double a, double b, double s)
    Linear interpolate between two doubles.
    static void
    lerp(org.joml.Vector3d start, org.joml.Vector3d end, double lambda, org.joml.Vector3d result)
    Point on ray between two point with lerp factor.
    static void
    lerpDistance(org.joml.Vector3d start, org.joml.Vector3d end, double distance, org.joml.Vector3d result)
    Point on ray between two point with given distance from start point.
    static float
    lookatHeading(org.joml.Vector3d self, org.joml.Vector3d pointOfInterest, float headingHint)
    Compute heading required to look to a point of interest.
    static org.joml.Vector3d
    multiply(org.joml.Vector3d v, org.joml.Vector3d w)
     
    static boolean
    near(double v, double w)
     
    static boolean
    near(double v, double w, double epsilonLength)
     
    static boolean
    near(org.joml.Vector3dc v, org.joml.Vector3dc w)
     
    static boolean
    near(org.joml.Vector3dc v, org.joml.Vector3dc w, double epsilonLength)
     
    static void
    offsetVector(double sx, double sy, double sz, double dx, double dy, double dz, double lambda, org.joml.Vector3d result)
    Compute a+tb for a vector without doing allocations.
    static void
    offsetVector(org.joml.Vector3d start, double dx, double dy, double dz, double lambda, org.joml.Vector3d result)
    Compute a+tb for a vector without doing allocations.
    static void
    orthoComposition(org.joml.Vector3dc start, org.joml.Vector3dc end, double distanceStart, org.joml.Vector3dc ortho, double distance, org.joml.Vector3d result)
    Calculate vector as sum of a linear component and a vector orthogonal to the linear component and a second base vector.
    static void
    orthoComposition(org.joml.Vector3d start, org.joml.Vector3d end, org.joml.Vector3d ortho, double distance, org.joml.Vector3d result)
     
    static float
    pitchFromDirection(double x, double y, double z, float def)
    Return pitch from x/y/z direction vector using game coordinate system.
    static double
    projectedLength(org.joml.Vector3d v, org.joml.Vector3d componentSelector)
     
    static double
    projectedLengthSquared(org.joml.Vector3d v, org.joml.Vector3d componentSelector)
     
    static org.joml.Vector3d
    projection(org.joml.Vector3d v, org.joml.Vector3d p, org.joml.Vector3d result)
     
    static org.joml.Vector3d
    projection(org.joml.Vector3d base, org.joml.Vector3d v, org.joml.Vector3d p, org.joml.Vector3d result)
     
    static double
    rayCircleIntersect(double sx, double sy, double dx, double dy, double radius)
     
    static double
    rayCircleIntersect(org.joml.Vector3dc start, org.joml.Vector3dc end, org.joml.Vector3dc center, double radius, org.joml.Vector3dc normal)
     
    static void
    realignUnitVector(org.joml.Vector3d v, org.joml.Vector3d w, double cosine, org.joml.Vector3d result)
     
    static void
    realignVector(org.joml.Vector3d v, double vLen, org.joml.Vector3d w, double wLen, double cosine, org.joml.Vector3d result)
     
    static void
    realignVector(org.joml.Vector3d v, org.joml.Vector3d w, double cosine, org.joml.Vector3d result)
     
    static boolean
    realignVectorReturnDirection(org.joml.Vector3d v, double vLen, org.joml.Vector3d w, double wLen, double cosine, org.joml.Vector3d result)
     
    static org.joml.Vector3d
    rejection(org.joml.Vector3d v, org.joml.Vector3d p, org.joml.Vector3d result)
     
    static org.joml.Vector3d
    rejection(org.joml.Vector3d base, org.joml.Vector3d v, org.joml.Vector3d p, org.joml.Vector3d result)
     
    static void
    rotationFromDirection(double x, double y, double z, Rotation3fc inRotation, Rotation3f outRotation)
    Return rotation with pitch and yaw computed from direction.
    static void
    rotationFromDirection(org.joml.Vector3dc direction, Rotation3fc inRotation, Rotation3f outRotation)
     
    static void
    rotationFromDirection(org.joml.Vector3dc from, org.joml.Vector3dc to, Rotation3fc inRotation, Rotation3f outRotation)
     
    static double
    squaredDistProjected(double px, double py, double pz, double qx, double qy, double qz, org.joml.Vector3dc normal)
     
    static double
    squaredDistProjected(double px, double py, double pz, org.joml.Vector3d q, org.joml.Vector3dc normal)
     
    static org.joml.Vector3d
    subtractVector(org.joml.Vector3d p, org.joml.Vector3d q, org.joml.Vector3d result)
     
    static float
    turnAngle(float from, float to)
    Return smallest angle to rotate from angle to another angle

    Methods inherited from class Object

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

  • Method Details

    • near

      public static boolean near(@Nonnull org.joml.Vector3dc v, @Nonnull org.joml.Vector3dc w)
    • near

      public static boolean near(@Nonnull org.joml.Vector3dc v, @Nonnull org.joml.Vector3dc w, double epsilonLength)
    • near

      public static boolean near(double v, double w)
    • near

      public static boolean near(double v, double w, double epsilonLength)
    • headingFromDirection

      public static float headingFromDirection(double x, double z, float def)
      Get heading from x/z directional vector using game coordinate system.
      Parameters:
      x - x component of direction
      z - z component of direction
      def - return value when heading not defined for input values
      Returns:
      heading in radians or def if x and z are 0
    • pitchFromDirection

      public static float pitchFromDirection(double x, double y, double z, float def)
      Return pitch from x/y/z direction vector using game coordinate system.
      Parameters:
      x - x component of direction
      y - y component of direction
      z - z component of direction
      def - return value when heading not defined for input values
      Returns:
      pitch in radians or def if x and z are 0
    • rotationFromDirection

      public static void rotationFromDirection(double x, double y, double z, @Nonnull Rotation3fc inRotation, @Nonnull Rotation3f outRotation)
      Return rotation with pitch and yaw computed from direction. Uses default rotation values from another rotation in degenerate cases.
      Parameters:
      x - Direction x component.
      y - Direction y component.
      z - Direction z component.
      inRotation - Rotation to use for default values when direction is too short to compute valid rotation.
      outRotation - Rotation to assign result to.
    • rotationFromDirection

      public static void rotationFromDirection(@Nonnull org.joml.Vector3dc direction, @Nonnull Rotation3fc inRotation, @Nonnull Rotation3f outRotation)
    • rotationFromDirection

      public static void rotationFromDirection(@Nonnull org.joml.Vector3dc from, @Nonnull org.joml.Vector3dc to, @Nonnull Rotation3fc inRotation, @Nonnull Rotation3f outRotation)
    • getViewDirection

      @Nonnull public static org.joml.Vector3d getViewDirection(@Nonnull Rotation3f rotation, @Nonnull org.joml.Vector3d outDirection)
      Compute view direction (not necessarily normalized) of an entity.
      Parameters:
      rotation - the rotation
      outDirection - vector to be assigned with direction
      Returns:
      outDirection vector
    • cosAngleBetweenVectors

      public static double cosAngleBetweenVectors(@Nonnull org.joml.Vector3d v, @Nonnull org.joml.Vector3d w)
    • cosAngleBetweenVectors

      public static double cosAngleBetweenVectors(@Nonnull org.joml.Vector3d v, double vLen, @Nonnull org.joml.Vector3d w, double wLen)
    • cosAngleBetweenUnitVectors

      public static double cosAngleBetweenUnitVectors(@Nonnull org.joml.Vector3d v, @Nonnull org.joml.Vector3d w)
    • realignVector

      public static void realignVector(@Nonnull org.joml.Vector3d v, @Nonnull org.joml.Vector3d w, double cosine, @Nonnull org.joml.Vector3d result)
    • realignVector

      public static void realignVector(@Nonnull org.joml.Vector3d v, double vLen, @Nonnull org.joml.Vector3d w, double wLen, double cosine, @Nonnull org.joml.Vector3d result)
    • realignUnitVector

      public static void realignUnitVector(@Nonnull org.joml.Vector3d v, @Nonnull org.joml.Vector3d w, double cosine, @Nonnull org.joml.Vector3d result)
    • realignVectorReturnDirection

      public static boolean realignVectorReturnDirection(@Nonnull org.joml.Vector3d v, double vLen, @Nonnull org.joml.Vector3d w, double wLen, double cosine, @Nonnull org.joml.Vector3d result)
    • createOrthogonalvector

      @Nonnull public static org.joml.Vector3d createOrthogonalvector(@Nonnull org.joml.Vector3d in, @Nonnull org.joml.Vector3d out)
    • inViewSector

      public static boolean inViewSector(double xViewer, double zViewer, float heading, float coneAngle, double xObject, double zObject)
      2D view sector test.
      Parameters:
      xViewer - position of view sector tip
      zViewer - position of view sector tip
      heading - direction of view cone
      coneAngle - view cone full angle
      xObject - position of target
      zObject - position of target
      Returns:
      true if target within sector [heading-coneAngle/2, heading+coneAngle/2]
    • isInViewCone

      public static boolean isInViewCone(double xViewer, double yViewer, double zViewer, double xViewDirection, double yViewDirection, double zViewDirection, float cosConeHalfAngle, double xObject, double yObject, double zObject)
      Test if object is within view cone of viewer.
      Parameters:
      xViewer - coordinate viewer
      yViewer - coordinate viewer
      zViewer - coordinate viewer
      xViewDirection - view direction viewer (normalized)
      yViewDirection - view direction viewer (normalized)
      zViewDirection - view direction viewer (normalized)
      cosConeHalfAngle - cosine of half angle of view cone [cos(viewAngle/2)]
      xObject - coordinate object
      yObject - coordinate object
      zObject - coordinate object
      Returns:
      true if object is inside view cone
    • isInViewCone

      public static boolean isInViewCone(double xViewDirection, double yViewDirection, double zViewDirection, float cosConeHalfAngle, double xObject, double yObject, double zObject)
      Test if object is within view cone of viewer with relative object position.
      Parameters:
      xViewDirection - view direction viewer (normalized)
      yViewDirection - view direction viewer (normalized)
      zViewDirection - view direction viewer (normalized)
      cosConeHalfAngle - cosine of half angle of view cone [cos(viewAngle/2)]
      xObject - relative coordinate object
      yObject - relative coordinate object
      zObject - relative coordinate object
      Returns:
      true if object is inside view cone
    • isInViewCone

      public static boolean isInViewCone(@Nonnull org.joml.Vector3d viewer, @Nonnull org.joml.Vector3d viewDirection, float cosConeHalfAngle, @Nonnull org.joml.Vector3d object)
      Test if object is within view cone of viewer.
      Parameters:
      viewer - position of viewer
      viewDirection - view direction (normalized)
      cosConeHalfAngle - cosine of half angle of view cone [cos(viewAngle/2)]
      object - position of object
      Returns:
      true if object is inside view cone
    • isInViewCone

      public static boolean isInViewCone(@Nonnull org.joml.Vector3d viewer, @Nonnull org.joml.Vector3d viewDirection, float cosConeHalfAngle, @Nonnull org.joml.Vector3d object, @Nonnull org.joml.Vector3d componentSelector)
      Test if object is within view cone of viewer.
      Parameters:
      viewer - position of viewer
      viewDirection - view direction (normalized)
      cosConeHalfAngle - cosine of half angle of view cone [cos(viewAngle/2)]
      object - position of object
      componentSelector - component selector for projection coordinates
      Returns:
      true if object is inside view cone
    • turnAngle

      public static float turnAngle(float from, float to)
      Return smallest angle to rotate from angle to another angle
      Parameters:
      from - start angle in radian
      to - end angle in radian
      Returns:
      difference angle (can be positive or negative)
    • clampRotation

      public static float clampRotation(float rotation, float maxAngle)
      Clamp a rotation angle to interval [-maxAngle, +maxAngle]
      Parameters:
      rotation - Angle to clamp
      maxAngle - Max amount of rotation angle
      Returns:
      clamped angle
    • intersectLineSphere

      public static int intersectLineSphere(@Nonnull org.joml.Vector3d center, double radius, @Nonnull org.joml.Vector3d p, @Nonnull org.joml.Vector3d q, @Nonnull org.joml.Vector3d x1, @Nonnull org.joml.Vector3d x2, boolean segmentOnly)
      Intersect a sphere with a line between two points and return collision points.
      Parameters:
      center - Center of sphere
      radius - Radius of sphere
      p - Start position of line
      q - End position of line
      x1 - Result first point when 1 or 2 solutions (also used as temp value)
      x2 - Result second point when 2 solutions (also used as temp value)
      segmentOnly - Only return intersection points between p and q
      Returns:
      Number of intersections: 0, 1, or 2
    • intersectLineSphereLerp

      public static double intersectLineSphereLerp(@Nonnull org.joml.Vector3d center, double radius, @Nonnull org.joml.Vector3d p, @Nonnull org.joml.Vector3d q, @Nonnull org.joml.Vector3d t1, @Nonnull org.joml.Vector3d t2, @Nonnull org.joml.Vector3d componentSelector)
      Intersect a sphere with a line between and return collision lerp factor.
      Parameters:
      center - Center of sphere
      radius - Radius of sphere
      p - Start position of line
      q - End position of line
      t1 - Temp value
      t2 - Temp value
      componentSelector - Component mask for projected coordinates
      Returns:
      Returns d, so that p + d * q is intersetion point or 1 if no intersection happens
    • intersectLineSphereLerp

      public static double intersectLineSphereLerp(@Nonnull org.joml.Vector3d center, double radius, @Nonnull org.joml.Vector3d p, @Nonnull org.joml.Vector3d q, @Nonnull org.joml.Vector3d componentSelector)
      Intersect a sphere with a line between and return collision lerp factor.

      Allocates temp values.

      Parameters:
      center - Center of sphere
      radius - Radius of sphere
      p - Start position of line
      q - End position of line
      componentSelector - Component mask for projected coordinates
      Returns:
      Returns d, so that p + d * q is intersetion point or 1 if no intersection happens
    • dotProduct

      public static double dotProduct(@Nonnull org.joml.Vector3d base, @Nonnull org.joml.Vector3d p, @Nonnull org.joml.Vector3d q)
      Compute dot product between a ray and a point.
      Parameters:
      base - Start of vector
      p - Point on vector specifying direction
      q - Point in space
      Returns:
      Scalar product
    • dotProduct

      public static double dotProduct(@Nonnull org.joml.Vector3d base, @Nonnull org.joml.Vector3d p, @Nonnull org.joml.Vector3d q, @Nonnull org.joml.Vector3d componentSelector)
      Compute dot product between a ray and a point using component selector.
      Parameters:
      base - Start of vector
      p - Point on vector specifying direction
      q - Point in space
      componentSelector - Selector for components when using projections
      Returns:
      Scalar product
    • dotProduct

      public static double dotProduct(double dx, double dy, double dz)
    • dotProduct

      public static double dotProduct(double px, double py, double pz, double qx, double qy, double qz)
    • dotProduct

      public static double dotProduct(float dx, float dy, float dz)
    • dotProduct

      public static double dotProduct(float px, float py, float pz, float qx, float qy, float qz)
    • lerpDistance

      public static void lerpDistance(@Nonnull org.joml.Vector3d start, @Nonnull org.joml.Vector3d end, double distance, @Nonnull org.joml.Vector3d result)
      Point on ray between two point with given distance from start point.
      Parameters:
      start - Start of ray
      end - Other point on ray specifying direction
      distance - Distance from start point
      result - Resulting point on ray with given distance from start
    • lerp

      public static void lerp(@Nonnull org.joml.Vector3d start, @Nonnull org.joml.Vector3d end, double lambda, @Nonnull org.joml.Vector3d result)
      Point on ray between two point with lerp factor.
      Parameters:
      start - Start of ray
      end - Other point on ray specifying direction
      lambda - Distance factor where 0 is start point and 1 second point specified
      result - Resulting point on ray
    • lerp

      public static double lerp(double a, double b, double s)
      Linear interpolate between two doubles.
      Parameters:
      a - value when s equals 0
      b - value when s equals 1
      s - interpolation factor
      Returns:
      interpolated value
    • offsetVector

      public static void offsetVector(@Nonnull org.joml.Vector3d start, double dx, double dy, double dz, double lambda, @Nonnull org.joml.Vector3d result)
      Compute a+tb for a vector without doing allocations.
      Parameters:
      start - Origin
      dx - Direction x
      dy - Direction y
      dz - Direction z
      lambda - Scale factor
      result - origin+lambda * d
    • offsetVector

      public static void offsetVector(double sx, double sy, double sz, double dx, double dy, double dz, double lambda, @Nonnull org.joml.Vector3d result)
      Compute a+tb for a vector without doing allocations.
      Parameters:
      sx - Origin x
      sy - Origin y
      sz - Origin z
      dx - Direction x
      dy - Direction y
      dz - Direction z
      lambda - Scale factor
      result - origin+lambda * d
    • orthoComposition

      public static void orthoComposition(@Nonnull org.joml.Vector3d start, @Nonnull org.joml.Vector3d end, @Nonnull org.joml.Vector3d ortho, double distance, @Nonnull org.joml.Vector3d result)
    • orthoComposition

      public static void orthoComposition(@Nonnull org.joml.Vector3dc start, @Nonnull org.joml.Vector3dc end, double distanceStart, @Nonnull org.joml.Vector3dc ortho, double distance, @Nonnull org.joml.Vector3d result)
      Calculate vector as sum of a linear component and a vector orthogonal to the linear component and a second base vector.
      Parameters:
      start - Origin of linear component
      end - Tip of linear component
      distanceStart - Absolute length to scale linear component
      ortho - Second base vector (must have unit length)
      distance - Absolute length to scale orthogonal component
      result - Sum of linear and orthogonal component
    • lookatHeading

      public static float lookatHeading(@Nonnull org.joml.Vector3d self, @Nonnull org.joml.Vector3d pointOfInterest, float headingHint)
      Compute heading required to look to a point of interest.
      Parameters:
      self - Self position
      pointOfInterest - Position to look at
      headingHint - Heading to return if heading can't be computed (ie points identical)
      Returns:
      direction angle
    • blockEmptySpace

      public static double blockEmptySpace(@Nullable BlockType blockType, int rotation, @Nonnull NPCPhysicsMath.Direction direction)
      Return space along a block type when approaching from a direction along coordinate axis.
      Parameters:
      blockType - The block type to examine.
      direction - Direction to enter block.
      Returns:
      the distance to the first potential collision (between 0 and 1).
    • heightOverGround

      public static double heightOverGround(@Nonnull World world, double x, double y, double z)
      Compute height over ground for a given position.
      Parameters:
      world - World
      x - Position
      y - Position
      z - Position
      Returns:
      Height so that the entity would be above the block hitbox, or Double.NaN if required world data is unavailable
    • heightOverGround

      public static double heightOverGround(@Nonnull World world, double x, double y, double z, int maxSearchHeight)
      Compute height over ground by searching upward for an empty block.
      Parameters:
      world - World
      x - Position
      y - Position
      z - Position
      maxSearchHeight - Maximum number of blocks to search above the initial block
      Returns:
      Height of the block surface below the first empty block, Double.NEGATIVE_INFINITY if no surface was found within the search height, or Double.NaN if required world data is unavailable
    • heightOverGround

      public static double heightOverGround(@Nonnull World world, double x, double z)
      Compute height considering block height at position.
      Parameters:
      world - World
      x - Position
      z - Position
      Returns:
      Height so that the entity would be above the block hitbox, Double.NEGATIVE_INFINITY if the column has no surface, or Double.NaN if required world data is unavailable
    • blockHeight

      public static double blockHeight(@Nullable BlockType blockType, int rotation)
      Compute top hitbox height of block.
      Parameters:
      blockType - Block type
      rotation - Block rotation index
      Returns:
      Top Y coordinate of hitbox
    • blockBottom

      public static double blockBottom(@Nullable BlockType blockType, int rotation)
      Compute bottom hitbox height of block.
      Parameters:
      blockType - Block type
      rotation - Block rotation index
      Returns:
      Bottom Y coordinate of hitbox
    • dotProduct

      public static double dotProduct(double x, double y, double z, @Nonnull org.joml.Vector3d componentSelector)
      Compute dot product of vector with itself with component selector
      Parameters:
      x - Component of vector
      y - Component of vector
      z - Component of vector
      componentSelector - Which components to include
      Returns:
      dot product (x y z)*(x y z) (after applying component selector)
    • dotProduct

      public static double dotProduct(double px, double py, double pz, double qx, double qy, double qz, @Nonnull org.joml.Vector3d componentSelector)
      Compute dot product of two vectors component selector
      Parameters:
      px - Component of first vector
      py - Component of first vector
      pz - Component of first vector
      qx - Component of second vector
      qy - Component of second vector
      qz - Component of second vector
      componentSelector - Which components to include
      Returns:
      dot product (px py pz)*(qx qy qz) (after applying component selector)
    • projectedLengthSquared

      public static double projectedLengthSquared(@Nonnull org.joml.Vector3d v, @Nonnull org.joml.Vector3d componentSelector)
    • projectedLength

      public static double projectedLength(@Nonnull org.joml.Vector3d v, @Nonnull org.joml.Vector3d componentSelector)
    • getMaxBoundingBoxExtent

      public static double getMaxBoundingBoxExtent(@Nonnull Box box, @Nonnull org.joml.Vector3dc componentSelector)
    • getMinBoundingBoxExtent

      public static double getMinBoundingBoxExtent(@Nonnull Box box, @Nonnull org.joml.Vector3dc componentSelector)
    • getMinBoundingBoxDistance

      public static double getMinBoundingBoxDistance(@Nonnull Box box, @Nonnull Box box2, @Nonnull org.joml.Vector3dc componentSelector)
    • getBoundingBoxCenterToCornerDistance

      public static double getBoundingBoxCenterToCornerDistance(@Nonnull Box box, @Nonnull org.joml.Vector3dc componentSelector)
    • dotProductWithSelector

      public static double dotProductWithSelector(@Nonnull org.joml.Vector3d p, @Nonnull org.joml.Vector3d q, @Nonnull org.joml.Vector3d componentSelector)
      Compute dot product of two vectors with component selector
      Parameters:
      p - First vector
      q - Second vector
      componentSelector - Which components to include
      Returns:
      dot product (p*q) (after applying component selector)
    • distanceWithSelector

      public static double distanceWithSelector(@Nonnull org.joml.Vector3d p, @Nonnull org.joml.Vector3d q, @Nonnull org.joml.Vector3d componentSelector)
      Compute distance between two points with component selector
      Parameters:
      p - First point
      q - Second point
      componentSelector - Which components to include
      Returns:
      distance between p and q (after applying component selector)
    • distanceSquaredWithSelector

      public static double distanceSquaredWithSelector(@Nonnull org.joml.Vector3d p, @Nonnull org.joml.Vector3d q, @Nonnull org.joml.Vector3d componentSelector)
      Compute squared distance between two points with component selector
      Parameters:
      p - First point
      q - Second point
      componentSelector - Which components to include
      Returns:
      squared distance between p and q (after applying component selector)
    • intersectSweptSpheres

      public static int intersectSweptSpheres(@Nonnull org.joml.Vector3d p1, @Nonnull org.joml.Vector3d velocity1, @Nonnull org.joml.Vector3d p2, @Nonnull org.joml.Vector3d velocity2, double radius, @Nonnull org.joml.Vector3d componentSelector, double[] results)
      Compute collision between two swept spheres with given position and speed.
      Parameters:
      p1 - Origin of first sphere
      velocity1 - Velocity of first sphere
      p2 - Origin of second sphere
      velocity2 - Velocity of second sphere
      radius - Sum of radiuses of spheres
      componentSelector - Which components to include in case of projection
      results - Space for two values representing time of collision and time of collision end
      Returns:
      0, 1, 2 for number of solutions
    • intersectSweptSpheresFootpoint

      public static int intersectSweptSpheresFootpoint(@Nonnull org.joml.Vector3d p1, @Nonnull org.joml.Vector3d velocity1, double radius1, @Nonnull org.joml.Vector3d p2, @Nonnull org.joml.Vector3d velocity2, double radius2, @Nonnull org.joml.Vector3dc componentSelector, double[] results)
    • intersectSweptSpheres

      public static int intersectSweptSpheres(double p1x, double p1y, double p1z, double velocity1x, double velocity1y, double velocity1z, double p2x, double p2y, double p2z, double velocity2x, double velocity2y, double velocity2z, double radius, @Nonnull org.joml.Vector3dc componentSelector, double[] results)
    • collisionSphereRadius

      public static double collisionSphereRadius(@Nonnull Box boundingBox)
    • collisionSphereRadius

      public static double collisionSphereRadius(double boxWidth, double boxDepth, double boxHeight)
    • collisionSphereRadius

      public static double collisionSphereRadius(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
    • rayCircleIntersect

      public static double rayCircleIntersect(double sx, double sy, double dx, double dy, double radius)
    • rayCircleIntersect

      public static double rayCircleIntersect(@Nonnull org.joml.Vector3dc start, @Nonnull org.joml.Vector3dc end, @Nonnull org.joml.Vector3dc center, double radius, @Nonnull org.joml.Vector3dc normal)
    • projection

      @Nonnull public static org.joml.Vector3d projection(@Nonnull org.joml.Vector3d v, @Nonnull org.joml.Vector3d p, @Nonnull org.joml.Vector3d result)
    • rejection

      @Nonnull public static org.joml.Vector3d rejection(@Nonnull org.joml.Vector3d v, @Nonnull org.joml.Vector3d p, @Nonnull org.joml.Vector3d result)
    • subtractVector

      @Nonnull public static org.joml.Vector3d subtractVector(@Nonnull org.joml.Vector3d p, @Nonnull org.joml.Vector3d q, @Nonnull org.joml.Vector3d result)
    • addDifference

      @Nonnull public static org.joml.Vector3d addDifference(@Nonnull org.joml.Vector3d result, @Nonnull org.joml.Vector3d p, @Nonnull org.joml.Vector3d q)
    • projection

      @Nonnull public static org.joml.Vector3d projection(@Nonnull org.joml.Vector3d base, @Nonnull org.joml.Vector3d v, @Nonnull org.joml.Vector3d p, @Nonnull org.joml.Vector3d result)
    • rejection

      @Nonnull public static org.joml.Vector3d rejection(@Nonnull org.joml.Vector3d base, @Nonnull org.joml.Vector3d v, @Nonnull org.joml.Vector3d p, @Nonnull org.joml.Vector3d result)
    • multiply

      @Nonnull public static org.joml.Vector3d multiply(@Nonnull org.joml.Vector3d v, @Nonnull org.joml.Vector3d w)
    • squaredDistProjected

      public static double squaredDistProjected(double px, double py, double pz, @Nonnull org.joml.Vector3d q, @Nonnull org.joml.Vector3dc normal)
    • squaredDistProjected

      public static double squaredDistProjected(double px, double py, double pz, double qx, double qy, double qz, @Nonnull org.joml.Vector3dc normal)
    • getProjectedDifference

      public static double getProjectedDifference(@Nonnull org.joml.Vector3d p, @Nonnull org.joml.Vector3d q, @Nonnull org.joml.Vector3d componentSelector)
    • isInvalid

      public static boolean isInvalid(double v)
    • isInvalid

      public static boolean isInvalid(@Nonnull org.joml.Vector3d v)
    • isValid

      public static boolean isValid(double v)
    • isValid

      public static boolean isValid(@Nonnull org.joml.Vector3d v)
    • jumpParameters

      public static double jumpParameters(@Nonnull org.joml.Vector3d position, @Nonnull org.joml.Vector3d targetPosition, double gravity, @Nonnull org.joml.Vector3d velocity)
    • accelerate

      public static double accelerate(double v, double a, double t, double limitSpeed)
    • deccelerateToStop

      public static double deccelerateToStop(double v, double a, double t)
    • deccelerateToStop

      @Nonnull public static org.joml.Vector3d deccelerateToStop(@Nonnull org.joml.Vector3d v, double a, double t)
    • accelerateDrag

      public static double accelerateDrag(double v, double a, double t, double terminalVelocity, double p)
    • accelerateDragCapped

      public static double accelerateDragCapped(double v, double a, double t, double terminalVelocity, double p)
    • accelerateDrag

      public static double accelerateDrag(double v, double a, double t, double terminalVelocity)
    • accelerateDragCapped

      public static double accelerateDragCapped(double v, double a, double t, double terminalVelocity)
    • accelerateToTargetSpeed

      public static double accelerateToTargetSpeed(double vCurrent, double vTarget, double dt, double accel, double decel, double vMin, double vMax)
    • accelerateToTargetSpeed

      public static double accelerateToTargetSpeed(double vCurrent, double vTarget, double dt, double accel, double decel, double vMax)
    • accelerateToTargetSpeed

      public static double accelerateToTargetSpeed(double vCurrent, double vTarget, double dt, double accel, double vMax)
    • gravityDrag

      public static double gravityDrag(double v, double a, double t, double terminalVelocity, double p)
    • gravityDrag

      public static double gravityDrag(double v, double a, double t, double terminalVelocity)