Contents
- Description
- Nested Class Summary
- Field Summary
- Method Summary
- Field Details
- Method Details
- near(Vector3dc, Vector3dc)
- near(Vector3dc, Vector3dc, double)
- near(double, double)
- near(double, double, double)
- headingFromDirection(double, double, float)
- pitchFromDirection(double, double, double, float)
- rotationFromDirection(double, double, double, Rotation3fc, Rotation3f)
- rotationFromDirection(Vector3dc, Rotation3fc, Rotation3f)
- rotationFromDirection(Vector3dc, Vector3dc, Rotation3fc, Rotation3f)
- getViewDirection(Rotation3f, Vector3d)
- cosAngleBetweenVectors(Vector3d, Vector3d)
- cosAngleBetweenVectors(Vector3d, double, Vector3d, double)
- cosAngleBetweenUnitVectors(Vector3d, Vector3d)
- realignVector(Vector3d, Vector3d, double, Vector3d)
- realignVector(Vector3d, double, Vector3d, double, double, Vector3d)
- realignUnitVector(Vector3d, Vector3d, double, Vector3d)
- realignVectorReturnDirection(Vector3d, double, Vector3d, double, double, Vector3d)
- createOrthogonalvector(Vector3d, Vector3d)
- inViewSector(double, double, float, float, double, double)
- isInViewCone(double, double, double, double, double, double, float, double, double, double)
- isInViewCone(double, double, double, float, double, double, double)
- isInViewCone(Vector3d, Vector3d, float, Vector3d)
- isInViewCone(Vector3d, Vector3d, float, Vector3d, Vector3d)
- turnAngle(float, float)
- clampRotation(float, float)
- intersectLineSphere(Vector3d, double, Vector3d, Vector3d, Vector3d, Vector3d, boolean)
- intersectLineSphereLerp(Vector3d, double, Vector3d, Vector3d, Vector3d, Vector3d, Vector3d)
- intersectLineSphereLerp(Vector3d, double, Vector3d, Vector3d, Vector3d)
- dotProduct(Vector3d, Vector3d, Vector3d)
- dotProduct(Vector3d, Vector3d, Vector3d, Vector3d)
- dotProduct(double, double, double)
- dotProduct(double, double, double, double, double, double)
- dotProduct(float, float, float)
- dotProduct(float, float, float, float, float, float)
- lerpDistance(Vector3d, Vector3d, double, Vector3d)
- lerp(Vector3d, Vector3d, double, Vector3d)
- lerp(double, double, double)
- offsetVector(Vector3d, double, double, double, double, Vector3d)
- offsetVector(double, double, double, double, double, double, double, Vector3d)
- orthoComposition(Vector3d, Vector3d, Vector3d, double, Vector3d)
- orthoComposition(Vector3dc, Vector3dc, double, Vector3dc, double, Vector3d)
- lookatHeading(Vector3d, Vector3d, float)
- blockEmptySpace(BlockType, int, NPCPhysicsMath.Direction)
- heightOverGround(World, double, double, double)
- heightOverGround(World, double, double, double, int)
- heightOverGround(World, double, double)
- blockHeight(BlockType, int)
- blockBottom(BlockType, int)
- dotProduct(double, double, double, Vector3d)
- dotProduct(double, double, double, double, double, double, Vector3d)
- projectedLengthSquared(Vector3d, Vector3d)
- projectedLength(Vector3d, Vector3d)
- getMaxBoundingBoxExtent(Box, Vector3dc)
- getMinBoundingBoxExtent(Box, Vector3dc)
- getMinBoundingBoxDistance(Box, Box, Vector3dc)
- getBoundingBoxCenterToCornerDistance(Box, Vector3dc)
- dotProductWithSelector(Vector3d, Vector3d, Vector3d)
- distanceWithSelector(Vector3d, Vector3d, Vector3d)
- distanceSquaredWithSelector(Vector3d, Vector3d, Vector3d)
- intersectSweptSpheres(Vector3d, Vector3d, Vector3d, Vector3d, double, Vector3d, double[])
- intersectSweptSpheresFootpoint(Vector3d, Vector3d, double, Vector3d, Vector3d, double, Vector3dc, double[])
- intersectSweptSpheres(double, double, double, double, double, double, double, double, double, double, double, double, double, Vector3dc, double[])
- collisionSphereRadius(Box)
- collisionSphereRadius(double, double, double)
- collisionSphereRadius(Ref, ComponentAccessor)
- rayCircleIntersect(double, double, double, double, double)
- rayCircleIntersect(Vector3dc, Vector3dc, Vector3dc, double, Vector3dc)
- projection(Vector3d, Vector3d, Vector3d)
- rejection(Vector3d, Vector3d, Vector3d)
- subtractVector(Vector3d, Vector3d, Vector3d)
- addDifference(Vector3d, Vector3d, Vector3d)
- projection(Vector3d, Vector3d, Vector3d, Vector3d)
- rejection(Vector3d, Vector3d, Vector3d, Vector3d)
- multiply(Vector3d, Vector3d)
- squaredDistProjected(double, double, double, Vector3d, Vector3dc)
- squaredDistProjected(double, double, double, double, double, double, Vector3dc)
- getProjectedDifference(Vector3d, Vector3d, Vector3d)
- isInvalid(double)
- isInvalid(Vector3d)
- isValid(double)
- isValid(Vector3d)
- jumpParameters(Vector3d, Vector3d, double, Vector3d)
- accelerate(double, double, double, double)
- deccelerateToStop(double, double, double)
- deccelerateToStop(Vector3d, double, double)
- accelerateDrag(double, double, double, double, double)
- accelerateDragCapped(double, double, double, double, double)
- accelerateDrag(double, double, double, double)
- accelerateDragCapped(double, double, double, double)
- accelerateToTargetSpeed(double, double, double, double, double, double, double)
- accelerateToTargetSpeed(double, double, double, double, double, double)
- accelerateToTargetSpeed(double, double, double, double, double)
- gravityDrag(double, double, double, double, double)
- gravityDrag(double, double, double, double)
Class NPCPhysicsMath
java.lang.Object
com.hypixel.hytale.server.npc.util.NPCPhysicsMath
Math helper for world calculations or alternative implementations of existing functions requiring no memory allocations.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doublestatic final double -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleaccelerate(double v, double a, double t, double limitSpeed) static doubleaccelerateDrag(double v, double a, double t, double terminalVelocity) static doubleaccelerateDrag(double v, double a, double t, double terminalVelocity, double p) static doubleaccelerateDragCapped(double v, double a, double t, double terminalVelocity) static doubleaccelerateDragCapped(double v, double a, double t, double terminalVelocity, double p) static doubleaccelerateToTargetSpeed(double vCurrent, double vTarget, double dt, double accel, double vMax) static doubleaccelerateToTargetSpeed(double vCurrent, double vTarget, double dt, double accel, double decel, double vMax) static doubleaccelerateToTargetSpeed(double vCurrent, double vTarget, double dt, double accel, double decel, double vMin, double vMax) static org.joml.Vector3daddDifference(org.joml.Vector3d result, org.joml.Vector3d p, org.joml.Vector3d q) static doubleblockBottom(BlockType blockType, int rotation) Compute bottom hitbox height of block.static doubleblockEmptySpace(BlockType blockType, int rotation, NPCPhysicsMath.Direction direction) Return space along a block type when approaching from a direction along coordinate axis.static doubleblockHeight(BlockType blockType, int rotation) Compute top hitbox height of block.static floatclampRotation(float rotation, float maxAngle) Clamp a rotation angle to interval [-maxAngle, +maxAngle]static doublecollisionSphereRadius(double boxWidth, double boxDepth, double boxHeight) static doublecollisionSphereRadius(Ref<EntityStore> ref, ComponentAccessor<EntityStore> componentAccessor) static doublecollisionSphereRadius(Box boundingBox) static doublecosAngleBetweenUnitVectors(org.joml.Vector3d v, org.joml.Vector3d w) static doublecosAngleBetweenVectors(org.joml.Vector3d v, double vLen, org.joml.Vector3d w, double wLen) static doublecosAngleBetweenVectors(org.joml.Vector3d v, org.joml.Vector3d w) static org.joml.Vector3dcreateOrthogonalvector(org.joml.Vector3d in, org.joml.Vector3d out) static doubledeccelerateToStop(double v, double a, double t) static org.joml.Vector3ddeccelerateToStop(org.joml.Vector3d v, double a, double t) static doubledistanceSquaredWithSelector(org.joml.Vector3d p, org.joml.Vector3d q, org.joml.Vector3d componentSelector) Compute squared distance between two points with component selectorstatic doubledistanceWithSelector(org.joml.Vector3d p, org.joml.Vector3d q, org.joml.Vector3d componentSelector) Compute distance between two points with component selectorstatic doubledotProduct(double dx, double dy, double dz) static doubledotProduct(double px, double py, double pz, double qx, double qy, double qz) static doubledotProduct(double px, double py, double pz, double qx, double qy, double qz, org.joml.Vector3d componentSelector) Compute dot product of two vectors component selectorstatic doubledotProduct(double x, double y, double z, org.joml.Vector3d componentSelector) Compute dot product of vector with itself with component selectorstatic doubledotProduct(float dx, float dy, float dz) static doubledotProduct(float px, float py, float pz, float qx, float qy, float qz) static doubledotProduct(org.joml.Vector3d base, org.joml.Vector3d p, org.joml.Vector3d q) Compute dot product between a ray and a point.static doubledotProduct(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 doubledotProductWithSelector(org.joml.Vector3d p, org.joml.Vector3d q, org.joml.Vector3d componentSelector) Compute dot product of two vectors with component selectorstatic doublegetBoundingBoxCenterToCornerDistance(Box box, org.joml.Vector3dc componentSelector) static doublegetMaxBoundingBoxExtent(Box box, org.joml.Vector3dc componentSelector) static doublegetMinBoundingBoxDistance(Box box, Box box2, org.joml.Vector3dc componentSelector) static doublegetMinBoundingBoxExtent(Box box, org.joml.Vector3dc componentSelector) static doublegetProjectedDifference(org.joml.Vector3d p, org.joml.Vector3d q, org.joml.Vector3d componentSelector) static org.joml.Vector3dgetViewDirection(Rotation3f rotation, org.joml.Vector3d outDirection) Compute view direction (not necessarily normalized) of an entity.static doublegravityDrag(double v, double a, double t, double terminalVelocity) static doublegravityDrag(double v, double a, double t, double terminalVelocity, double p) static floatheadingFromDirection(double x, double z, float def) Get heading from x/z directional vector using game coordinate system.static doubleheightOverGround(World world, double x, double z) Compute height considering block height at position.static doubleheightOverGround(World world, double x, double y, double z) Compute height over ground for a given position.static doubleheightOverGround(World world, double x, double y, double z, int maxSearchHeight) Compute height over ground by searching upward for an empty block.static intintersectLineSphere(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 doubleintersectLineSphereLerp(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 doubleintersectLineSphereLerp(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 intintersectSweptSpheres(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 intintersectSweptSpheres(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 intintersectSweptSpheresFootpoint(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 booleaninViewSector(double xViewer, double zViewer, float heading, float coneAngle, double xObject, double zObject) 2D view sector test.static booleanisInvalid(double v) static booleanisInvalid(org.joml.Vector3d v) static booleanisInViewCone(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 booleanisInViewCone(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 booleanisInViewCone(org.joml.Vector3d viewer, org.joml.Vector3d viewDirection, float cosConeHalfAngle, org.joml.Vector3d object) Test if object is within view cone of viewer.static booleanisInViewCone(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 booleanisValid(double v) static booleanisValid(org.joml.Vector3d v) static doublejumpParameters(org.joml.Vector3d position, org.joml.Vector3d targetPosition, double gravity, org.joml.Vector3d velocity) static doublelerp(double a, double b, double s) Linear interpolate between two doubles.static voidlerp(org.joml.Vector3d start, org.joml.Vector3d end, double lambda, org.joml.Vector3d result) Point on ray between two point with lerp factor.static voidlerpDistance(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 floatlookatHeading(org.joml.Vector3d self, org.joml.Vector3d pointOfInterest, float headingHint) Compute heading required to look to a point of interest.static org.joml.Vector3dmultiply(org.joml.Vector3d v, org.joml.Vector3d w) static booleannear(double v, double w) static booleannear(double v, double w, double epsilonLength) static booleannear(org.joml.Vector3dc v, org.joml.Vector3dc w) static booleannear(org.joml.Vector3dc v, org.joml.Vector3dc w, double epsilonLength) static voidoffsetVector(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 voidoffsetVector(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 voidorthoComposition(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 voidorthoComposition(org.joml.Vector3d start, org.joml.Vector3d end, org.joml.Vector3d ortho, double distance, org.joml.Vector3d result) static floatpitchFromDirection(double x, double y, double z, float def) Return pitch from x/y/z direction vector using game coordinate system.static doubleprojectedLength(org.joml.Vector3d v, org.joml.Vector3d componentSelector) static doubleprojectedLengthSquared(org.joml.Vector3d v, org.joml.Vector3d componentSelector) static org.joml.Vector3dprojection(org.joml.Vector3d v, org.joml.Vector3d p, org.joml.Vector3d result) static org.joml.Vector3dprojection(org.joml.Vector3d base, org.joml.Vector3d v, org.joml.Vector3d p, org.joml.Vector3d result) static doublerayCircleIntersect(double sx, double sy, double dx, double dy, double radius) static doublerayCircleIntersect(org.joml.Vector3dc start, org.joml.Vector3dc end, org.joml.Vector3dc center, double radius, org.joml.Vector3dc normal) static voidrealignUnitVector(org.joml.Vector3d v, org.joml.Vector3d w, double cosine, org.joml.Vector3d result) static voidrealignVector(org.joml.Vector3d v, double vLen, org.joml.Vector3d w, double wLen, double cosine, org.joml.Vector3d result) static voidrealignVector(org.joml.Vector3d v, org.joml.Vector3d w, double cosine, org.joml.Vector3d result) static booleanrealignVectorReturnDirection(org.joml.Vector3d v, double vLen, org.joml.Vector3d w, double wLen, double cosine, org.joml.Vector3d result) static org.joml.Vector3drejection(org.joml.Vector3d v, org.joml.Vector3d p, org.joml.Vector3d result) static org.joml.Vector3drejection(org.joml.Vector3d base, org.joml.Vector3d v, org.joml.Vector3d p, org.joml.Vector3d result) static voidrotationFromDirection(double x, double y, double z, Rotation3fc inRotation, Rotation3f outRotation) Return rotation with pitch and yaw computed from direction.static voidrotationFromDirection(org.joml.Vector3dc direction, Rotation3fc inRotation, Rotation3f outRotation) static voidrotationFromDirection(org.joml.Vector3dc from, org.joml.Vector3dc to, Rotation3fc inRotation, Rotation3f outRotation) static doublesquaredDistProjected(double px, double py, double pz, double qx, double qy, double qz, org.joml.Vector3dc normal) static doublesquaredDistProjected(double px, double py, double pz, org.joml.Vector3d q, org.joml.Vector3dc normal) static org.joml.Vector3dsubtractVector(org.joml.Vector3d p, org.joml.Vector3d q, org.joml.Vector3d result) static floatturnAngle(float from, float to) Return smallest angle to rotate from angle to another angle
-
Field Details
-
EPSILON_LENGTH
public static final double EPSILON_LENGTH- See Also:
-
EPSILON_LENGTH_2
public static final double EPSILON_LENGTH_2- See Also:
-
-
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 directionz- z component of directiondef- 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 directiony- y component of directionz- z component of directiondef- 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 rotationoutDirection- 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 tipzViewer- position of view sector tipheading- direction of view coneconeAngle- view cone full anglexObject- position of targetzObject- 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 vieweryViewer- coordinate viewerzViewer- coordinate viewerxViewDirection- 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 objectyObject- coordinate objectzObject- 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 objectyObject- relative coordinate objectzObject- 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 viewerviewDirection- 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 viewerviewDirection- view direction (normalized)cosConeHalfAngle- cosine of half angle of view cone [cos(viewAngle/2)]object- position of objectcomponentSelector- 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 radianto- 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 clampmaxAngle- 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 sphereradius- Radius of spherep- Start position of lineq- End position of linex1- 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 sphereradius- Radius of spherep- Start position of lineq- End position of linet1- Temp valuet2- Temp valuecomponentSelector- 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 sphereradius- Radius of spherep- Start position of lineq- End position of linecomponentSelector- 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 vectorp- Point on vector specifying directionq- 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 vectorp- Point on vector specifying directionq- Point in spacecomponentSelector- 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 rayend- Other point on ray specifying directiondistance- Distance from start pointresult- 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 rayend- Other point on ray specifying directionlambda- Distance factor where 0 is start point and 1 second point specifiedresult- 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 0b- value when s equals 1s- 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- Origindx- Direction xdy- Direction ydz- Direction zlambda- Scale factorresult- 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 xsy- Origin ysz- Origin zdx- Direction xdy- Direction ydz- Direction zlambda- Scale factorresult- 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 componentend- Tip of linear componentdistanceStart- Absolute length to scale linear componentortho- Second base vector (must have unit length)distance- Absolute length to scale orthogonal componentresult- 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 positionpointOfInterest- Position to look atheadingHint- 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
Compute height over ground for a given position.- Parameters:
world- Worldx- Positiony- Positionz- Position- Returns:
- Height so that the entity would be above the block hitbox, or
Double.NaNif 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- Worldx- Positiony- Positionz- PositionmaxSearchHeight- Maximum number of blocks to search above the initial block- Returns:
- Height of the block surface below the first empty block,
Double.NEGATIVE_INFINITYif no surface was found within the search height, orDouble.NaNif required world data is unavailable
-
heightOverGround
Compute height considering block height at position.- Parameters:
world- Worldx- Positionz- Position- Returns:
- Height so that the entity would be above the block hitbox,
Double.NEGATIVE_INFINITYif the column has no surface, orDouble.NaNif required world data is unavailable
-
blockHeight
Compute top hitbox height of block.- Parameters:
blockType- Block typerotation- Block rotation index- Returns:
- Top Y coordinate of hitbox
-
blockBottom
Compute bottom hitbox height of block.- Parameters:
blockType- Block typerotation- 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 vectory- Component of vectorz- Component of vectorcomponentSelector- 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 vectorpy- Component of first vectorpz- Component of first vectorqx- Component of second vectorqy- Component of second vectorqz- Component of second vectorcomponentSelector- 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
-
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 vectorq- Second vectorcomponentSelector- 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 pointq- Second pointcomponentSelector- 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 pointq- Second pointcomponentSelector- 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 spherevelocity1- Velocity of first spherep2- Origin of second spherevelocity2- Velocity of second sphereradius- Sum of radiuses of spherescomponentSelector- Which components to include in case of projectionresults- 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
-
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)
-