Package org.joml

Class Matrix2f

java.lang.Object
org.joml.Matrix2f
All Implemented Interfaces:
Externalizable, Serializable, Cloneable, Matrix2fc

public class Matrix2f extends Object implements Externalizable, Cloneable, Matrix2fc
Contains the definition of a 2x2 matrix of floats, and associated functions to transform it. The matrix is column-major to match OpenGL's interpretation, and it looks like this:

m00 m10
m01 m11

Author:
Joseph Burton
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    float
     
    float
     
    float
     
    float
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new Matrix2f and set it to identity.
    Matrix2f(float m00, float m01, float m10, float m11)
    Create a new 2x2 matrix using the supplied float values.
    Create a new Matrix2f by reading its 4 float components from the given FloatBuffer at the buffer's current position.
    Create a new Matrix2f and make it a copy of the given matrix.
    Create a new Matrix2f and make it a copy of the upper left 2x2 of the given Matrix3fc.
    Create a new Matrix2f and initialize its two columns using the supplied vectors.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(Matrix2fc other)
    Component-wise add this and other.
    add(Matrix2fc other, Matrix2f dest)
    Component-wise add this and other and store the result in dest.
     
    float
    Return the determinant of this matrix.
    boolean
     
    boolean
    equals(Matrix2fc m, float delta)
    Compare the matrix elements of this matrix with the given matrix using the given delta and return whether all of them are equal within a maximum difference of delta.
    float[]
    get(float[] arr)
    Store this matrix into the supplied float array in column-major order.
    float[]
    get(float[] arr, int offset)
    Store this matrix into the supplied float array in column-major order at the given offset.
    float
    get(int column, int row)
    Get the matrix element value at the given column and row.
    com.google.gwt.typedarrays.shared.Float32Array
    get(int index, com.google.gwt.typedarrays.shared.Float32Array buffer)
    Store this matrix in column-major order into the supplied Float32Array at the given index.
    get(int index, ByteBuffer buffer)
    Store this matrix in column-major order into the supplied ByteBuffer starting at the specified absolute buffer position/index.
    get(int index, FloatBuffer buffer)
    Store this matrix in column-major order into the supplied FloatBuffer starting at the specified absolute buffer position/index.
    com.google.gwt.typedarrays.shared.Float32Array
    get(com.google.gwt.typedarrays.shared.Float32Array buffer)
    Store this matrix in column-major order into the supplied Float32Array.
    get(ByteBuffer buffer)
    Store this matrix in column-major order into the supplied ByteBuffer at the current buffer position.
    get(FloatBuffer buffer)
    Store this matrix in column-major order into the supplied FloatBuffer at the current buffer position.
    get(Matrix2f dest)
    Get the current values of this matrix and store them into dest.
    get(Matrix3f dest)
    Get the current values of this matrix and store them as the rotational component of dest.
    Get the current values of this matrix and store them as the rotational component of dest.
    getColumn(int column, Vector2f dest)
    Get the column at the given column index, starting with 0.
    float
    Get the angle of the rotation component of this matrix.
    getRow(int row, Vector2f dest)
    Get the row at the given row index, starting with 0.
    Get the scaling factors of this matrix for the three base axes.
    getToAddress(long address)
    Store this matrix in column-major order at the given off-heap address.
    getTransposed(int index, ByteBuffer buffer)
    Store the transpose of this matrix in column-major order into the supplied ByteBuffer starting at the specified absolute buffer position/index.
    getTransposed(int index, FloatBuffer buffer)
    Store the transpose of this matrix in column-major order into the supplied FloatBuffer starting at the specified absolute buffer position/index.
    Store the transpose of this matrix in column-major order into the supplied ByteBuffer at the current buffer position.
    Store the transpose of this matrix in column-major order into the supplied FloatBuffer at the current buffer position.
    int
     
    Set this matrix to the identity.
    Invert this matrix.
    Invert the this matrix and store the result in dest.
    boolean
    Determine whether all matrix elements are finite floating-point values, that is, they are not NaN and not infinity.
    lerp(Matrix2fc other, float t)
    Linearly interpolate this and other using the given interpolation factor t and store the result in this.
    lerp(Matrix2fc other, float t, Matrix2f dest)
    Linearly interpolate this and other using the given interpolation factor t and store the result in dest.
    float
    m00()
    Return the value of the matrix element at column 0 and row 0.
    m00(float m00)
    Set the value of the matrix element at column 0 and row 0.
    float
    m01()
    Return the value of the matrix element at column 0 and row 1.
    m01(float m01)
    Set the value of the matrix element at column 0 and row 1.
    float
    m10()
    Return the value of the matrix element at column 1 and row 0.
    m10(float m10)
    Set the value of the matrix element at column 1 and row 0.
    float
    m11()
    Return the value of the matrix element at column 1 and row 1.
    m11(float m11)
    Set the value of the matrix element at column 1 and row 1.
    mul(Matrix2fc right)
    Multiply this matrix by the supplied right matrix.
    mul(Matrix2fc right, Matrix2f dest)
    Multiply this matrix by the supplied right matrix and store the result in dest.
    Component-wise multiply this by other.
    Component-wise multiply this by other and store the result in dest.
    Pre-multiply this matrix by the supplied left matrix and store the result in this.
    Pre-multiply this matrix by the supplied left matrix and store the result in dest.
    Set this matrix to its own normal matrix.
    Compute a normal matrix from this matrix and store it into dest.
    Obtain the direction of +X before the transformation represented by this orthogonal matrix is applied.
    Obtain the direction of +Y before the transformation represented by this orthogonal matrix is applied.
    Obtain the direction of +X before the transformation represented by this matrix is applied.
    Obtain the direction of +Y before the transformation represented by this matrix is applied.
    void
     
    rotate(float angle)
    Apply rotation about the origin to this matrix by rotating the given amount of radians.
    rotate(float angle, Matrix2f dest)
    Apply rotation to this matrix by rotating the given amount of radians and store the result in dest.
    rotateLocal(float angle)
    Pre-multiply a rotation to this matrix by rotating the given amount of radians about the origin.
    rotateLocal(float angle, Matrix2f dest)
    Pre-multiply a rotation to this matrix by rotating the given amount of radians and store the result in dest.
    rotation(float angle)
    Set this matrix to a rotation matrix which rotates the given radians about the origin.
    scale(float xy)
    Apply scaling to this matrix by uniformly scaling all base axes by the given xy factor.
    scale(float x, float y)
    Apply scaling to this matrix by scaling the base axes by the given x and y factors.
    scale(float x, float y, Matrix2f dest)
    Apply scaling to this matrix by scaling the base axes by the given x and y factors and store the result in dest.
    scale(float xy, Matrix2f dest)
    Apply scaling to this matrix by uniformly scaling all base axes by the given xy factor and store the result in dest.
    Apply scaling to this matrix by scaling the base axes by the given xy.x and xy.y factors, respectively.
    Apply scaling to this matrix by scaling the base axes by the given xy.x and xy.y factors, respectively and store the result in dest.
    scaleLocal(float x, float y)
    Pre-multiply scaling to this matrix by scaling the base axes by the given x and y factors.
    scaleLocal(float x, float y, Matrix2f dest)
    Pre-multiply scaling to this matrix by scaling the base axes by the given x and y factors and store the result in dest.
    scaling(float factor)
    Set this matrix to be a simple scale matrix, which scales all axes uniformly by the given factor.
    scaling(float x, float y)
    Set this matrix to be a simple scale matrix.
    Set this matrix to be a simple scale matrix which scales the base axes by xy.x and xy.y respectively.
    set(float[] m)
    Set the values in this matrix based on the supplied float array.
    set(float m00, float m01, float m10, float m11)
    Set the values within this matrix to the supplied float values.
    set(int column, int row, float value)
    Set the matrix element at the given column and row to the specified value.
    set(int index, ByteBuffer buffer)
    Set the values of this matrix by reading 4 float values from the given ByteBuffer in column-major order, starting at the specified absolute buffer position/index.
    set(int index, FloatBuffer buffer)
    Set the values of this matrix by reading 4 float values from the given FloatBuffer in column-major order, starting at the specified absolute buffer position/index.
    set(ByteBuffer buffer)
    Set the values of this matrix by reading 4 float values from the given ByteBuffer in column-major order, starting at its current position.
    set(FloatBuffer buffer)
    Set the values of this matrix by reading 4 float values from the given FloatBuffer in column-major order, starting at its current position.
    Set the elements of this matrix to the ones in m.
    Set the elements of this matrix to the upper left 2x2 of the given Matrix3fc.
    Set the elements of this matrix to the left 2x2 submatrix of m.
    set(Vector2fc col0, Vector2fc col1)
    Set the two columns of this matrix to the supplied vectors, respectively.
    setColumn(int column, float x, float y)
    Set the column at the given column index, starting with 0.
    setColumn(int column, Vector2fc src)
    Set the column at the given column index, starting with 0.
    setFromAddress(long address)
    Set the values of this matrix by reading 4 float values from off-heap memory in column-major order, starting at the given address.
    setRow(int row, float x, float y)
    Set the row at the given row index, starting with 0.
    setRow(int row, Vector2fc src)
    Set the row at the given row index, starting with 0.
    sub(Matrix2fc subtrahend)
    Component-wise subtract subtrahend from this.
    sub(Matrix2fc other, Matrix2f dest)
    Component-wise subtract subtrahend from this and store the result in dest.
    swap(Matrix2f other)
    Exchange the values of this matrix with the given other matrix.
    Return a string representation of this matrix.
    Return a string representation of this matrix by formatting the matrix elements with the given NumberFormat.
    transform(float x, float y, Vector2f dest)
    Transform the vector (x, y) by this matrix and store the result in dest.
    Transform the given vector by this matrix.
    Transform the given vector by this matrix and store the result in dest.
    transformTranspose(float x, float y, Vector2f dest)
    Transform the vector (x, y) by the transpose of this matrix and store the result in dest.
    Transform the given vector by the transpose of this matrix.
    Transform the given vector by the transpose of this matrix and store the result in dest.
    Transpose this matrix.
    Transpose this matrix and store the result in dest.
    void
     
    Set all values within this matrix to zero.

    Methods inherited from class java.lang.Object

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

    • m00

      public float m00
    • m01

      public float m01
    • m10

      public float m10
    • m11

      public float m11
  • Constructor Details

    • Matrix2f

      public Matrix2f()
      Create a new Matrix2f and set it to identity.
    • Matrix2f

      public Matrix2f(Matrix2fc mat)
      Create a new Matrix2f and make it a copy of the given matrix.
      Parameters:
      mat - the Matrix2fc to copy the values from
    • Matrix2f

      public Matrix2f(Matrix3fc mat)
      Create a new Matrix2f and make it a copy of the upper left 2x2 of the given Matrix3fc.
      Parameters:
      mat - the Matrix3fc to copy the values from
    • Matrix2f

      public Matrix2f(float m00, float m01, float m10, float m11)
      Create a new 2x2 matrix using the supplied float values. The order of the parameter is column-major, so the first two parameters specify the two elements of the first column.
      Parameters:
      m00 - the value of m00
      m01 - the value of m01
      m10 - the value of m10
      m11 - the value of m11
    • Matrix2f

      public Matrix2f(FloatBuffer buffer)
      Create a new Matrix2f by reading its 4 float components from the given FloatBuffer at the buffer's current position.

      That FloatBuffer is expected to hold the values in column-major order.

      The buffer's position will not be changed by this method.

      Parameters:
      buffer - the FloatBuffer to read the matrix values from
    • Matrix2f

      public Matrix2f(Vector2fc col0, Vector2fc col1)
      Create a new Matrix2f and initialize its two columns using the supplied vectors.
      Parameters:
      col0 - the first column
      col1 - the second column
  • Method Details

    • m00

      public float m00()
      Description copied from interface: Matrix2fc
      Return the value of the matrix element at column 0 and row 0.
      Specified by:
      m00 in interface Matrix2fc
      Returns:
      the value of the matrix element
    • m01

      public float m01()
      Description copied from interface: Matrix2fc
      Return the value of the matrix element at column 0 and row 1.
      Specified by:
      m01 in interface Matrix2fc
      Returns:
      the value of the matrix element
    • m10

      public float m10()
      Description copied from interface: Matrix2fc
      Return the value of the matrix element at column 1 and row 0.
      Specified by:
      m10 in interface Matrix2fc
      Returns:
      the value of the matrix element
    • m11

      public float m11()
      Description copied from interface: Matrix2fc
      Return the value of the matrix element at column 1 and row 1.
      Specified by:
      m11 in interface Matrix2fc
      Returns:
      the value of the matrix element
    • m00

      public Matrix2f m00(float m00)
      Set the value of the matrix element at column 0 and row 0.
      Parameters:
      m00 - the new value
      Returns:
      this
    • m01

      public Matrix2f m01(float m01)
      Set the value of the matrix element at column 0 and row 1.
      Parameters:
      m01 - the new value
      Returns:
      this
    • m10

      public Matrix2f m10(float m10)
      Set the value of the matrix element at column 1 and row 0.
      Parameters:
      m10 - the new value
      Returns:
      this
    • m11

      public Matrix2f m11(float m11)
      Set the value of the matrix element at column 1 and row 1.
      Parameters:
      m11 - the new value
      Returns:
      this
    • set

      public Matrix2f set(Matrix2fc m)
      Set the elements of this matrix to the ones in m.
      Parameters:
      m - the matrix to copy the elements from
      Returns:
      this
    • set

      public Matrix2f set(Matrix3x2fc m)
      Set the elements of this matrix to the left 2x2 submatrix of m.
      Parameters:
      m - the matrix to copy the elements from
      Returns:
      this
    • set

      public Matrix2f set(Matrix3fc m)
      Set the elements of this matrix to the upper left 2x2 of the given Matrix3fc.
      Parameters:
      m - the Matrix3fc to copy the values from
      Returns:
      this
    • mul

      public Matrix2f mul(Matrix2fc right)
      Multiply this matrix by the supplied right matrix.

      If M is this matrix and R the right matrix, then the new matrix will be M * R. So when transforming a vector v with the new matrix by using M * R * v, the transformation of the right matrix will be applied first!

      Parameters:
      right - the right operand of the matrix multiplication
      Returns:
      this
    • mul

      public Matrix2f mul(Matrix2fc right, Matrix2f dest)
      Description copied from interface: Matrix2fc
      Multiply this matrix by the supplied right matrix and store the result in dest.

      If M is this matrix and R the right matrix, then the new matrix will be M * R. So when transforming a vector v with the new matrix by using M * R * v, the transformation of the right matrix will be applied first!

      Specified by:
      mul in interface Matrix2fc
      Parameters:
      right - the right operand of the matrix multiplication
      dest - will hold the result
      Returns:
      dest
    • mulLocal

      public Matrix2f mulLocal(Matrix2fc left)
      Pre-multiply this matrix by the supplied left matrix and store the result in this.

      If M is this matrix and L the left matrix, then the new matrix will be L * M. So when transforming a vector v with the new matrix by using L * M * v, the transformation of this matrix will be applied first!

      Parameters:
      left - the left operand of the matrix multiplication
      Returns:
      this
    • mulLocal

      public Matrix2f mulLocal(Matrix2fc left, Matrix2f dest)
      Description copied from interface: Matrix2fc
      Pre-multiply this matrix by the supplied left matrix and store the result in dest.

      If M is this matrix and L the left matrix, then the new matrix will be L * M. So when transforming a vector v with the new matrix by using L * M * v, the transformation of this matrix will be applied first!

      Specified by:
      mulLocal in interface Matrix2fc
      Parameters:
      left - the left operand of the matrix multiplication
      dest - the destination matrix, which will hold the result
      Returns:
      dest
    • set

      public Matrix2f set(float m00, float m01, float m10, float m11)
      Set the values within this matrix to the supplied float values. The result looks like this:

      m00, m10
      m01, m11

      Parameters:
      m00 - the new value of m00
      m01 - the new value of m01
      m10 - the new value of m10
      m11 - the new value of m11
      Returns:
      this
    • set

      public Matrix2f set(float[] m)
      Set the values in this matrix based on the supplied float array. The result looks like this:

      0, 2
      1, 3
      This method only uses the first 4 values, all others are ignored.

      Parameters:
      m - the array to read the matrix values from
      Returns:
      this
    • set

      public Matrix2f set(Vector2fc col0, Vector2fc col1)
      Set the two columns of this matrix to the supplied vectors, respectively.
      Parameters:
      col0 - the first column
      col1 - the second column
      Returns:
      this
    • determinant

      public float determinant()
      Description copied from interface: Matrix2fc
      Return the determinant of this matrix.
      Specified by:
      determinant in interface Matrix2fc
      Returns:
      the determinant
    • invert

      public Matrix2f invert()
      Invert this matrix.
      Returns:
      this
    • invert

      public Matrix2f invert(Matrix2f dest)
      Description copied from interface: Matrix2fc
      Invert the this matrix and store the result in dest.
      Specified by:
      invert in interface Matrix2fc
      Parameters:
      dest - will hold the result
      Returns:
      dest
    • transpose

      public Matrix2f transpose()
      Transpose this matrix.
      Returns:
      this
    • transpose

      public Matrix2f transpose(Matrix2f dest)
      Description copied from interface: Matrix2fc
      Transpose this matrix and store the result in dest.
      Specified by:
      transpose in interface Matrix2fc
      Parameters:
      dest - will hold the result
      Returns:
      dest
    • toString

      public String toString()
      Return a string representation of this matrix.

      This method creates a new DecimalFormat on every invocation with the format string "0.000E0;-".

      Overrides:
      toString in class Object
      Returns:
      the string representation
    • toString

      public String toString(NumberFormat formatter)
      Return a string representation of this matrix by formatting the matrix elements with the given NumberFormat.
      Parameters:
      formatter - the NumberFormat used to format the matrix values with
      Returns:
      the string representation
    • get

      public Matrix2f get(Matrix2f dest)
      Get the current values of this matrix and store them into dest.

      This is the reverse method of set(Matrix2fc) and allows to obtain intermediate calculation results when chaining multiple transformations.

      Specified by:
      get in interface Matrix2fc
      Parameters:
      dest - the destination matrix
      Returns:
      the passed in destination
      See Also:
    • get

      public Matrix3x2f get(Matrix3x2f dest)
      Description copied from interface: Matrix2fc
      Get the current values of this matrix and store them as the rotational component of dest. All other values of dest will be set to 0.
      Specified by:
      get in interface Matrix2fc
      Parameters:
      dest - the destination matrix
      Returns:
      the passed in destination
      See Also:
    • get

      public Matrix3f get(Matrix3f dest)
      Description copied from interface: Matrix2fc
      Get the current values of this matrix and store them as the rotational component of dest. All other values of dest will be set to identity.
      Specified by:
      get in interface Matrix2fc
      Parameters:
      dest - the destination matrix
      Returns:
      the passed in destination
      See Also:
    • getRotation

      public float getRotation()
      Description copied from interface: Matrix2fc
      Get the angle of the rotation component of this matrix.

      This method assumes that there is a valid rotation to be returned, i.e. that atan2(-m10, m00) == atan2(m01, m11).

      Specified by:
      getRotation in interface Matrix2fc
      Returns:
      the angle
    • get

      public com.google.gwt.typedarrays.shared.Float32Array get(com.google.gwt.typedarrays.shared.Float32Array buffer)
      Description copied from interface: Matrix2fc
      Store this matrix in column-major order into the supplied Float32Array.
      Specified by:
      get in interface Matrix2fc
      Parameters:
      buffer - will receive the values of this matrix in column-major order
      Returns:
      the passed in buffer
    • get

      public com.google.gwt.typedarrays.shared.Float32Array get(int index, com.google.gwt.typedarrays.shared.Float32Array buffer)
      Description copied from interface: Matrix2fc
      Store this matrix in column-major order into the supplied Float32Array at the given index.
      Specified by:
      get in interface Matrix2fc
      Parameters:
      index - the index at which to store this matrix in the supplied Float32Array
      buffer - will receive the values of this matrix in column-major order
      Returns:
      the passed in buffer
    • get

      public FloatBuffer get(FloatBuffer buffer)
      Description copied from interface: Matrix2fc
      Store this matrix in column-major order into the supplied FloatBuffer at the current buffer position.

      This method will not increment the position of the given FloatBuffer.

      In order to specify the offset into the FloatBuffer at which the matrix is stored, use Matrix2fc.get(int, FloatBuffer), taking the absolute position as parameter.

      Specified by:
      get in interface Matrix2fc
      Parameters:
      buffer - will receive the values of this matrix in column-major order at its current position
      Returns:
      the passed in buffer
      See Also:
    • get

      public FloatBuffer get(int index, FloatBuffer buffer)
      Description copied from interface: Matrix2fc
      Store this matrix in column-major order into the supplied FloatBuffer starting at the specified absolute buffer position/index.

      This method will not increment the position of the given FloatBuffer.

      Specified by:
      get in interface Matrix2fc
      Parameters:
      index - the absolute position into the FloatBuffer
      buffer - will receive the values of this matrix in column-major order
      Returns:
      the passed in buffer
    • get

      public ByteBuffer get(ByteBuffer buffer)
      Description copied from interface: Matrix2fc
      Store this matrix in column-major order into the supplied ByteBuffer at the current buffer position.

      This method will not increment the position of the given ByteBuffer.

      In order to specify the offset into the ByteBuffer at which the matrix is stored, use Matrix2fc.get(int, ByteBuffer), taking the absolute position as parameter.

      Specified by:
      get in interface Matrix2fc
      Parameters:
      buffer - will receive the values of this matrix in column-major order at its current position
      Returns:
      the passed in buffer
      See Also:
    • get

      public ByteBuffer get(int index, ByteBuffer buffer)
      Description copied from interface: Matrix2fc
      Store this matrix in column-major order into the supplied ByteBuffer starting at the specified absolute buffer position/index.

      This method will not increment the position of the given ByteBuffer.

      Specified by:
      get in interface Matrix2fc
      Parameters:
      index - the absolute position into the ByteBuffer
      buffer - will receive the values of this matrix in column-major order
      Returns:
      the passed in buffer
    • getTransposed

      public FloatBuffer getTransposed(FloatBuffer buffer)
      Description copied from interface: Matrix2fc
      Store the transpose of this matrix in column-major order into the supplied FloatBuffer at the current buffer position.

      This method will not increment the position of the given FloatBuffer.

      In order to specify the offset into the FloatBuffer at which the matrix is stored, use Matrix2fc.getTransposed(int, FloatBuffer), taking the absolute position as parameter.

      Specified by:
      getTransposed in interface Matrix2fc
      Parameters:
      buffer - will receive the values of this matrix in column-major order at its current position
      Returns:
      the passed in buffer
      See Also:
    • getTransposed

      public FloatBuffer getTransposed(int index, FloatBuffer buffer)
      Description copied from interface: Matrix2fc
      Store the transpose of this matrix in column-major order into the supplied FloatBuffer starting at the specified absolute buffer position/index.

      This method will not increment the position of the given FloatBuffer.

      Specified by:
      getTransposed in interface Matrix2fc
      Parameters:
      index - the absolute position into the FloatBuffer
      buffer - will receive the values of this matrix in column-major order
      Returns:
      the passed in buffer
    • getTransposed

      public ByteBuffer getTransposed(ByteBuffer buffer)
      Description copied from interface: Matrix2fc
      Store the transpose of this matrix in column-major order into the supplied ByteBuffer at the current buffer position.

      This method will not increment the position of the given ByteBuffer.

      In order to specify the offset into the ByteBuffer at which the matrix is stored, use Matrix2fc.getTransposed(int, ByteBuffer), taking the absolute position as parameter.

      Specified by:
      getTransposed in interface Matrix2fc
      Parameters:
      buffer - will receive the values of this matrix in column-major order at its current position
      Returns:
      the passed in buffer
      See Also:
    • getTransposed

      public ByteBuffer getTransposed(int index, ByteBuffer buffer)
      Description copied from interface: Matrix2fc
      Store the transpose of this matrix in column-major order into the supplied ByteBuffer starting at the specified absolute buffer position/index.

      This method will not increment the position of the given ByteBuffer.

      Specified by:
      getTransposed in interface Matrix2fc
      Parameters:
      index - the absolute position into the ByteBuffer
      buffer - will receive the values of this matrix in column-major order
      Returns:
      the passed in buffer
    • getToAddress

      public Matrix2fc getToAddress(long address)
      Description copied from interface: Matrix2fc
      Store this matrix in column-major order at the given off-heap address.

      This method will throw an UnsupportedOperationException when JOML is used with `-Djoml.nounsafe`.

      This method is unsafe as it can result in a crash of the JVM process when the specified address range does not belong to this process.

      Specified by:
      getToAddress in interface Matrix2fc
      Parameters:
      address - the off-heap address where to store this matrix
      Returns:
      this
    • get

      public float[] get(float[] arr, int offset)
      Description copied from interface: Matrix2fc
      Store this matrix into the supplied float array in column-major order at the given offset.
      Specified by:
      get in interface Matrix2fc
      Parameters:
      arr - the array to write the matrix values into
      offset - the offset into the array
      Returns:
      the passed in array
    • get

      public float[] get(float[] arr)
      Description copied from interface: Matrix2fc
      Store this matrix into the supplied float array in column-major order.

      In order to specify an explicit offset into the array, use the method Matrix2fc.get(float[], int).

      Specified by:
      get in interface Matrix2fc
      Parameters:
      arr - the array to write the matrix values into
      Returns:
      the passed in array
      See Also:
    • set

      public Matrix2f set(FloatBuffer buffer)
      Set the values of this matrix by reading 4 float values from the given FloatBuffer in column-major order, starting at its current position.

      The FloatBuffer is expected to contain the values in column-major order.

      The position of the FloatBuffer will not be changed by this method.

      Parameters:
      buffer - the FloatBuffer to read the matrix values from in column-major order
      Returns:
      this
    • set

      public Matrix2f set(ByteBuffer buffer)
      Set the values of this matrix by reading 4 float values from the given ByteBuffer in column-major order, starting at its current position.

      The ByteBuffer is expected to contain the values in column-major order.

      The position of the ByteBuffer will not be changed by this method.

      Parameters:
      buffer - the ByteBuffer to read the matrix values from in column-major order
      Returns:
      this
    • set

      public Matrix2f set(int index, FloatBuffer buffer)
      Set the values of this matrix by reading 4 float values from the given FloatBuffer in column-major order, starting at the specified absolute buffer position/index.

      The FloatBuffer is expected to contain the values in column-major order.

      The position of the FloatBuffer will not be changed by this method.

      Parameters:
      index - the absolute position into the FloatBuffer
      buffer - the FloatBuffer to read the matrix values from in column-major order
      Returns:
      this
    • set

      public Matrix2f set(int index, ByteBuffer buffer)
      Set the values of this matrix by reading 4 float values from the given ByteBuffer in column-major order, starting at the specified absolute buffer position/index.

      The ByteBuffer is expected to contain the values in column-major order.

      The position of the ByteBuffer will not be changed by this method.

      Parameters:
      index - the absolute position into the ByteBuffer
      buffer - the ByteBuffer to read the matrix values from in column-major order
      Returns:
      this
    • setFromAddress

      public Matrix2f setFromAddress(long address)
      Set the values of this matrix by reading 4 float values from off-heap memory in column-major order, starting at the given address.

      This method will throw an UnsupportedOperationException when JOML is used with `-Djoml.nounsafe`.

      This method is unsafe as it can result in a crash of the JVM process when the specified address range does not belong to this process.

      Parameters:
      address - the off-heap memory address to read the matrix values from in column-major order
      Returns:
      this
    • zero

      public Matrix2f zero()
      Set all values within this matrix to zero.
      Returns:
      this
    • identity

      public Matrix2f identity()
      Set this matrix to the identity.
      Returns:
      this
    • scale

      public Matrix2f scale(Vector2fc xy, Matrix2f dest)
      Description copied from interface: Matrix2fc
      Apply scaling to this matrix by scaling the base axes by the given xy.x and xy.y factors, respectively and store the result in dest.

      If M is this matrix and S the scaling matrix, then the new matrix will be M * S. So when transforming a vector v with the new matrix by using M * S * v , the scaling will be applied first!

      Specified by:
      scale in interface Matrix2fc
      Parameters:
      xy - the factors of the x and y component, respectively
      dest - will hold the result
      Returns:
      dest
    • scale

      public Matrix2f scale(Vector2fc xy)
      Apply scaling to this matrix by scaling the base axes by the given xy.x and xy.y factors, respectively.

      If M is this matrix and S the scaling matrix, then the new matrix will be M * S. So when transforming a vector v with the new matrix by using M * S * v, the scaling will be applied first!

      Parameters:
      xy - the factors of the x and y component, respectively
      Returns:
      this
    • scale

      public Matrix2f scale(float x, float y, Matrix2f dest)
      Description copied from interface: Matrix2fc
      Apply scaling to this matrix by scaling the base axes by the given x and y factors and store the result in dest.

      If M is this matrix and S the scaling matrix, then the new matrix will be M * S. So when transforming a vector v with the new matrix by using M * S * v , the scaling will be applied first!

      Specified by:
      scale in interface Matrix2fc
      Parameters:
      x - the factor of the x component
      y - the factor of the y component
      dest - will hold the result
      Returns:
      dest
    • scale

      public Matrix2f scale(float x, float y)
      Apply scaling to this matrix by scaling the base axes by the given x and y factors.

      If M is this matrix and S the scaling matrix, then the new matrix will be M * S. So when transforming a vector v with the new matrix by using M * S * v , the scaling will be applied first!

      Parameters:
      x - the factor of the x component
      y - the factor of the y component
      Returns:
      this
    • scale

      public Matrix2f scale(float xy, Matrix2f dest)
      Description copied from interface: Matrix2fc
      Apply scaling to this matrix by uniformly scaling all base axes by the given xy factor and store the result in dest.

      If M is this matrix and S the scaling matrix, then the new matrix will be M * S. So when transforming a vector v with the new matrix by using M * S * v , the scaling will be applied first!

      Specified by:
      scale in interface Matrix2fc
      Parameters:
      xy - the factor for all components
      dest - will hold the result
      Returns:
      dest
      See Also:
    • scale

      public Matrix2f scale(float xy)
      Apply scaling to this matrix by uniformly scaling all base axes by the given xy factor.

      If M is this matrix and S the scaling matrix, then the new matrix will be M * S. So when transforming a vector v with the new matrix by using M * S * v , the scaling will be applied first!

      Parameters:
      xy - the factor for all components
      Returns:
      this
      See Also:
    • scaleLocal

      public Matrix2f scaleLocal(float x, float y, Matrix2f dest)
      Description copied from interface: Matrix2fc
      Pre-multiply scaling to this matrix by scaling the base axes by the given x and y factors and store the result in dest.

      If M is this matrix and S the scaling matrix, then the new matrix will be S * M. So when transforming a vector v with the new matrix by using S * M * v , the scaling will be applied last!

      Specified by:
      scaleLocal in interface Matrix2fc
      Parameters:
      x - the factor of the x component
      y - the factor of the y component
      dest - will hold the result
      Returns:
      dest
    • scaleLocal

      public Matrix2f scaleLocal(float x, float y)
      Pre-multiply scaling to this matrix by scaling the base axes by the given x and y factors.

      If M is this matrix and S the scaling matrix, then the new matrix will be S * M. So when transforming a vector v with the new matrix by using S * M * v, the scaling will be applied last!

      Parameters:
      x - the factor of the x component
      y - the factor of the y component
      Returns:
      this
    • scaling

      public Matrix2f scaling(float factor)
      Set this matrix to be a simple scale matrix, which scales all axes uniformly by the given factor.

      The resulting matrix can be multiplied against another transformation matrix to obtain an additional scaling.

      In order to post-multiply a scaling transformation directly to a matrix, use scale() instead.

      Parameters:
      factor - the scale factor in x and y
      Returns:
      this
      See Also:
    • scaling

      public Matrix2f scaling(float x, float y)
      Set this matrix to be a simple scale matrix.
      Parameters:
      x - the scale in x
      y - the scale in y
      Returns:
      this
    • scaling

      public Matrix2f scaling(Vector2fc xy)
      Set this matrix to be a simple scale matrix which scales the base axes by xy.x and xy.y respectively.

      The resulting matrix can be multiplied against another transformation matrix to obtain an additional scaling.

      In order to post-multiply a scaling transformation directly to a matrix use scale() instead.

      Parameters:
      xy - the scale in x and y respectively
      Returns:
      this
      See Also:
    • rotation

      public Matrix2f rotation(float angle)
      Set this matrix to a rotation matrix which rotates the given radians about the origin.

      The produced rotation will rotate a vector counter-clockwise around the origin.

      The resulting matrix can be multiplied against another transformation matrix to obtain an additional rotation.

      In order to post-multiply a rotation transformation directly to a matrix, use rotate() instead.

      Parameters:
      angle - the angle in radians
      Returns:
      this
      See Also:
    • transform

      public Vector2f transform(Vector2f v)
      Description copied from interface: Matrix2fc
      Transform the given vector by this matrix.
      Specified by:
      transform in interface Matrix2fc
      Parameters:
      v - the vector to transform
      Returns:
      v
    • transform

      public Vector2f transform(Vector2fc v, Vector2f dest)
      Description copied from interface: Matrix2fc
      Transform the given vector by this matrix and store the result in dest.
      Specified by:
      transform in interface Matrix2fc
      Parameters:
      v - the vector to transform
      dest - will hold the result
      Returns:
      dest
    • transform

      public Vector2f transform(float x, float y, Vector2f dest)
      Description copied from interface: Matrix2fc
      Transform the vector (x, y) by this matrix and store the result in dest.
      Specified by:
      transform in interface Matrix2fc
      Parameters:
      x - the x coordinate of the vector to transform
      y - the y coordinate of the vector to transform
      dest - will hold the result
      Returns:
      dest
    • transformTranspose

      public Vector2f transformTranspose(Vector2f v)
      Description copied from interface: Matrix2fc
      Transform the given vector by the transpose of this matrix.
      Specified by:
      transformTranspose in interface Matrix2fc
      Parameters:
      v - the vector to transform
      Returns:
      v
    • transformTranspose

      public Vector2f transformTranspose(Vector2fc v, Vector2f dest)
      Description copied from interface: Matrix2fc
      Transform the given vector by the transpose of this matrix and store the result in dest.
      Specified by:
      transformTranspose in interface Matrix2fc
      Parameters:
      v - the vector to transform
      dest - will hold the result
      Returns:
      dest
    • transformTranspose

      public Vector2f transformTranspose(float x, float y, Vector2f dest)
      Description copied from interface: Matrix2fc
      Transform the vector (x, y) by the transpose of this matrix and store the result in dest.
      Specified by:
      transformTranspose in interface Matrix2fc
      Parameters:
      x - the x coordinate of the vector to transform
      y - the y coordinate of the vector to transform
      dest - will hold the result
      Returns:
      dest
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
    • rotate

      public Matrix2f rotate(float angle)
      Apply rotation about the origin to this matrix by rotating the given amount of radians.

      The produced rotation will rotate a vector counter-clockwise around the origin.

      If M is this matrix and R the rotation matrix, then the new matrix will be M * R. So when transforming a vector v with the new matrix by using M * R * v , the rotation will be applied first!

      Reference: http://en.wikipedia.org

      Parameters:
      angle - the angle in radians
      Returns:
      this
    • rotate

      public Matrix2f rotate(float angle, Matrix2f dest)
      Description copied from interface: Matrix2fc
      Apply rotation to this matrix by rotating the given amount of radians and store the result in dest.

      The produced rotation will rotate a vector counter-clockwise around the origin.

      If M is this matrix and R the rotation matrix, then the new matrix will be M * R. So when transforming a vector v with the new matrix by using M * R * v , the rotation will be applied first!

      Reference: http://en.wikipedia.org

      Specified by:
      rotate in interface Matrix2fc
      Parameters:
      angle - the angle in radians
      dest - will hold the result
      Returns:
      dest
    • rotateLocal

      public Matrix2f rotateLocal(float angle)
      Pre-multiply a rotation to this matrix by rotating the given amount of radians about the origin.

      The produced rotation will rotate a vector counter-clockwise around the origin.

      If M is this matrix and R the rotation matrix, then the new matrix will be R * M. So when transforming a vector v with the new matrix by using R * M * v, the rotation will be applied last!

      In order to set the matrix to a rotation matrix without pre-multiplying the rotation transformation, use rotation().

      Reference: http://en.wikipedia.org

      Parameters:
      angle - the angle in radians to rotate about the X axis
      Returns:
      this
      See Also:
    • rotateLocal

      public Matrix2f rotateLocal(float angle, Matrix2f dest)
      Description copied from interface: Matrix2fc
      Pre-multiply a rotation to this matrix by rotating the given amount of radians and store the result in dest.

      The produced rotation will rotate a vector counter-clockwise around the origin.

      If M is this matrix and R the rotation matrix, then the new matrix will be R * M. So when transforming a vector v with the new matrix by using R * M * v, the rotation will be applied last!

      Reference: http://en.wikipedia.org

      Specified by:
      rotateLocal in interface Matrix2fc
      Parameters:
      angle - the angle in radians
      dest - will hold the result
      Returns:
      dest
    • getRow

      public Vector2f getRow(int row, Vector2f dest) throws IndexOutOfBoundsException
      Description copied from interface: Matrix2fc
      Get the row at the given row index, starting with 0.
      Specified by:
      getRow in interface Matrix2fc
      Parameters:
      row - the row index in [0..1]
      dest - will hold the row components
      Returns:
      the passed in destination
      Throws:
      IndexOutOfBoundsException - if row is not in [0..1]
    • setRow

      public Matrix2f setRow(int row, Vector2fc src) throws IndexOutOfBoundsException
      Set the row at the given row index, starting with 0.
      Parameters:
      row - the row index in [0..1]
      src - the row components to set
      Returns:
      this
      Throws:
      IndexOutOfBoundsException - if row is not in [0..1]
    • setRow

      public Matrix2f setRow(int row, float x, float y) throws IndexOutOfBoundsException
      Set the row at the given row index, starting with 0.
      Parameters:
      row - the row index in [0..1]
      x - the first element in the row
      y - the second element in the row
      Returns:
      this
      Throws:
      IndexOutOfBoundsException - if row is not in [0..1]
    • getColumn

      public Vector2f getColumn(int column, Vector2f dest) throws IndexOutOfBoundsException
      Description copied from interface: Matrix2fc
      Get the column at the given column index, starting with 0.
      Specified by:
      getColumn in interface Matrix2fc
      Parameters:
      column - the column index in [0..1]
      dest - will hold the column components
      Returns:
      the passed in destination
      Throws:
      IndexOutOfBoundsException - if column is not in [0..1]
    • setColumn

      public Matrix2f setColumn(int column, Vector2fc src) throws IndexOutOfBoundsException
      Set the column at the given column index, starting with 0.
      Parameters:
      column - the column index in [0..1]
      src - the column components to set
      Returns:
      this
      Throws:
      IndexOutOfBoundsException - if column is not in [0..1]
    • setColumn

      public Matrix2f setColumn(int column, float x, float y) throws IndexOutOfBoundsException
      Set the column at the given column index, starting with 0.
      Parameters:
      column - the column index in [0..1]
      x - the first element in the column
      y - the second element in the column
      Returns:
      this
      Throws:
      IndexOutOfBoundsException - if column is not in [0..1]
    • get

      public float get(int column, int row)
      Description copied from interface: Matrix2fc
      Get the matrix element value at the given column and row.
      Specified by:
      get in interface Matrix2fc
      Parameters:
      column - the colum index in [0..1]
      row - the row index in [0..1]
      Returns:
      the element value
    • set

      public Matrix2f set(int column, int row, float value)
      Set the matrix element at the given column and row to the specified value.
      Parameters:
      column - the colum index in [0..1]
      row - the row index in [0..1]
      value - the value
      Returns:
      this
    • normal

      public Matrix2f normal()
      Set this matrix to its own normal matrix.

      Please note that, if this is an orthogonal matrix or a matrix whose columns are orthogonal vectors, then this method need not be invoked, since in that case this itself is its normal matrix. In this case, use set(Matrix2fc) to set a given Matrix2f to this matrix.

      Returns:
      this
      See Also:
    • normal

      public Matrix2f normal(Matrix2f dest)
      Compute a normal matrix from this matrix and store it into dest.

      Please note that, if this is an orthogonal matrix or a matrix whose columns are orthogonal vectors, then this method need not be invoked, since in that case this itself is its normal matrix. In this case, use set(Matrix2fc) to set a given Matrix2f to this matrix.

      Specified by:
      normal in interface Matrix2fc
      Parameters:
      dest - will hold the result
      Returns:
      dest
      See Also:
    • getScale

      public Vector2f getScale(Vector2f dest)
      Description copied from interface: Matrix2fc
      Get the scaling factors of this matrix for the three base axes.
      Specified by:
      getScale in interface Matrix2fc
      Parameters:
      dest - will hold the scaling factors for x and y
      Returns:
      dest
    • positiveX

      public Vector2f positiveX(Vector2f dir)
      Description copied from interface: Matrix2fc
      Obtain the direction of +X before the transformation represented by this matrix is applied.

      This method is equivalent to the following code:

       Matrix2f inv = new Matrix2f(this).invert();
       inv.transform(dir.set(1, 0)).normalize();
       
      If this is already an orthogonal matrix, then consider using Matrix2fc.normalizedPositiveX(Vector2f) instead.
      Specified by:
      positiveX in interface Matrix2fc
      Parameters:
      dir - will hold the direction of +X
      Returns:
      dest
    • normalizedPositiveX

      public Vector2f normalizedPositiveX(Vector2f dir)
      Description copied from interface: Matrix2fc
      Obtain the direction of +X before the transformation represented by this orthogonal matrix is applied. This method only produces correct results if this is an orthogonal matrix.

      This method is equivalent to the following code:

       Matrix2f inv = new Matrix2f(this).transpose();
       inv.transform(dir.set(1, 0));
       
      Specified by:
      normalizedPositiveX in interface Matrix2fc
      Parameters:
      dir - will hold the direction of +X
      Returns:
      dest
    • positiveY

      public Vector2f positiveY(Vector2f dir)
      Description copied from interface: Matrix2fc
      Obtain the direction of +Y before the transformation represented by this matrix is applied.

      This method is equivalent to the following code:

       Matrix2f inv = new Matrix2f(this).invert();
       inv.transform(dir.set(0, 1)).normalize();
       
      If this is already an orthogonal matrix, then consider using Matrix2fc.normalizedPositiveY(Vector2f) instead.
      Specified by:
      positiveY in interface Matrix2fc
      Parameters:
      dir - will hold the direction of +Y
      Returns:
      dest
    • normalizedPositiveY

      public Vector2f normalizedPositiveY(Vector2f dir)
      Description copied from interface: Matrix2fc
      Obtain the direction of +Y before the transformation represented by this orthogonal matrix is applied. This method only produces correct results if this is an orthogonal matrix.

      This method is equivalent to the following code:

       Matrix2f inv = new Matrix2f(this).transpose();
       inv.transform(dir.set(0, 1));
       
      Specified by:
      normalizedPositiveY in interface Matrix2fc
      Parameters:
      dir - will hold the direction of +Y
      Returns:
      dest
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • equals

      public boolean equals(Matrix2fc m, float delta)
      Description copied from interface: Matrix2fc
      Compare the matrix elements of this matrix with the given matrix using the given delta and return whether all of them are equal within a maximum difference of delta.

      Please note that this method is not used by any data structure such as ArrayList HashSet or HashMap and their operations, such as ArrayList.contains(Object) or HashSet.remove(Object), since those data structures only use the Object.equals(Object) and Object.hashCode() methods.

      Specified by:
      equals in interface Matrix2fc
      Parameters:
      m - the other matrix
      delta - the allowed maximum difference
      Returns:
      true whether all of the matrix elements are equal; false otherwise
    • swap

      public Matrix2f swap(Matrix2f other)
      Exchange the values of this matrix with the given other matrix.
      Parameters:
      other - the other matrix to exchange the values with
      Returns:
      this
    • add

      public Matrix2f add(Matrix2fc other)
      Component-wise add this and other.
      Parameters:
      other - the other addend
      Returns:
      this
    • add

      public Matrix2f add(Matrix2fc other, Matrix2f dest)
      Description copied from interface: Matrix2fc
      Component-wise add this and other and store the result in dest.
      Specified by:
      add in interface Matrix2fc
      Parameters:
      other - the other addend
      dest - will hold the result
      Returns:
      dest
    • sub

      public Matrix2f sub(Matrix2fc subtrahend)
      Component-wise subtract subtrahend from this.
      Parameters:
      subtrahend - the subtrahend
      Returns:
      this
    • sub

      public Matrix2f sub(Matrix2fc other, Matrix2f dest)
      Description copied from interface: Matrix2fc
      Component-wise subtract subtrahend from this and store the result in dest.
      Specified by:
      sub in interface Matrix2fc
      Parameters:
      other - the subtrahend
      dest - will hold the result
      Returns:
      dest
    • mulComponentWise

      public Matrix2f mulComponentWise(Matrix2fc other)
      Component-wise multiply this by other.
      Parameters:
      other - the other matrix
      Returns:
      this
    • mulComponentWise

      public Matrix2f mulComponentWise(Matrix2fc other, Matrix2f dest)
      Description copied from interface: Matrix2fc
      Component-wise multiply this by other and store the result in dest.
      Specified by:
      mulComponentWise in interface Matrix2fc
      Parameters:
      other - the other matrix
      dest - will hold the result
      Returns:
      dest
    • lerp

      public Matrix2f lerp(Matrix2fc other, float t)
      Linearly interpolate this and other using the given interpolation factor t and store the result in this.

      If t is 0.0 then the result is this. If the interpolation factor is 1.0 then the result is other.

      Parameters:
      other - the other matrix
      t - the interpolation factor between 0.0 and 1.0
      Returns:
      this
    • lerp

      public Matrix2f lerp(Matrix2fc other, float t, Matrix2f dest)
      Description copied from interface: Matrix2fc
      Linearly interpolate this and other using the given interpolation factor t and store the result in dest.

      If t is 0.0 then the result is this. If the interpolation factor is 1.0 then the result is other.

      Specified by:
      lerp in interface Matrix2fc
      Parameters:
      other - the other matrix
      t - the interpolation factor between 0.0 and 1.0
      dest - will hold the result
      Returns:
      dest
    • isFinite

      public boolean isFinite()
      Description copied from interface: Matrix2fc
      Determine whether all matrix elements are finite floating-point values, that is, they are not NaN and not infinity.
      Specified by:
      isFinite in interface Matrix2fc
      Returns:
      true if all components are finite floating-point values; false otherwise
    • clone

      public Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException