Package com.jme3.math

Class Vector3f

java.lang.Object
com.jme3.math.Vector3f
All Implemented Interfaces:
Savable, Serializable, Cloneable

public final class Vector3f extends Object implements Savable, Cloneable, Serializable
A vector composed of 3 single-precision components, used to represent locations, offsets, velocities, and directions in 3-dimensional space.

Methods with names ending in "Local" modify the current instance. They are used to cut down on the creation of new instances.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Vector3f
    Shared instance of the all-NaN vector (NaN,NaN,NaN).
    static final Vector3f
    Shared instance of the all-negative-infinity vector (-Inf,-Inf,-Inf).
    static final Vector3f
    Shared instance of the all-plus-infinity vector (+Inf,+Inf,+Inf).
    static final Vector3f
    Shared instance of the +X direction (1,0,0).
    static final Vector3f
    Shared instance of the all-ones vector (1,1,1).
    static final Vector3f
    Shared instance of the +Y direction (0,1,0).
    static final Vector3f
    Shared instance of the +Z direction (0,0,1).
    float
    The first (X) component.
    float
    The 2nd (Y) component.
    float
    The 3rd (Z) component.
    static final Vector3f
    Shared instance of the all-zero vector (0,0,0).
  • Constructor Summary

    Constructors
    Constructor
    Description
    Instantiates an all-zero vector (0,0,0).
    Vector3f(float x, float y, float z)
    Instantiates a vector with specified components.
    Instantiates a copy of the argument.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(float addX, float addY, float addZ)
    Adds specified amounts to the vector's components and returns the sum as a new instance.
    Adds the argument and returns the sum as a new instance.
    add(Vector3f vec, Vector3f result)
    Adds a specified vector and returns the sum in a 3rd vector.
    addLocal(float addX, float addY, float addZ)
    Adds specified amounts to the vector's components and returns the (modified) current instance.
    Adds the argument and returns the (modified) current instance.
    float
    angleBetween(Vector3f otherVector)
    Returns the angle (in radians) between this vector and the argument, provided both vectors have length=1.
    Creates a copy.
    cross(float otherX, float otherY, float otherZ, Vector3f result)
    Calculates a cross product with specified components and returns the product in the specified vector.
    Calculates a cross product with the argument and returns the product as a new instance.
    cross(Vector3f v, Vector3f result)
    Calculates a cross product with a specified vector and returns the product in a 3rd vector.
    crossLocal(float otherX, float otherY, float otherZ)
    Right multiplies by the specified components (cross product) and returns the (modified) current instance.
    Right multiplies by the argument (cross product) and returns the (modified) current instance.
    float
    Returns the distance between this vector and the argument.
    float
    Returns the square of the distance between this vector and the argument.
    divide(float scalar)
    Divides by the argument and returns the quotient as a new instance.
    divide(float x, float y, float z)
    Divides component-wise by the specified components and returns the quotient as a new instance.
    divide(Vector3f divisor)
    Divides component-wise by the argument and returns the quotient as a new instance.
    divideLocal(float scalar)
    Divides by the argument and returns the (modified) current instance.
    divideLocal(float x, float y, float z)
    Divides component-wise by the specified components returns the (modified) current instance.
    Divides component-wise by the argument and returns the (modified) current instance.
    float
    Returns the dot (or inner) product with the argument.
    boolean
    Tests for exact equality with the argument, distinguishing -0 from 0.
    static void
     
    static void
     
    float
    get(int index)
    Returns the indexed component.
    float
    Returns the X component.
    float
    Returns the Y component.
    float
    Returns the Z component.
    int
    Returns a hash code.
    interpolateLocal(Vector3f finalVec, float changeAmount)
    Interpolates linearly between this vector and the specified vector, returning the (modified) current instance.
    interpolateLocal(Vector3f beginVec, Vector3f finalVec, float changeAmount)
    Interpolates linearly between the specified beginning and final vectors, returning the (modified) current instance.
    boolean
    isSimilar(Vector3f other, float epsilon)
    Tests for approximate equality with the specified vector, using the specified tolerance.
    boolean
    Tests for a unit vector, with 1% tolerance.
    static boolean
    Tests whether the argument is a valid vector, returning false if it's null or if any component is NaN or infinite.
    float
    Returns the length (or magnitude).
    float
    Returns the square of the length.
    Compares this vector component-wise with the argument (keeping the most positive value for each component) and returns the (modified) current instance.
    Compares this vector component-wise with the argument (keeping the most negative value for each component) and returns the (modified) current instance.
    mult(float scalar)
    Multiplies with the argument and returns the product as a new instance.
    mult(float x, float y, float z)
    Multiplies component-wise by the specified components and returns the product as a new instance.
    mult(float scalar, Vector3f product)
    Multiplies with the specified scalar and returns the product in the specified vector.
    Multiplies component-wise with the argument and returns the product as a new instance.
    mult(Vector3f vec, Vector3f store)
    Multiplies component-wise with the specified vector and returns the product in a 3rd vector.
    multLocal(float scalar)
    Multiplies by the argument and returns the (modified) current instance.
    multLocal(float x, float y, float z)
    Multiplies component-wise by the specified components and returns the (modified) current instance.
    Multiplies component-wise by the argument and returns the (modified) current instance.
    Returns the negative.
    Negates all 3 components and returns the (modified) current instance.
    Normalizes the vector to length=1 and returns the result as a new instance.
    Normalizes the vector to length=1 and returns the (modified) current instance.
    Projects onto the argument and returns the result as a new vector.
    Projects onto the argument and returns the (modified) current instance.
    void
    read(JmeImporter importer)
    De-serializes from the argument, for example when loading from a J3O file.
    scaleAdd(float scalar, Vector3f add)
    Multiplies by the specified scalar, adds the specified vector, and returns the (modified) current instance.
    scaleAdd(float scalar, Vector3f mult, Vector3f add)
    Multiplies a specified vector by a specified scalar, then adds another specified vector to it, before storing the result in the current instance.
    set(float x, float y, float z)
    Sets all 3 components to specified values.
    void
    set(int index, float value)
    Sets the indexed component.
    set(Vector3f vect)
    Copies all 3 components from the argument.
    setX(float x)
    Sets the X component.
    setY(float y)
    Sets the Y component.
    setZ(float z)
    Sets the Z component.
    subtract(float subtractX, float subtractY, float subtractZ)
    Subtracts the specified amounts from the vector's components and returns the difference as a new instance.
    Subtracts the argument and returns the difference as a new instance.
    subtract(Vector3f vec, Vector3f result)
    Subtracts the specified vector and returns the difference in a 3rd vector.
    subtractLocal(float subtractX, float subtractY, float subtractZ)
    Subtracts the specified amounts from the vector's components and returns the (modified) current instance.
    Subtracts the argument and returns the (modified) current instance.
    float[]
    toArray(float[] floats)
    Copies the vector into the argument.
    Returns a string representation of the vector, which is unaffected.
    void
    Serializes to the argument, for example when saving to a J3O file.
    Sets all 3 components to zero.

    Methods inherited from class java.lang.Object

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

    • ZERO

      public static final Vector3f ZERO
      Shared instance of the all-zero vector (0,0,0). Do not modify!
    • NAN

      public static final Vector3f NAN
      Shared instance of the all-NaN vector (NaN,NaN,NaN). Do not modify!
    • UNIT_X

      public static final Vector3f UNIT_X
      Shared instance of the +X direction (1,0,0). Do not modify!
    • UNIT_Y

      public static final Vector3f UNIT_Y
      Shared instance of the +Y direction (0,1,0). Do not modify!
    • UNIT_Z

      public static final Vector3f UNIT_Z
      Shared instance of the +Z direction (0,0,1). Do not modify!
    • UNIT_XYZ

      public static final Vector3f UNIT_XYZ
      Shared instance of the all-ones vector (1,1,1). Do not modify!
    • POSITIVE_INFINITY

      public static final Vector3f POSITIVE_INFINITY
      Shared instance of the all-plus-infinity vector (+Inf,+Inf,+Inf). Do not modify!
    • NEGATIVE_INFINITY

      public static final Vector3f NEGATIVE_INFINITY
      Shared instance of the all-negative-infinity vector (-Inf,-Inf,-Inf). Do not modify!
    • x

      public float x
      The first (X) component.
    • y

      public float y
      The 2nd (Y) component.
    • z

      public float z
      The 3rd (Z) component.
  • Constructor Details

    • Vector3f

      public Vector3f()
      Instantiates an all-zero vector (0,0,0).
    • Vector3f

      public Vector3f(float x, float y, float z)
      Instantiates a vector with specified components.
      Parameters:
      x - the desired X component
      y - the desired Y component
      z - the desired Z component
    • Vector3f

      public Vector3f(Vector3f copy)
      Instantiates a copy of the argument.
      Parameters:
      copy - the vector to copy (not null, unaffected)
  • Method Details

    • set

      public Vector3f set(float x, float y, float z)
      Sets all 3 components to specified values.
      Parameters:
      x - the desired X component
      y - the desired Y component
      z - the desired Z component
      Returns:
      the (modified) current instance (for chaining)
    • set

      public Vector3f set(Vector3f vect)
      Copies all 3 components from the argument.
      Parameters:
      vect - the Vector3f to copy (not null, unaffected)
      Returns:
      the (modified) current instance (for chaining)
    • add

      public Vector3f add(Vector3f vec)
      Adds the argument and returns the sum as a new instance. If the argument is null, null is returned. Either way, the current instance is unaffected.
      Parameters:
      vec - the vector to add (unaffected) or null for none
      Returns:
      a new Vector3f or null
    • add

      public Vector3f add(Vector3f vec, Vector3f result)
      Adds a specified vector and returns the sum in a 3rd vector. The current instance is unaffected unless it's result.
      Parameters:
      vec - the vector to add (not null, unaffected unless it's result)
      result - storage for the sum (not null)
      Returns:
      result (for chaining)
    • addLocal

      public Vector3f addLocal(Vector3f vec)
      Adds the argument and returns the (modified) current instance. If the argument is null, null is returned.
      Parameters:
      vec - the vector to add (unaffected unless it's this) or null for none
      Returns:
      the (modified) current instance or null
    • add

      public Vector3f add(float addX, float addY, float addZ)
      Adds specified amounts to the vector's components and returns the sum as a new instance. The current instance is unaffected.
      Parameters:
      addX - the amount to add to the X component
      addY - the amount to add to the Y component
      addZ - the amount to add to the Z component
      Returns:
      a new Vector3f
    • addLocal

      public Vector3f addLocal(float addX, float addY, float addZ)
      Adds specified amounts to the vector's components and returns the (modified) current instance.
      Parameters:
      addX - the amount to add to the X component
      addY - the amount to add to the Y component
      addZ - the amount to add to the Z component
      Returns:
      the (modified) current instance (for chaining)
    • scaleAdd

      public Vector3f scaleAdd(float scalar, Vector3f add)
      Multiplies by the specified scalar, adds the specified vector, and returns the (modified) current instance.

      this = scalar * this + add

      Parameters:
      scalar - the scaling factor
      add - the vector to add (not null, unaffected unless it's this)
      Returns:
      the (modified) current instance (for chaining)
    • scaleAdd

      public Vector3f scaleAdd(float scalar, Vector3f mult, Vector3f add)
      Multiplies a specified vector by a specified scalar, then adds another specified vector to it, before storing the result in the current instance.

      this = scalar * mult + add

      Parameters:
      scalar - the scaling factor
      mult - the vector to scale (not null, unaffected unless it's this)
      add - the vector to add (not null, unaffected unless it's this)
      Returns:
      the (modified) current instance (for chaining)
    • dot

      public float dot(Vector3f vec)
      Returns the dot (or inner) product with the argument. If the argument is null, 0 is returned. Either way, the current instance is unaffected.
      Parameters:
      vec - the vector to multiply (unaffected) or null for none
      Returns:
      the product or 0
    • cross

      public Vector3f cross(Vector3f v)
      Calculates a cross product with the argument and returns the product as a new instance. The current instance is unaffected.
      Parameters:
      v - the right factor (not null, unaffected)
      Returns:
      this cross v (a new Vector3f)
    • cross

      public Vector3f cross(Vector3f v, Vector3f result)
      Calculates a cross product with a specified vector and returns the product in a 3rd vector. The current instance is unaffected unless it's result.
      Parameters:
      v - the right factor (not null, unaffected unless it's result)
      result - storage for the product, or null for a new Vector3f
      Returns:
      this cross v (either result or a new Vector3f)
    • cross

      public Vector3f cross(float otherX, float otherY, float otherZ, Vector3f result)
      Calculates a cross product with specified components and returns the product in the specified vector. The current instance is unaffected unless it's result.
      Parameters:
      otherX - the X component of the right factor
      otherY - the Y component of the right factor
      otherZ - the Z component of the right factor
      result - storage for the product, or null for a new Vector3f
      Returns:
      this cross (X,Y,Z) (either result or a new Vector3f)
    • crossLocal

      public Vector3f crossLocal(Vector3f v)
      Right multiplies by the argument (cross product) and returns the (modified) current instance.
      Parameters:
      v - the right factor (not null, unaffected unless it's this)
      Returns:
      the (modified) current instance (for chaining)
    • crossLocal

      public Vector3f crossLocal(float otherX, float otherY, float otherZ)
      Right multiplies by the specified components (cross product) and returns the (modified) current instance.
      Parameters:
      otherX - the X component of the right factor
      otherY - the Y component of the right factor
      otherZ - the Z component of the right factor
      Returns:
      the (modified) current instance (for chaining)
    • project

      public Vector3f project(Vector3f other)
      Projects onto the argument and returns the result as a new vector. The current instance is unaffected.
      Parameters:
      other - the vector to project onto (not null, unaffected)
      Returns:
      a new Vector3f
    • projectLocal

      public Vector3f projectLocal(Vector3f other)
      Projects onto the argument and returns the (modified) current instance.
      Parameters:
      other - the vector to project onto (not null, unaffected unless it's this)
      Returns:
      the (modified) current instance (for chaining)
    • isUnitVector

      public boolean isUnitVector()
      Tests for a unit vector, with 1% tolerance. The current instance is unaffected.
      Returns:
      true if the current vector's length is between 0.99 and 1.01 inclusive, otherwise false
    • length

      public float length()
      Returns the length (or magnitude). The current instance is unaffected.
      Returns:
      the root-sum of the squared components (not negative)
    • lengthSquared

      public float lengthSquared()
      Returns the square of the length. The current instance is unaffected.
      Returns:
      the sum of the squared components (not negative)
    • distanceSquared

      public float distanceSquared(Vector3f v)
      Returns the square of the distance between this vector and the argument. The current instance is unaffected.
      Parameters:
      v - the vector to compare (not null, unaffected)
      Returns:
      the square of the Euclidean distance (not negative)
    • distance

      public float distance(Vector3f v)
      Returns the distance between this vector and the argument. The current instance is unaffected.
      Parameters:
      v - the vector to compare (not null, unaffected)
      Returns:
      the Euclidean distance (not negative)
    • mult

      public Vector3f mult(float scalar)
      Multiplies with the argument and returns the product as a new instance. The current instance is unaffected.
      Parameters:
      scalar - the scaling factor
      Returns:
      a new Vector3f
    • mult

      public Vector3f mult(float scalar, Vector3f product)
      Multiplies with the specified scalar and returns the product in the specified vector. The current instance is unaffected, unless it's product.
      Parameters:
      scalar - the scaling factor
      product - storage for the product, or null for a new Vector3f
      Returns:
      either product or a new Vector3f
    • multLocal

      public Vector3f multLocal(float scalar)
      Multiplies by the argument and returns the (modified) current instance.
      Parameters:
      scalar - the scaling factor
      Returns:
      the (modified) current instance (for chaining)
    • multLocal

      public Vector3f multLocal(Vector3f vec)
      Multiplies component-wise by the argument and returns the (modified) current instance. If the argument is null, null is returned.
      Parameters:
      vec - the scale vector (unaffected unless it's this) or null for none
      Returns:
      the (modified) current instance (for chaining) or null
    • multLocal

      public Vector3f multLocal(float x, float y, float z)
      Multiplies component-wise by the specified components and returns the (modified) current instance.
      Parameters:
      x - the scale factor for the X component
      y - the scale factor for the Y component
      z - the scale factor for the Z component
      Returns:
      the (modified) current instance (for chaining)
    • mult

      public Vector3f mult(Vector3f vec)
      Multiplies component-wise with the argument and returns the product as a new instance. If the argument is null, null is returned. Either way, the current instance is unaffected.
      Parameters:
      vec - the scale vector (unaffected) or null for none
      Returns:
      a new Vector3f or null
    • mult

      public Vector3f mult(float x, float y, float z)
      Multiplies component-wise by the specified components and returns the product as a new instance. The current instance is unaffected.
      Parameters:
      x - the scale factor for the X component
      y - the scale factor for the Y component
      z - the scale factor for the Z component
      Returns:
      a new Vector3f
    • mult

      public Vector3f mult(Vector3f vec, Vector3f store)
      Multiplies component-wise with the specified vector and returns the product in a 3rd vector. If the argument is null, null is returned. Either way, the current instance is unaffected, unless it's store.
      Parameters:
      vec - the scale vector (unaffected unless it's store) or null for none
      store - storage for the product, or null for a new Vector3f
      Returns:
      either store or a new Vector3f or null
    • divide

      public Vector3f divide(float scalar)
      Divides by the argument and returns the quotient as a new instance. The current instance is unaffected.
      Parameters:
      scalar - the divisor
      Returns:
      a new Vector3f
    • divideLocal

      public Vector3f divideLocal(float scalar)
      Divides by the argument and returns the (modified) current instance.
      Parameters:
      scalar - the divisor
      Returns:
      the (modified) current instance (for chaining)
    • divideLocal

      public Vector3f divideLocal(float x, float y, float z)
      Divides component-wise by the specified components returns the (modified) current instance.
      Parameters:
      x - the divisor for the X component
      y - the divisor for the Y component
      z - the divisor for the Z component
      Returns:
      the (modified) current instance (for chaining)
    • divide

      public Vector3f divide(Vector3f divisor)
      Divides component-wise by the argument and returns the quotient as a new instance. The current instance is unaffected.
      Parameters:
      divisor - the divisor (not null, unaffected)
      Returns:
      a new Vector3f
    • divide

      public Vector3f divide(float x, float y, float z)
      Divides component-wise by the specified components and returns the quotient as a new instance. The current instance is unaffected.
      Parameters:
      x - the divisor for the X component
      y - the divisor for the Y component
      z - the divisor for the Z component
      Returns:
      a new Vector3f
    • divideLocal

      public Vector3f divideLocal(Vector3f divisor)
      Divides component-wise by the argument and returns the (modified) current instance.
      Parameters:
      divisor - the divisor (not null, unaffected unless it's this)
      Returns:
      the (modified) current instance (for chaining)
    • negate

      public Vector3f negate()
      Returns the negative. The current instance is unaffected.
      Returns:
      a new Vector3f
    • negateLocal

      public Vector3f negateLocal()
      Negates all 3 components and returns the (modified) current instance.
      Returns:
      the (modified) current instance (for chaining)
    • subtract

      public Vector3f subtract(Vector3f vec)
      Subtracts the argument and returns the difference as a new instance. The current instance is unaffected.
      Parameters:
      vec - the vector to subtract (not null, unaffected)
      Returns:
      a new Vector3f
    • subtractLocal

      public Vector3f subtractLocal(Vector3f vec)
      Subtracts the argument and returns the (modified) current instance. If the argument is null, null is returned.
      Parameters:
      vec - the vector to subtract (unaffected unless it's this) or null for none
      Returns:
      the (modified) current instance or null
    • subtract

      public Vector3f subtract(Vector3f vec, Vector3f result)
      Subtracts the specified vector and returns the difference in a 3rd vector. The current instance is unaffected unless it's result.
      Parameters:
      vec - the vector to subtract (not null, unaffected unless it's result)
      result - storage for the difference, or null for a new Vector3f
      Returns:
      either result or a new Vector3f
    • subtract

      public Vector3f subtract(float subtractX, float subtractY, float subtractZ)
      Subtracts the specified amounts from the vector's components and returns the difference as a new instance. The current instance is unaffected.
      Parameters:
      subtractX - the amount to subtract from the X component
      subtractY - the amount to subtract from the Y component
      subtractZ - the amount to subtract from the Z component
      Returns:
      a new Vector3f
    • subtractLocal

      public Vector3f subtractLocal(float subtractX, float subtractY, float subtractZ)
      Subtracts the specified amounts from the vector's components and returns the (modified) current instance.
      Parameters:
      subtractX - the amount to subtract from the X component
      subtractY - the amount to subtract from the Y component
      subtractZ - the amount to subtract from the Z component
      Returns:
      the (modified) current instance (for chaining)
    • normalize

      public Vector3f normalize()
      Normalizes the vector to length=1 and returns the result as a new instance. If the vector has length=0, a clone is returned. Either way, the current instance is unaffected.
      Returns:
      a new Vector3f
    • normalizeLocal

      public Vector3f normalizeLocal()
      Normalizes the vector to length=1 and returns the (modified) current instance. If the vector has length=0, it's unchanged.
      Returns:
      the (modified) current instance (for chaining)
    • maxLocal

      public Vector3f maxLocal(Vector3f other)
      Compares this vector component-wise with the argument (keeping the most positive value for each component) and returns the (modified) current instance.
      Parameters:
      other - the vector to compare (not null, unaffected)
      Returns:
      the (modified) current instance (for chaining)
    • minLocal

      public Vector3f minLocal(Vector3f other)
      Compares this vector component-wise with the argument (keeping the most negative value for each component) and returns the (modified) current instance.
      Parameters:
      other - the vector to compare (not null, unaffected)
      Returns:
      the (modified) current instance (for chaining)
    • zero

      public Vector3f zero()
      Sets all 3 components to zero.
      Returns:
      the (modified) current instance (for chaining)
    • angleBetween

      public float angleBetween(Vector3f otherVector)
      Returns the angle (in radians) between this vector and the argument, provided both vectors have length=1. The current instance is unaffected.
      Parameters:
      otherVector - a unit vector to compare (not null, unaffected)
      Returns:
      the angle (in radians, not negative)
    • interpolateLocal

      public Vector3f interpolateLocal(Vector3f finalVec, float changeAmount)
      Interpolates linearly between this vector and the specified vector, returning the (modified) current instance.

      this = (1 - changeAmount) * this + changeAmount * finalVec

      Parameters:
      finalVec - the desired value when changeAmount=1 (not null, unaffected unless it's this)
      changeAmount - the fractional change amount
      Returns:
      the (modified) current instance (for chaining)
    • interpolateLocal

      public Vector3f interpolateLocal(Vector3f beginVec, Vector3f finalVec, float changeAmount)
      Interpolates linearly between the specified beginning and final vectors, returning the (modified) current instance.

      this = (1 - changeAmount) * beginVec + changeAmount * finalVec

      Parameters:
      beginVec - the desired value when changeAmount=0 (not null, unaffected unless it's this)
      finalVec - the desired value when changeAmount=1 (not null, unaffected unless it's this)
      changeAmount - the fractional change amount
      Returns:
      the (modified) current instance (for chaining)
    • isValidVector

      public static boolean isValidVector(Vector3f vector)
      Tests whether the argument is a valid vector, returning false if it's null or if any component is NaN or infinite.
      Parameters:
      vector - the vector to test (unaffected)
      Returns:
      true if non-null and finite, otherwise false
    • generateOrthonormalBasis

      public static void generateOrthonormalBasis(Vector3f u, Vector3f v, Vector3f w)
    • generateComplementBasis

      public static void generateComplementBasis(Vector3f u, Vector3f v, Vector3f w)
    • clone

      public Vector3f clone()
      Creates a copy. The current instance is unaffected.
      Overrides:
      clone in class Object
      Returns:
      a new instance, equivalent to the current one
    • toArray

      public float[] toArray(float[] floats)
      Copies the vector into the argument. The current instance is unaffected.
      Parameters:
      floats - storage for the components (must have length≥3) or null for a new float[3]
      Returns:
      an array containing the X, Y, and Z components in that order (either floats or a new float[3])
    • equals

      public boolean equals(Object o)
      Tests for exact equality with the argument, distinguishing -0 from 0. If o is null, false is returned. Either way, the current instance is unaffected.
      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare (may be null, unaffected)
      Returns:
      true if this and o have identical values, otherwise false
    • isSimilar

      public boolean isSimilar(Vector3f other, float epsilon)
      Tests for approximate equality with the specified vector, using the specified tolerance. If other is null, false is returned. Either way, the current instance is unaffected.
      Parameters:
      other - the vector to compare (unaffected) or null for none
      epsilon - the tolerance for each component
      Returns:
      true if all 3 components are within tolerance, otherwise false
    • hashCode

      public int hashCode()
      Returns a hash code. If two vectors have identical values, they will have the same hash code. The current instance is unaffected.
      Overrides:
      hashCode in class Object
      Returns:
      a 32-bit value for use in hashing
    • toString

      public String toString()
      Returns a string representation of the vector, which is unaffected. For example, the +X direction vector is represented by:
       (1.0, 0.0, 0.0)
       
      Overrides:
      toString in class Object
      Returns:
      the string representation (not null, not empty)
    • write

      public void write(JmeExporter e) throws IOException
      Serializes to the argument, for example when saving to a J3O file. The current instance is unaffected.
      Specified by:
      write in interface Savable
      Parameters:
      e - the exporter to use (not null)
      Throws:
      IOException - from the exporter
    • read

      public void read(JmeImporter importer) throws IOException
      De-serializes from the argument, for example when loading from a J3O file.
      Specified by:
      read in interface Savable
      Parameters:
      importer - the importer to use (not null)
      Throws:
      IOException - from the importer
    • getX

      public float getX()
      Returns the X component. The vector is unaffected.
      Returns:
      the value of the x component
    • setX

      public Vector3f setX(float x)
      Sets the X component.
      Parameters:
      x - the desired value
      Returns:
      the (modified) current instance (for chaining)
    • getY

      public float getY()
      Returns the Y component. The vector is unaffected.
      Returns:
      the value of the y component
    • setY

      public Vector3f setY(float y)
      Sets the Y component.
      Parameters:
      y - the desired value
      Returns:
      the (modified) current instance (for chaining)
    • getZ

      public float getZ()
      Returns the Z component. The vector is unaffected.
      Returns:
      z the value of the z component
    • setZ

      public Vector3f setZ(float z)
      Sets the Z component.
      Parameters:
      z - the desired value
      Returns:
      the (modified) current instance (for chaining)
    • get

      public float get(int index)
      Returns the indexed component. The vector is unaffected.
      Parameters:
      index - 0, 1, or 2
      Returns:
      the X component if index=0, the Y component if index=1, or the Z component if index=2
      Throws:
      IllegalArgumentException - if index is not 0, 1, or 2
    • set

      public void set(int index, float value)
      Sets the indexed component.
      Parameters:
      index - which component to set: 0 → the X component, 1 → the Y component, 2 → the Z component
      value - the desired component value
      Throws:
      IllegalArgumentException - if index is not 0, 1, or 2