Package org.geysermc.geyser.util
Class MathUtils
java.lang.Object
org.geysermc.geyser.util.MathUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.cloudburstmc.math.vector.Vector3fcalculateViewVector(float pitch, float yaw) static intceil(float floatNumber) Round the given float to the next whole numberstatic longchunkPositionToLong(int x, int z) Packs a chunk's X and Z coordinates into a singlelong.static floatclamp(float value, float low, float high) Clamps the value between the low and high boundaries Copied fromGenericMathwith floats instead.static doubleconstrain(double num, double min, double max) If number is greater than the max, set it to max, and if number is lower than low, set it to low.static intconstrain(int num, int min, int max) If number is greater than the max, set it to max, and if number is lower than low, set it to low.static floatunwrapDegrees(double degrees) Unwrap the given double degrees to be between 0.0 and 360.0.static floatunwrapDegrees(float degrees) Unwrap the given float degrees to be between 0.0 and 360.0.static intunwrapDegreesToInt(float degrees) Unwrap the given degrees to be between 0 and 360 as an integer.static floatwrapDegrees(double degrees) Wrap the given double degrees to be between -180.0 and 180.0.static floatwrapDegrees(float degrees) Wrap the given float degrees to be between -180.0 and 180.0.static intwrapDegreesToInt(float degrees) Wrap the given degrees to be between -180 and 180 as an integer.static org.cloudburstmc.math.vector.Vector3fxYRot(org.cloudburstmc.math.vector.Vector3f velocity, float pitch, float yaw)
-
Field Details
-
SQRT_OF_TWO
public static final double SQRT_OF_TWO
-
-
Constructor Details
-
MathUtils
public MathUtils()
-
-
Method Details
-
xYRot
public static org.cloudburstmc.math.vector.Vector3f xYRot(org.cloudburstmc.math.vector.Vector3f velocity, float pitch, float yaw) -
calculateViewVector
public static org.cloudburstmc.math.vector.Vector3f calculateViewVector(float pitch, float yaw) -
wrapDegrees
public static float wrapDegrees(float degrees) Wrap the given float degrees to be between -180.0 and 180.0.- Parameters:
degrees- The degrees value to wrap- Returns:
- The wrapped degrees value between -180.0 and 180.0
-
wrapDegrees
public static float wrapDegrees(double degrees) Wrap the given double degrees to be between -180.0 and 180.0.- Parameters:
degrees- The degrees value to wrap- Returns:
- The wrapped degrees value between -180.0 and 180.0
-
wrapDegreesToInt
public static int wrapDegreesToInt(float degrees) Wrap the given degrees to be between -180 and 180 as an integer.- Parameters:
degrees- The degrees value to wrap- Returns:
- The wrapped degrees value between -180 and 180 as an integer
-
unwrapDegrees
public static float unwrapDegrees(float degrees) Unwrap the given float degrees to be between 0.0 and 360.0.- Parameters:
degrees- The degrees value to unwrap- Returns:
- The unwrapped degrees value between 0.0 and 360.0
-
unwrapDegrees
public static float unwrapDegrees(double degrees) Unwrap the given double degrees to be between 0.0 and 360.0.- Parameters:
degrees- The degrees value to unwrap- Returns:
- The unwrapped degrees value between 0.0 and 360.0
-
unwrapDegreesToInt
public static int unwrapDegreesToInt(float degrees) Unwrap the given degrees to be between 0 and 360 as an integer.- Parameters:
degrees- The degrees value to unwrap- Returns:
- The unwrapped degrees value between 0 and 360 as an integer
-
ceil
public static int ceil(float floatNumber) Round the given float to the next whole number- Parameters:
floatNumber- Float to round- Returns:
- Rounded number
-
constrain
public static double constrain(double num, double min, double max) If number is greater than the max, set it to max, and if number is lower than low, set it to low.- Parameters:
num- number to calculatemin- the lowest value the number can bemax- the greatest value the number can be- Returns:
- - min if num is lower than min
- max if num is greater than max
- num otherwise
-
constrain
public static int constrain(int num, int min, int max) If number is greater than the max, set it to max, and if number is lower than low, set it to low.- Parameters:
num- number to calculatemin- the lowest value the number can bemax- the greatest value the number can be- Returns:
- - min if num is lower than min
- max if num is greater than max
- num otherwise
-
clamp
public static float clamp(float value, float low, float high) Clamps the value between the low and high boundaries Copied fromGenericMathwith floats instead.- Parameters:
value- The value to clamplow- The low bound of the clamphigh- The high bound of the clamp- Returns:
- the clamped value
-
chunkPositionToLong
public static long chunkPositionToLong(int x, int z) Packs a chunk's X and Z coordinates into a singlelong.- Parameters:
x- the X coordinatez- the Z coordinate- Returns:
- the packed coordinates
-