Class Vector3f

java.lang.Object
net.risingworld.api.utils.Vector3f
All Implemented Interfaces:
Serializable

public class Vector3f extends Object implements Serializable
A Vector which holds three float values: X, Y and Z
It can be used to represent a three dimensional value, like a position or a direction.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Vector3f
    A unit vector along the -Z axis (backward direction)
    static final Vector3f
    A unit vector along the -Y axis (down direction)
    static final Vector3f
    A unit vector along the Z axis (forward direction)
    static final Vector3f
    A unit vector along the -X axis (left direction)
    static final Vector3f
    A vector with values 1, 1, 1
    static final Vector3f
    A unit vector along the X axis (right direction)
    static final Vector3f
    A unit vector along the Y axis (up direction)
    float
    The X value of this vector
    float
    The Y value of this vector
    float
    The Z value of this vector
    static final Vector3f
    A vector with values 0, 0, 0
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new Vector3f with default values 0, 0, 0.
    Vector3f(float x, float y, float z)
    Creates a new Vector3f with the provided values.
    Creates a new Vector3f and copies the X, Y and Z values from the provided vector.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(float addX, float addY, float addZ)
    Creates a new vector with the same values of this vector and adds the provided values.
    add(Vector3f other)
    Creates a new vector with the same values of this vector and adds the values of the provided vector.
    addLocal(float addX, float addY, float addZ)
    Adds the provided values to the values of this vector.
    Adds the values of the provided vector to the values of this vector.
    float
    Gets the angle between this vector and another vector.
    Creates a copy of this Vector.
    cross(Vector3f other)
    Creates a new vector containing the cross product of this vector and another vector.
    crossLocal(float v2x, float v2y, float v2z)
    Calculates the cross product of this vector and the provided coordinates.
    Calculates the cross product of this vector and another vector.
    float
    distance(float x, float y, float z)
    Gets the distance between this vector and the provided coordinates.
    float
    Gets the distance between this vector and another vector.
    float
    distanceSquared(float x, float y, float z)
    Gets the squared distance between this vector and the provided coordinates.
    float
    Gets the squared distance between this vector and another Vector3f.
    Creates a new vector with the same values of this vector and divides the values of the provided vector.
    divideLocal(float scalar)
     
     
    float
    dot(float x, float y, float z)
    Gets the dot product of this vector with the provided coordinates.
    float
    dot(Vector3f other)
    Gets the dot product of this vector with the provided vector.
    boolean
    equals(float x, float y, float z)
     
    boolean
    Gets whether or not this vector is equal to another object.
     
    float
    Returns the x value of this vector.
    float
    Returns the y value of this vector.
    float
    Returns the z value of this vector.
    int
    Gets a unique* hash code for this vector, based on its values.
    interpolate(Vector3f startVector, Vector3f finalVector, float mu)
    Creates a new vector containing the interpolated values between the start vector and the final vector.
    interpolateLocal(Vector3f finalVector, float mu)
    Interpolates this vector to the provided final vector, e.g if this vector is (0, 5, 10), and the final vector is (-10, 0, 10), the result (by using a mu-value of 0.5f) would be (-5, 2.5f, 10)
    interpolateLocal(Vector3f startVector, Vector3f finalVector, float mu)
    Interpolates between the provided start and end vector and stores the result in this vector.
    boolean
    isOrthogonal(float x, float y, float z)
    Checks if this vector is orthogonal to another vector (i.e the angle between both vectors is ~ 90° degree).
    boolean
    Checks if this vector is orthogonal to another vector (i.e the angle between both vectors is ~ 90° degree).
    boolean
    Checks if this vector is a unit vector.
    float
    Gets the length of this vector.
    float
    Gets the squared length of this vector.
    mult(float scalar)
    Creates a new vector with the same values of this vector and multiplies them with the provided scalar.
    mult(float multX, float multY, float multZ)
    Creates a new vector with the same values of this vector and multiplies the provided values.
    mult(Vector3f other)
    Creates a new vector with the same values of this vector and multiplies the values of the provided vector.
    multLocal(float scalar)
    Multiplies the values of this vector with the provided scalar.
    multLocal(float multX, float multY, float multZ)
    Multiplies the values of this vector with the provided values.
    Multiplies the values of this vector with the values of the provided vector.
    Creates a new vector which contains negated values of this vector.
    Negates all values of this vector.
    Creates a new vector containing normalized values of this vector (i.e as a unit vector).
    Normalizes this vector (i.e turn it into a unit vector).
    set(float x, float y, float z)
    Sets the x, y and z values of this vector to the provided values.
    set(Vector3f vector)
    Sets the x, y and z values of this vector to the values of the provided vector.
    setX(float x)
    Sets the x value of this vector.
    setY(float y)
    Sets the y value of this vector.
    setZ(float z)
    Sets the z value of this vector.
    subtract(float subtractX, float subtractY, float subtractZ)
    Creates a new vector with the same values of this vector and subtracts the provided values.
    Creates a new vector with the same values of this vector and subtracts the values of the provided vector.
    subtractLocal(float subtractX, float subtractY, float subtractZ)
    Subtracts the provided values from the values of this vector.
    Subtracts the values of the provided vector from the values of this vector.
    Gets a String representation of this vector, for example (4.0, 5.25, 10.998)

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • ZERO

      public static final Vector3f ZERO
      A vector with values 0, 0, 0
    • ONE

      public static final Vector3f ONE
      A vector with values 1, 1, 1
    • LEFT

      public static final Vector3f LEFT
      A unit vector along the -X axis (left direction)
    • UP

      public static final Vector3f UP
      A unit vector along the Y axis (up direction)
    • DOWN

      public static final Vector3f DOWN
      A unit vector along the -Y axis (down direction)
    • FORWARD

      public static final Vector3f FORWARD
      A unit vector along the Z axis (forward direction)
    • BACK

      public static final Vector3f BACK
      A unit vector along the -Z axis (backward direction)
    • x

      public float x
      The X value of this vector
    • y

      public float y
      The Y value of this vector
    • z

      public float z
      The Z value of this vector
  • Constructor Details

    • Vector3f

      public Vector3f()
      Creates a new Vector3f with default values 0, 0, 0.
    • Vector3f

      public Vector3f(float x, float y, float z)
      Creates a new Vector3f with the provided values.
      Parameters:
      x - the x value of the vector.
      y - the y value of the vector.
      z - the z value of the vector.
    • Vector3f

      public Vector3f(Vector3f copy)
      Creates a new Vector3f and copies the X, Y and Z values from the provided vector.
      Parameters:
      copy - the Vector3f to copy.
  • Method Details

    • copy

      public Vector3f copy()
      Creates a copy of this Vector.
      Returns:
      a new instance with the same values of this Vector.
    • set

      public Vector3f set(Vector3f vector)
      Sets the x, y and z values of this vector to the values of the provided vector.
      Parameters:
      vector - the Vector3f to copy.
      Returns:
      this vector.
    • set

      public Vector3f set(float x, float y, float z)
      Sets the x, y and z values of this vector to the provided values.
      Parameters:
      x - the x value.
      y - the y value.
      z - the z value.
      Returns:
      this vector.
    • setX

      public Vector3f setX(float x)
      Sets the x value of this vector.
      Parameters:
      x - the new x value.
      Returns:
      this vector.
    • setY

      public Vector3f setY(float y)
      Sets the y value of this vector.
      Parameters:
      y - the new y value.
      Returns:
      this vector.
    • setZ

      public Vector3f setZ(float z)
      Sets the z value of this vector.
      Parameters:
      z - the new z value.
      Returns:
      this vector.
    • getX

      public float getX()
      Returns the x value of this vector.
      Returns:
      the current x value.
    • getY

      public float getY()
      Returns the y value of this vector.
      Returns:
      the current y value.
    • getZ

      public float getZ()
      Returns the z value of this vector.
      Returns:
      the current z value.
    • dot

      public float dot(Vector3f other)
      Gets the dot product of this vector with the provided vector.
      Parameters:
      other - the vector to calculate the dot product with.
      Returns:
      the resulting dot product.
    • dot

      public float dot(float x, float y, float z)
      Gets the dot product of this vector with the provided coordinates.
      Parameters:
      x - the x coordinate.
      y - the y coordinate.
      z - the z coordinate.
      Returns:
      the resulting dot product.
    • length

      public float length()
      Gets the length of this vector.
      Returns:
      the length of this vector.
      See Also:
    • lengthSquared

      public float lengthSquared()
      Gets the squared length of this vector. Use this function to avoid calculating the squareroot.
      Returns:
      the squared length of this vector.
      See Also:
    • distance

      public float distance(Vector3f other)
      Gets the distance between this vector and another vector.
      Parameters:
      other - the other vector.
      Returns:
      the distance between this vector and another vector.
      See Also:
    • distance

      public float distance(float x, float y, float z)
      Gets the distance between this vector and the provided coordinates.
      Parameters:
      x - the other x coordinate.
      y - the other y coordinate.
      z - the other z coordinate.
      Returns:
      the distance between this vector and the provided coordinates.
      See Also:
    • distanceSquared

      public float distanceSquared(Vector3f other)
      Gets the squared distance between this vector and another Vector3f. Use this function to avoid calculating the squareroot.
      Parameters:
      other - the other Vector3f.
      Returns:
      the squared distance between this vector and the provided Vector3f.
    • distanceSquared

      public float distanceSquared(float x, float y, float z)
      Gets the squared distance between this vector and the provided coordinates. Use this function to avoid calculating the squareroot.
      Parameters:
      x - the other x coordinate.
      y - the other y coordinate.
      z - the other z coordinate.
      Returns:
      the squared distance between this vector and the provided coordinates.
    • add

      public Vector3f add(Vector3f other)
      Creates a new vector with the same values of this vector and adds the values of the provided vector. Same as new Vector3f(this).addLocal(other);
      Parameters:
      other - the vector to add.
      Returns:
      the newly created vector.
    • add

      public Vector3f add(float addX, float addY, float addZ)
      Creates a new vector with the same values of this vector and adds the provided values. Same as new Vector3f(this).addLocal(x, y, z);
      Parameters:
      addX - the x value to add.
      addY - the y value to add.
      addZ - the z value to add.
      Returns:
      the newly created vector.
    • addLocal

      public Vector3f addLocal(Vector3f other)
      Adds the values of the provided vector to the values of this vector.
      Parameters:
      other - the vector to add.
      Returns:
      this vector.
    • addLocal

      public Vector3f addLocal(float addX, float addY, float addZ)
      Adds the provided values to the values of this vector.
      Parameters:
      addX - the x value to add.
      addY - the y value to add.
      addZ - the z value to add.
      Returns:
      this vector.
    • subtract

      public Vector3f subtract(Vector3f other)
      Creates a new vector with the same values of this vector and subtracts the values of the provided vector. Same as new Vector3f(this).subtractLocal(other);
      Parameters:
      other - the vector to subtract.
      Returns:
      the newly created vector.
    • subtract

      public Vector3f subtract(float subtractX, float subtractY, float subtractZ)
      Creates a new vector with the same values of this vector and subtracts the provided values. Same as new Vector3f(this).subtractLocal(x, y, z);
      Parameters:
      subtractX - the x value to subtract.
      subtractY - the y value to subtract.
      subtractZ - the z value to subtract.
      Returns:
      the newly created vector.
    • subtractLocal

      public Vector3f subtractLocal(Vector3f other)
      Subtracts the values of the provided vector from the values of this vector.
      Parameters:
      other - the vector to subtract.
      Returns:
      this vector.
    • subtractLocal

      public Vector3f subtractLocal(float subtractX, float subtractY, float subtractZ)
      Subtracts the provided values from the values of this vector.
      Parameters:
      subtractX - the x value to subtract.
      subtractY - the y value to subtract.
      subtractZ - the z value to subtract.
      Returns:
      this vector.
    • mult

      public Vector3f mult(float scalar)
      Creates a new vector with the same values of this vector and multiplies them with the provided scalar.
      Parameters:
      scalar - the value to multiply the vector by.
      Returns:
      the newly created vector.
    • mult

      public Vector3f mult(Vector3f other)
      Creates a new vector with the same values of this vector and multiplies the values of the provided vector. Same as new Vector3f(this).multLocal(other);
      Parameters:
      other - the vector to multiply.
      Returns:
      the newly created vector.
    • mult

      public Vector3f mult(float multX, float multY, float multZ)
      Creates a new vector with the same values of this vector and multiplies the provided values. Same as new Vector3f(this).multLocal(x, y, z);
      Parameters:
      multX - the x value to multiply.
      multY - the y value to multiply.
      multZ - the z value to multiply.
      Returns:
      the newly created vector.
    • multLocal

      public Vector3f multLocal(float scalar)
      Multiplies the values of this vector with the provided scalar.
      Parameters:
      scalar - the value to multiply this vector by.
      Returns:
      this vector.
    • multLocal

      public Vector3f multLocal(Vector3f other)
      Multiplies the values of this vector with the values of the provided vector.
      Parameters:
      other - the vector to multiply.
      Returns:
      this vector.
    • multLocal

      public Vector3f multLocal(float multX, float multY, float multZ)
      Multiplies the values of this vector with the provided values.
      Parameters:
      multX - the x value to multiply the x coordinate of this vector by.
      multY - the y value to multiply the y coordinate of this vector by.
      multZ - the z value to multiply the z coordinate of this vector by.
      Returns:
      this vector.
    • divide

      public Vector3f divide(Vector3f other)
      Creates a new vector with the same values of this vector and divides the values of the provided vector. Same as new Vector3f(this).divideLocal(other);
      Parameters:
      other - the vector to divide.
      Returns:
      the newly created vector.
    • divideLocal

      public Vector3f divideLocal(float scalar)
    • divideLocal

      public Vector3f divideLocal(Vector3f other)
    • negate

      public Vector3f negate()
      Creates a new vector which contains negated values of this vector.
      Returns:
      the newly created vector.
    • negateLocal

      public Vector3f negateLocal()
      Negates all values of this vector.
      Returns:
      this vector.
    • cross

      public Vector3f cross(Vector3f other)
      Creates a new vector containing the cross product of this vector and another vector.
      Parameters:
      other - the other vector.
      Returns:
      the newly created vector.
    • crossLocal

      public Vector3f crossLocal(Vector3f other)
      Calculates the cross product of this vector and another vector.
      Parameters:
      other - the other vector.
      Returns:
      this vector.
    • crossLocal

      public Vector3f crossLocal(float v2x, float v2y, float v2z)
      Calculates the cross product of this vector and the provided coordinates.
      Parameters:
      v2x - the other x coordinate.
      v2y - the other y coordinate.
      v2z - the other z coordinate.
      Returns:
      this vector.
    • normalize

      public Vector3f normalize()
      Creates a new vector containing normalized values of this vector (i.e as a unit vector).
      Returns:
      a newly created, normalized vector.
    • normalizeLocal

      public Vector3f normalizeLocal()
      Normalizes this vector (i.e turn it into a unit vector).
      Returns:
      this vector (normalized).
    • angleBetween

      public float angleBetween(Vector3f other)
      Gets the angle between this vector and another vector.
      Parameters:
      other - the other vector (unit vector).
      Returns:
      the angle in degrees.
    • isUnitVector

      public boolean isUnitVector()
      Checks if this vector is a unit vector.
      Returns:
      true if this is a unit vector, false if not.
    • isOrthogonal

      public boolean isOrthogonal(Vector3f other)
      Checks if this vector is orthogonal to another vector (i.e the angle between both vectors is ~ 90° degree).
      Parameters:
      other - the other vector.
      Returns:
      true if this vector is orthogonal to the other vector, false if not.
    • isOrthogonal

      public boolean isOrthogonal(float x, float y, float z)
      Checks if this vector is orthogonal to another vector (i.e the angle between both vectors is ~ 90° degree).
      Parameters:
      x - the x coordinate of the other vector.
      y - the y coordinate of the other vector.
      z - the z coordinate of the other vector.
      Returns:
      true if this vector is orthogonal to the other vector, false if not.
    • interpolateLocal

      public Vector3f interpolateLocal(Vector3f finalVector, float mu)
      Interpolates this vector to the provided final vector, e.g if this vector is (0, 5, 10), and the final vector is (-10, 0, 10), the result (by using a mu-value of 0.5f) would be (-5, 2.5f, 10)
      Parameters:
      finalVector - the final vector to interpolate towards.
      mu - the mu value between 0.0 and 1.0 (i.e the percentage change from this vector to towards the final vector).
      Returns:
      this vector containing the interpolated values.
    • interpolateLocal

      public Vector3f interpolateLocal(Vector3f startVector, Vector3f finalVector, float mu)
      Interpolates between the provided start and end vector and stores the result in this vector.
      Parameters:
      startVector - the start vector to interpolate from.
      finalVector - the final vector to interpolate towards.
      mu - the mu value between 0.0 and 1.0 (i.e the percentage change from the start vector to towards the final vector).
      Returns:
      this vector containing the interpolated values.
    • interpolate

      public Vector3f interpolate(Vector3f startVector, Vector3f finalVector, float mu)
      Creates a new vector containing the interpolated values between the start vector and the final vector.
      Parameters:
      startVector - the start vector to interpolate from.
      finalVector - the final vector to interpolate towards.
      mu - the mu value between 0.0 and 1.0 (i.e the percentage change from the start vector to towards the final vector).
      Returns:
      a new vector containing the interpolated values.
    • equals

      public boolean equals(Object o)
      Gets whether or not this vector is equal to another object. This function returns true, if the other object is a Vector3f and if it has exactly the same x, y and z values.
      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare to equality.
      Returns:
      true if the other object is a Vector3f and has the same values as this vector, false if not.
    • equals

      public boolean equals(float x, float y, float z)
    • hashCode

      public int hashCode()
      Gets a unique* hash code for this vector, based on its values. If two vectors have the same x, y and z values, they will return the same hash code.

      * Please keep in mind that the uniqueness is not fully reliable. There is always a small chance that collisions occur (i.e two completely different vectors return the same hash code). But usually the reliability is sufficient.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code for this vector.
    • toString

      public String toString()
      Gets a String representation of this vector, for example (4.0, 5.25, 10.998)
      Overrides:
      toString in class Object
      Returns:
      a string representing the values of this vector.
    • fromString

      public Vector3f fromString(String input)