java.lang.Object
com.github.stephengold.joltjni.Vec4
All Implemented Interfaces:
Vec4Arg

public final class Vec4 extends Object implements Vec4Arg
A vector composed of 4 single-precision components, used to construct matrices.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Instantiate an all-zero vector (0,0,0,0).
    Vec4(double x, double y, double z, double w)
    Instantiate a vector with specified components.
    Vec4(float[] array)
    Instantiate a vector from the specified array.
    Vec4(float x, float y, float z, float w)
    Instantiate a vector with specified components.
    Vec4(Vec3Arg vec, float w)
    Instantiate from a 3-D vector.
    Instantiate a copy of the argument.
  • Method Summary

    Modifier and Type
    Method
    Description
    float
    dot(Vec4Arg factor)
    Return the dot product with the specified vector.
    boolean
    equals(Object other)
    Tests for exact equality with the argument, distinguishing -0 from 0.
    float
    get(int index)
    Return the specified component.
    float
    Return the 4th (W) component in single precision.
    float
    Return the first (X) component in single precision.
    float
    Return the 2nd (Y) component in single precision.
    float
    Return the 3rd (Z) component in single precision.
    int
    Return a hash code.
    void
    set(float[] array)
    Set all 4 components from the specified array.
    void
    set(float x, float y, float z, float w)
    Set all 4 components to the specified values.
    void
    set(Vec4Arg source)
    Set all 4 components from the argument.
    void
    setW(float w)
    Alter the 4th (W) component.
    void
    setX(float x)
    Alter the first (X) component.
    void
    setY(float y)
    Alter the 2nd (Y) component.
    void
    setZ(float z)
    Alter the 3rd (Z) component.
    void
    Copy the W component to all components.
    void
    Copy the X component to all components.
    void
    Copy the Y component to all components.
    void
    Copy the Z component to all components.
    static Vec4
    sReplicate(float value)
    Create a vector with all components identical.
    static Vec4
    Create a vector with all components zero.
    float[]
    Copy the components to an array.
    Return a string representation of the vector, which is unaffected.

    Methods inherited from class java.lang.Object

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

    • Vec4

      public Vec4()
      Instantiate an all-zero vector (0,0,0,0).
    • Vec4

      public Vec4(double x, double y, double z, double w)
      Instantiate a vector with specified components.
      Parameters:
      x - the desired X component
      y - the desired Y component
      z - the desired Z component
      w - the desired W component
    • Vec4

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

      public Vec4(float[] array)
      Instantiate a vector from the specified array.
      Parameters:
      array - the desired component values (not null, length≥4, unaffected)
    • Vec4

      public Vec4(Vec3Arg vec, float w)
      Instantiate from a 3-D vector.
      Parameters:
      vec - the vector to copy (not null, unaffected)
      w - the desired W component
    • Vec4

      public Vec4(Vec4Arg vec)
      Instantiate a copy of the argument.
      Parameters:
      vec - the vector to copy (not null, unaffected)
  • Method Details

    • set

      public void set(float x, float y, float z, float w)
      Set all 4 components to the specified values.
      Parameters:
      x - the desired X component
      y - the desired Y component
      z - the desired Z component
      w - the desired W component
    • set

      public void set(float[] array)
      Set all 4 components from the specified array.
      Parameters:
      array - the desired component values (not null, length≥4, unaffected)
    • set

      public void set(Vec4Arg source)
      Set all 4 components from the argument.
      Parameters:
      source - the vector to copy (not null, unaffected)
    • setW

      public void setW(float w)
      Alter the 4th (W) component.
      Parameters:
      w - the desired value
    • setX

      public void setX(float x)
      Alter the first (X) component.
      Parameters:
      x - the desired value
    • setY

      public void setY(float y)
      Alter the 2nd (Y) component.
      Parameters:
      y - the desired value
    • setZ

      public void setZ(float z)
      Alter the 3rd (Z) component.
      Parameters:
      z - the desired value
    • splatW

      public void splatW()
      Copy the W component to all components.
    • splatX

      public void splatX()
      Copy the X component to all components.
    • splatY

      public void splatY()
      Copy the Y component to all components.
    • splatZ

      public void splatZ()
      Copy the Z component to all components.
    • sReplicate

      public static Vec4 sReplicate(float value)
      Create a vector with all components identical.
      Parameters:
      value - the desired component value
      Returns:
      a new vector
    • sZero

      public static Vec4 sZero()
      Create a vector with all components zero.
      Returns:
      a new vector
    • dot

      public float dot(Vec4Arg factor)
      Return the dot product with the specified vector. The current vector is unaffected.
      Specified by:
      dot in interface Vec4Arg
      Parameters:
      factor - the vector to dot with the current one (not null, unaffected)
      Returns:
      the dot product
    • get

      public float get(int index)
      Return the specified component. The vector is unaffected.
      Specified by:
      get in interface Vec4Arg
      Parameters:
      index - 0, 1, 2, or 3
      Returns:
      the X component if index=0, the Y component if index=1, the Z component if index=2, or the W component if index=3
      Throws:
      IllegalArgumentException - if index is not 0, 1, 2, or 3
    • getW

      public float getW()
      Return the 4th (W) component in single precision. The vector is unaffected.
      Specified by:
      getW in interface Vec4Arg
      Returns:
      the component value
    • getX

      public float getX()
      Return the first (X) component in single precision. The vector is unaffected.
      Specified by:
      getX in interface Vec4Arg
      Returns:
      the component value
    • getY

      public float getY()
      Return the 2nd (Y) component in single precision. The vector is unaffected.
      Specified by:
      getY in interface Vec4Arg
      Returns:
      the component value
    • getZ

      public float getZ()
      Return the 3rd (Z) component in single precision. The vector is unaffected.
      Specified by:
      getZ in interface Vec4Arg
      Returns:
      the component value
    • toArray

      public float[] toArray()
      Copy the components to an array. The vector is unaffected.
      Specified by:
      toArray in interface Vec4Arg
      Returns:
      a new array with length=4
    • equals

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

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

      public String toString()
      Return a string representation of the vector, which is unaffected. For example, a zero vector is represented by:
       Vec4(0.0 0.0 0.0 0.0)
       
      Overrides:
      toString in class Object
      Returns:
      the string representation (not null, not empty)