Class Matrix4F

java.lang.Object
com.blackrook.gloop.opengl.math.Matrix4F

public class Matrix4F extends Object
This is a 4x4 Matrix object that stores floats. Indices are in column-major order.
0 4 8 12
1 5 9 13
2 6 10 14
3 7 11 15
Author:
Matthew Tropiano
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static float[]
    Identity Matrix in column-major form.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new, blank 4x4 matrix.
  • Method Summary

    Modifier and Type
    Method
    Description
    aspectOrtho(float aspect, float left, float right, float bottom, float top, float zNear, float zFar)
    Multiplies an aspect-corrected orthographic projection matrix into this one.
     
    void
    copyTo(Matrix4F target)
    Copies this Matrix into another.
    frustum(float left, float right, float bottom, float top, float zNear, float zFar)
    Multiplies a frustum projection matrix into this one.
    float[]
     
    void
    getFloats(float[] out)
    Returns the floats that make up this matrix into a float array.
    void
    getFloats(float[] out, int offset)
    Returns the floats that make up this matrix into a float array.
    lookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
    Multiplies a "look at" perspective matrix into this one.
    void
    Multiplies this matrix with another.
    void
    Multiplies this matrix with another.
    static Matrix4F
     
    ortho(float left, float right, float bottom, float top, float zNear, float zFar)
    Multiplies a orthographic projection matrix into this one.
    perspective(float fov, float aspect, float zNear, float zFar)
    Multiplies a perspective projection matrix into this one.
    Resets this matrix to the identity matrix.
    rotateX(float degrees)
    Multiplies a X-axis rotation matrix into this one.
    rotateY(float degrees)
    Multiplies a Y-axis rotation matrix into this one.
    rotateZ(float degrees)
    Multiplies a Z-axis rotation matrix into this one.
    scale(float scalar)
    Multiplies a scaling matrix into this one.
    scale(float scaleX, float scaleY, float scaleZ)
    Multiplies a scaling matrix into this one.
    void
    set(float[] values)
    Sets all positions in this matrix to a set of values.
    void
    set(int index, float value)
    Sets a matrix index (column major index) to a value.
    void
    set(int row, int col, float val)
    Sets a position in this matrix to a value.
    void
    set(Matrix4F matrix)
    Sets all positions in this matrix to a set of values from another.
    void
    setAspectOrtho(float aspect, float left, float right, float bottom, float top, float zNear, float zFar)
    Sets this matrix's values up as an aspect-corrected projection matrix, orthographic projection.
    void
    setFrustum(float left, float right, float bottom, float top, float zNear, float zFar)
    Sets this matrix's values up as a projection matrix, frustum projection.
    void
    Sets this matrix to the identity matrix.
    void
    setLookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
    Sets this matrix's values up as a "look at" perspective matrix.
    void
    setOrtho(float left, float right, float bottom, float top, float zNear, float zFar)
    Sets this matrix's values up as a projection matrix, orthographic projection.
    void
    setPerspective(float fov, float aspect, float zNear, float zFar)
    Sets this matrix's values up as a projection matrix, perspective arguments.
    void
    setRotateX(float degrees)
    Sets this matrix to a x-rotation matrix.
    void
    setRotateY(float degrees)
    Sets this matrix to a y-rotation matrix.
    void
    setRotateZ(float degrees)
    Sets this matrix to a z-rotation matrix.
    void
    setRotation(float degX, float degY, float degZ)
    Sets this matrix to a rotation matrix.
    void
    setScale(float scalar)
    Sets this matrix to a scaling matrix, scaling all axes equally.
    void
    setScale(float scaleX, float scaleY, float scaleZ)
    Sets this matrix to a scaling matrix.
    void
    setShear(float shear)
    Sets this matrix to a shearing matrix.
    void
    setTranslation(float x, float y, float z)
    Sets this matrix to a translation matrix.
    shear(float shear)
    Multiplies a shearing matrix into this one.
    translate(float x, float y, float z)
    Multiplies a translation matrix into this one.

    Methods inherited from class Object

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

    • IDENTITY

      protected static float[] IDENTITY
      Identity Matrix in column-major form.
  • Constructor Details

    • Matrix4F

      public Matrix4F()
      Constructs a new, blank 4x4 matrix.
  • Method Details

    • newIdentity

      public static Matrix4F newIdentity()
      Returns:
      a new 4x4 Identity Matrix.
    • setIdentity

      public void setIdentity()
      Sets this matrix to the identity matrix.
    • setTranslation

      public void setTranslation(float x, float y, float z)
      Sets this matrix to a translation matrix.
      Parameters:
      x - the x-axis translation.
      y - the y-axis translation.
      z - the z-axis translation.
    • setRotateX

      public void setRotateX(float degrees)
      Sets this matrix to a x-rotation matrix.
      Parameters:
      degrees - degrees to rotate.
    • setRotateY

      public void setRotateY(float degrees)
      Sets this matrix to a y-rotation matrix.
      Parameters:
      degrees - degrees to rotate.
    • setRotateZ

      public void setRotateZ(float degrees)
      Sets this matrix to a z-rotation matrix.
      Parameters:
      degrees - degrees to rotate.
    • setRotation

      public void setRotation(float degX, float degY, float degZ)
      Sets this matrix to a rotation matrix.
      Parameters:
      degX - degrees to rotate around the X axis.
      degY - degrees to rotate around the Y axis.
      degZ - degrees to rotate around the Z axis.
    • setScale

      public void setScale(float scaleX, float scaleY, float scaleZ)
      Sets this matrix to a scaling matrix.
      Parameters:
      scaleX - amount to scale along the X axis.
      scaleY - amount to scale along the Y axis.
      scaleZ - amount to scale along the Z axis.
    • setScale

      public void setScale(float scalar)
      Sets this matrix to a scaling matrix, scaling all axes equally.
      Parameters:
      scalar - amount to scale along the all axes.
    • setShear

      public void setShear(float shear)
      Sets this matrix to a shearing matrix.
      Parameters:
      shear - amount to shear.
    • setLookAt

      public void setLookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
      Sets this matrix's values up as a "look at" perspective matrix.
      Parameters:
      eyeX - the eye vector, x-component.
      eyeY - the eye vector, y-component.
      eyeZ - the eye vector, z-component.
      centerX - the centerpoint, x-component.
      centerY - the centerpoint, y-component.
      centerZ - the centerpoint, z-component.
      upX - the upward vector, x-component.
      upY - the upward vector, y-component.
      upZ - the upward vector, z-component.
    • setPerspective

      public void setPerspective(float fov, float aspect, float zNear, float zFar)
      Sets this matrix's values up as a projection matrix, perspective arguments.
      Parameters:
      fov - front of view angle in degrees.
      aspect - the aspect ratio, usually view width over view height.
      zNear - the near clipping plane on the Z-Axis.
      zFar - the far clipping plane on the Z-Axis.
    • setFrustum

      public void setFrustum(float left, float right, float bottom, float top, float zNear, float zFar)
      Sets this matrix's values up as a projection matrix, frustum projection.
      Parameters:
      left - the left clipping plane on the X axis.
      right - the right clipping plane on the X axis.
      bottom - the bottom clipping plane on the Y axis.
      top - the upper clipping plane on the Y axis.
      zNear - the near clipping plane on the Z axis.
      zFar - the far clipping plane on the Z axis.
    • setOrtho

      public void setOrtho(float left, float right, float bottom, float top, float zNear, float zFar)
      Sets this matrix's values up as a projection matrix, orthographic projection.
      Parameters:
      left - the left clipping plane on the X axis.
      right - the right clipping plane on the X axis.
      bottom - the bottom clipping plane on the Y axis.
      top - the upper clipping plane on the Y axis.
      zNear - the near clipping plane on the Z axis.
      zFar - the far clipping plane on the Z axis.
    • setAspectOrtho

      public void setAspectOrtho(float aspect, float left, float right, float bottom, float top, float zNear, float zFar)
      Sets this matrix's values up as an aspect-corrected projection matrix, orthographic projection.
      Parameters:
      aspect - the target aspect.
      left - the left clipping plane on the X axis.
      right - the right clipping plane on the X axis.
      bottom - the bottom clipping plane on the Y axis.
      top - the upper clipping plane on the Y axis.
      zNear - the near clipping plane on the Z axis.
      zFar - the far clipping plane on the Z axis.
    • set

      public void set(int row, int col, float val)
      Sets a position in this matrix to a value.
      Parameters:
      row - the desired matrix row.
      col - the desired matrix column.
      val - the new value to set.
    • set

      public void set(Matrix4F matrix)
      Sets all positions in this matrix to a set of values from another.
      Parameters:
      matrix - the matrix to copy from.
    • set

      public void set(float[] values)
      Sets all positions in this matrix to a set of values. Please note that the values must be in column-major order. The amount of values copied is values.length or 16, whichever's smaller.
      Parameters:
      values - new array of values.
    • set

      public void set(int index, float value)
      Sets a matrix index (column major index) to a value.
      Parameters:
      index - the column-major-wise index.
      value - the value to set.
    • reset

      public Matrix4F reset()
      Resets this matrix to the identity matrix.
      Returns:
      itself, to chain commands.
    • translate

      public Matrix4F translate(float x, float y, float z)
      Multiplies a translation matrix into this one.
      Parameters:
      x - the x-axis translation.
      y - the y-axis translation.
      z - the z-axis translation.
      Returns:
      itself, to chain commands.
    • rotateX

      public Matrix4F rotateX(float degrees)
      Multiplies a X-axis rotation matrix into this one.
      Parameters:
      degrees - degrees to rotate.
      Returns:
      itself, to chain commands.
    • rotateY

      public Matrix4F rotateY(float degrees)
      Multiplies a Y-axis rotation matrix into this one.
      Parameters:
      degrees - degrees to rotate.
      Returns:
      itself, to chain commands.
    • rotateZ

      public Matrix4F rotateZ(float degrees)
      Multiplies a Z-axis rotation matrix into this one.
      Parameters:
      degrees - degrees to rotate.
      Returns:
      itself, to chain commands.
    • scale

      public Matrix4F scale(float scaleX, float scaleY, float scaleZ)
      Multiplies a scaling matrix into this one.
      Parameters:
      scaleX - amount to scale along the X axis.
      scaleY - amount to scale along the Y axis.
      scaleZ - amount to scale along the Z axis.
      Returns:
      itself, to chain commands.
    • scale

      public Matrix4F scale(float scalar)
      Multiplies a scaling matrix into this one.
      Parameters:
      scalar - amount to scale along the all axes.
      Returns:
      itself, to chain commands.
    • shear

      public Matrix4F shear(float shear)
      Multiplies a shearing matrix into this one.
      Parameters:
      shear - amount to shear.
      Returns:
      itself, to chain commands.
    • lookAt

      public Matrix4F lookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
      Multiplies a "look at" perspective matrix into this one.
      Parameters:
      eyeX - the eye vector, x-component.
      eyeY - the eye vector, y-component.
      eyeZ - the eye vector, z-component.
      centerX - the centerpoint, x-component.
      centerY - the centerpoint, y-component.
      centerZ - the centerpoint, z-component.
      upX - the upward vector, x-component.
      upY - the upward vector, y-component.
      upZ - the upward vector, z-component.
      Returns:
      itself, to chain commands.
    • perspective

      public Matrix4F perspective(float fov, float aspect, float zNear, float zFar)
      Multiplies a perspective projection matrix into this one.
      Parameters:
      fov - front of view angle in degrees.
      aspect - the aspect ratio, usually view width over view height.
      zNear - the near clipping plane on the Z-Axis.
      zFar - the far clipping plane on the Z-Axis.
      Returns:
      itself, to chain commands.
    • frustum

      public Matrix4F frustum(float left, float right, float bottom, float top, float zNear, float zFar)
      Multiplies a frustum projection matrix into this one.
      Parameters:
      left - the left clipping plane on the X axis.
      right - the right clipping plane on the X axis.
      bottom - the bottom clipping plane on the Y axis.
      top - the upper clipping plane on the Y axis.
      zNear - the near clipping plane on the Z axis.
      zFar - the far clipping plane on the Z axis.
      Returns:
      itself, to chain commands.
    • ortho

      public Matrix4F ortho(float left, float right, float bottom, float top, float zNear, float zFar)
      Multiplies a orthographic projection matrix into this one.
      Parameters:
      left - the left clipping plane on the X axis.
      right - the right clipping plane on the X axis.
      bottom - the bottom clipping plane on the Y axis.
      top - the upper clipping plane on the Y axis.
      zNear - the near clipping plane on the Z axis.
      zFar - the far clipping plane on the Z axis.
      Returns:
      itself, to chain commands.
    • aspectOrtho

      public Matrix4F aspectOrtho(float aspect, float left, float right, float bottom, float top, float zNear, float zFar)
      Multiplies an aspect-corrected orthographic projection matrix into this one.
      Parameters:
      aspect - the target aspect.
      left - the left clipping plane on the X axis.
      right - the right clipping plane on the X axis.
      bottom - the bottom clipping plane on the Y axis.
      top - the upper clipping plane on the Y axis.
      zNear - the near clipping plane on the Z axis.
      zFar - the far clipping plane on the Z axis.
      Returns:
      itself, to chain commands.
    • multiplyRight

      public void multiplyRight(Matrix4F matrix)
      Multiplies this matrix with another.
      this x m
      Parameters:
      matrix - the multiplicand matrix.
    • multiplyLeft

      public void multiplyLeft(Matrix4F matrix)
      Multiplies this matrix with another.
      m x this
      Parameters:
      matrix - the multiplicand matrix.
    • getArray

      public float[] getArray()
      Returns:
      a reference to the float array that makes up this matrix.
    • getFloats

      public void getFloats(float[] out)
      Returns the floats that make up this matrix into a float array. Equivalent to getFloats(out, 0) Values are in column-major order.
      Parameters:
      out - the output array.
      Throws:
      ArrayIndexOutOfBoundsException - if out.length < 16.
    • getFloats

      public void getFloats(float[] out, int offset)
      Returns the floats that make up this matrix into a float array. Values are in column-major order.
      Parameters:
      out - the output array.
      offset - the starting offset array.
      Throws:
      ArrayIndexOutOfBoundsException - if offset + 16 >= out.length.
    • copyTo

      public void copyTo(Matrix4F target)
      Copies this Matrix into another.
      Parameters:
      target - the target matrix to copy into.
    • copy

      public Matrix4F copy()
      Returns:
      a new copy of this Matrix.