Class Mat4

java.lang.Object
lol.trq.helios.math.Mat4

public final class Mat4 extends Object
4x4 matrix operations on float[16] arrays in OpenGL's column-major order: element (row r, column c) is at m[c * 4 + r]. Every method writes into an output array; only multiply(float[], float[], float[]) with an aliased output allocates (one temporary array). Outputs may alias inputs unless a method says otherwise.
  • Method Summary

    Modifier and Type
    Method
    Description
    static float[]
    identity(float[] out)
    Sets the identity.
    static boolean
    invert(float[] m, float[] out)
    Inverts a matrix.
    static float[]
    multiply(float[] a, float[] b, float[] out)
    Multiplies a * b: applying the result is applying b first, then a.
    static float[]
    ortho(float left, float right, float bottom, float top, float near, float far, float[] out)
    An orthographic projection, as glOrtho.
    static float[]
    perspective(float fovYDegrees, float aspect, float near, float far, float[] out)
    A perspective projection, as gluPerspective.
    static float[]
    rotation(float degrees, float x, float y, float z, float[] out)
    A rotation about an axis, as glRotatef.
    static float[]
    transform(float[] m, double x, double y, double z, double w, float[] out)
    Transforms a point: m * (x, y, z, w).
    static float[]
    translation(float x, float y, float z, float[] out)
    A translation.

    Methods inherited from class Object

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

    • identity

      public static float[] identity(float[] out)
      Sets the identity.
      Parameters:
      out - the matrix
      Returns:
      out
    • multiply

      public static float[] multiply(float[] a, float[] b, float[] out)
      Multiplies a * b: applying the result is applying b first, then a.
      Parameters:
      a - the left matrix
      b - the right matrix
      out - receives the product; may be a or b
      Returns:
      out
    • perspective

      public static float[] perspective(float fovYDegrees, float aspect, float near, float far, float[] out)
      A perspective projection, as gluPerspective.
      Parameters:
      fovYDegrees - vertical field of view
      aspect - width over height
      near - near plane distance, positive
      far - far plane distance
      out - receives the matrix
      Returns:
      out
    • ortho

      public static float[] ortho(float left, float right, float bottom, float top, float near, float far, float[] out)
      An orthographic projection, as glOrtho.
      Parameters:
      left - left plane
      right - right plane
      bottom - bottom plane
      top - top plane
      near - near plane
      far - far plane
      out - receives the matrix
      Returns:
      out
    • translation

      public static float[] translation(float x, float y, float z, float[] out)
      A translation.
      Parameters:
      x - x offset
      y - y offset
      z - z offset
      out - receives the matrix
      Returns:
      out
    • rotation

      public static float[] rotation(float degrees, float x, float y, float z, float[] out)
      A rotation about an axis, as glRotatef.
      Parameters:
      degrees - the angle, counter-clockwise looking down the axis
      x - axis x
      y - axis y
      z - axis z
      out - receives the matrix
      Returns:
      out
    • transform

      public static float[] transform(float[] m, double x, double y, double z, double w, float[] out)
      Transforms a point: m * (x, y, z, w).
      Parameters:
      m - the matrix
      x - x
      y - y
      z - z
      w - w, 1 for points and 0 for directions
      out - receives the four components
      Returns:
      out
    • invert

      public static boolean invert(float[] m, float[] out)
      Inverts a matrix.
      Parameters:
      m - the matrix
      out - receives the inverse; must not be m
      Returns:
      false, leaving out unspecified, when the matrix is singular