Class PZMath

java.lang.Object
zombie.core.math.PZMath

public final class PZMath extends Object
  • Nested Class Summary

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

    Fields
    Modifier and Type
    Field
    Description
    static final float
    Conversion ratios, Degrees to Radians and back
    static final long
     
    static final long
     
    static final float
    The double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.
    static final float
     
    static final float
     
    static final long
     
    static long
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static float
    abs(float val)
     
    static float
    almostIdentity(float x, float m, float n)
    Almost Identity Imagine you don't want to modify a signal unless it's drops to zero or close to it, in which case you want to replace the value with a small possitive constant.
    static float
    Almost Unit Identity This is a near-identiy function that maps the unit interval into itself.
    static float
    c_lerp(float src, float dest, float alpha)
     
    static boolean
     
    static float
    ceil(float val)
     
    static float
    clamp(float val, float min, float max)
    Result is clamped between min and max.
    static int
    clamp(int val, int min, int max)
    Result is clamped between min and max.
    static long
    clamp(long val, long min, long max)
     
    static float
    clamp_01(float val)
     
    static float
    clampFloat(float val, float min, float max)
     
    static org.lwjgl.util.vector.Matrix4f
    convertMatrix(org.joml.Matrix4f src, org.lwjgl.util.vector.Matrix4f dst)
     
    static org.joml.Matrix4f
    convertMatrix(org.lwjgl.util.vector.Matrix4f src, org.joml.Matrix4f dst)
     
    static float
    degToRad(float degrees)
     
    static boolean
    equal(float a, float b)
     
    static boolean
    equal(float a, float b, float delta)
     
    static int
    fastfloor(double x)
     
    static int
    fastfloor(float x)
     
    static float
    floor(float val)
     
    static float
    frac(float val)
     
    static float
    gain(float x, float k)
    Gain Remapping the unit interval into the unit interval by expanding the sides and compressing the center, and keeping 1/2 mapped to 1/2, that can be done with the gain() function.
    static float
    getClosestAngle(float in_radsA, float in_radsB)
     
    static float
    getClosestAngleDegrees(float in_degsA, float in_degsB)
     
    static float
    lerp(float src, float dest, float alpha)
     
    static org.lwjgl.util.vector.Vector3f
    lerp(org.lwjgl.util.vector.Vector3f out, org.lwjgl.util.vector.Vector3f a, org.lwjgl.util.vector.Vector3f b, float t)
     
    static Vector2
    lerp(Vector2 out, Vector2 a, Vector2 b, float t)
     
    static float
    lerpAngle(float src, float dest, float alpha)
     
    static float
     
    static float
     
    static float
     
    static float
    max(float a, float b)
     
    static int
    max(int a, int b)
     
    static float
    min(float a, float b)
     
    static int
    min(int a, int b)
     
    static float
    radToDeg(float radians)
     
    static float
    roundFromEdges(float val)
     
    static int
    roundToInt(float val)
     
    static float
    roundToIntPlus05(float val)
     
    static float
    roundToNearest(float val)
     
    static int
    sign(float val)
     
    static org.lwjgl.util.vector.Quaternion
    slerp(org.lwjgl.util.vector.Quaternion result, org.lwjgl.util.vector.Quaternion from, org.lwjgl.util.vector.Quaternion to, float alpha)
     
    static float
    sqrt(float val)
     
    static float
    step(float from, float to, float delta)
     
    testSideOfLine(float x1, float y1, float x2, float y2, float px, float py)
     
    static double
    tryParseDouble(String varStr, double defaultVal)
     
    static float
    tryParseFloat(String varStr, float defaultVal)
     
    static int
    tryParseInt(String varStr, int defaultVal)
     
    static float
    wrap(float val, float range)
     
    static float
    wrap(float in_val, float in_min, float in_max)
     

    Methods inherited from class java.lang.Object

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

    • PI

      public static final float PI
      The double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.
      See Also:
    • PI2

      public static final float PI2
      See Also:
    • degToRads

      public static final float degToRads
      Conversion ratios, Degrees to Radians and back
      See Also:
    • radToDegs

      public static final float radToDegs
      See Also:
    • microsToNanos

      public static final long microsToNanos
      See Also:
    • millisToMicros

      public static final long millisToMicros
      See Also:
    • secondsToMillis

      public static final long secondsToMillis
      See Also:
    • secondsToNanos

      public static long secondsToNanos
  • Constructor Details

    • PZMath

      public PZMath()
  • Method Details

    • almostUnitIdentity

      public static float almostUnitIdentity(float x)
      Almost Unit Identity This is a near-identiy function that maps the unit interval into itself. It is the cousin of smoothstep(), in that it maps 0 to 0, 1 to 1, and has a 0 derivative at the origin, just like smoothstep. However, instead of having a 0 derivative at 1, it has a derivative of 1 at that point. It's equivalent to the Almost Identiy above with n=0 and m=1. Since it's a cubic just like smoothstep() it is very fast to evaluate. https://iquilezles.org/www/articles/functions/functions.htm
      Parameters:
      x - value in [0..1]
      Returns:
      value in [0..1]
    • almostIdentity

      public static float almostIdentity(float x, float m, float n)
      Almost Identity Imagine you don't want to modify a signal unless it's drops to zero or close to it, in which case you want to replace the value with a small possitive constant. Then, rather than clamping the value and introduce a discontinuity, you can smoothly blend the signal into the desired clipped value. So, let m be the threshold (anything above m stays unchanged), and n the value things will take when the signal is zero. Then, the following function does the soft clipping (in a cubic fashion): https://iquilezles.org/www/articles/functions/functions.htm
      Parameters:
      x - value in [0..1]
      Returns:
      value in [0..1]
    • gain

      public static float gain(float x, float k)
      Gain Remapping the unit interval into the unit interval by expanding the sides and compressing the center, and keeping 1/2 mapped to 1/2, that can be done with the gain() function. This was a common function in RSL tutorials (the Renderman Shading Language). k=1 is the identity curve, k<1 produces the classic gain() shape, and k>1 produces "s" shaped curces. The curves are symmetric (and inverse) for k=a and k=1/a. https://iquilezles.org/www/articles/functions/functions.htm
      Parameters:
      x -
      k -
      Returns:
    • clamp

      public static float clamp(float val, float min, float max)
      Result is clamped between min and max.
      Returns:
      min <= val <= max
    • clamp

      public static long clamp(long val, long min, long max)
    • clamp

      public static int clamp(int val, int min, int max)
      Result is clamped between min and max.
      Returns:
      min <= val <= max
    • clampFloat

      public static float clampFloat(float val, float min, float max)
    • clamp_01

      public static float clamp_01(float val)
    • lerp

      public static float lerp(float src, float dest, float alpha)
    • lerpAngle

      public static float lerpAngle(float src, float dest, float alpha)
    • lerp

      public static org.lwjgl.util.vector.Vector3f lerp(org.lwjgl.util.vector.Vector3f out, org.lwjgl.util.vector.Vector3f a, org.lwjgl.util.vector.Vector3f b, float t)
    • lerp

      public static Vector2 lerp(Vector2 out, Vector2 a, Vector2 b, float t)
    • c_lerp

      public static float c_lerp(float src, float dest, float alpha)
    • slerp

      public static org.lwjgl.util.vector.Quaternion slerp(org.lwjgl.util.vector.Quaternion result, org.lwjgl.util.vector.Quaternion from, org.lwjgl.util.vector.Quaternion to, float alpha)
    • sqrt

      public static float sqrt(float val)
    • lerpFunc_EaseOutQuad

      public static float lerpFunc_EaseOutQuad(float x)
    • lerpFunc_EaseInQuad

      public static float lerpFunc_EaseInQuad(float x)
    • lerpFunc_EaseOutInQuad

      public static float lerpFunc_EaseOutInQuad(float x)
    • tryParseDouble

      public static double tryParseDouble(String varStr, double defaultVal)
    • tryParseFloat

      public static float tryParseFloat(String varStr, float defaultVal)
    • canParseFloat

      public static boolean canParseFloat(String varStr)
    • tryParseInt

      public static int tryParseInt(String varStr, int defaultVal)
    • degToRad

      public static float degToRad(float degrees)
    • radToDeg

      public static float radToDeg(float radians)
    • getClosestAngle

      public static float getClosestAngle(float in_radsA, float in_radsB)
    • getClosestAngleDegrees

      public static float getClosestAngleDegrees(float in_degsA, float in_degsB)
    • sign

      public static int sign(float val)
    • fastfloor

      public static int fastfloor(double x)
    • fastfloor

      public static int fastfloor(float x)
    • floor

      public static float floor(float val)
    • ceil

      public static float ceil(float val)
    • frac

      public static float frac(float val)
    • wrap

      public static float wrap(float val, float range)
    • wrap

      public static float wrap(float in_val, float in_min, float in_max)
    • max

      public static float max(float a, float b)
    • max

      public static int max(int a, int b)
    • min

      public static float min(float a, float b)
    • min

      public static int min(int a, int b)
    • abs

      public static float abs(float val)
    • equal

      public static boolean equal(float a, float b)
    • equal

      public static boolean equal(float a, float b, float delta)
    • convertMatrix

      public static org.lwjgl.util.vector.Matrix4f convertMatrix(org.joml.Matrix4f src, org.lwjgl.util.vector.Matrix4f dst)
    • convertMatrix

      public static org.joml.Matrix4f convertMatrix(org.lwjgl.util.vector.Matrix4f src, org.joml.Matrix4f dst)
    • step

      public static float step(float from, float to, float delta)
    • testSideOfLine

      public static PZMath.SideOfLine testSideOfLine(float x1, float y1, float x2, float y2, float px, float py)
    • roundToNearest

      public static float roundToNearest(float val)
    • roundToInt

      public static int roundToInt(float val)
    • roundToIntPlus05

      public static float roundToIntPlus05(float val)
    • roundFromEdges

      public static float roundFromEdges(float val)