Class MatrixStack

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

public class MatrixStack extends Object
A matrix stack for the core implementations.
Author:
Matthew Tropiano
  • Constructor Summary

    Constructors
    Constructor
    Description
    MatrixStack(int depth)
    Creates a new matrix stack.
  • Method Summary

    Modifier and Type
    Method
    Description
    aspectOrtho(float targetAspect, float left, float right, float bottom, float top, float near, float far)
    Multiplies the current matrix by an aspect-adjusted orthographic projection matrix using the canvas dimensions.
    frustum(float left, float right, float bottom, float top, float near, float far)
    Multiplies the current matrix by a frustum projection matrix.
    Sets the topmost matrix to the identity matrix.
    lookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
    Multiplies a "look at" matrix to the current matrix.
    multiply(float[] values)
    Multiplies the topmost matrix with another matrix.
    Multiplies the topmost matrix with another matrix.
    ortho(float left, float right, float bottom, float top, float near, float far)
    Multiplies the current matrix by an orthographic projection matrix.
     
    perspective(float fov, float aspect, float near, float far)
    Multiplies the current matrix by a symmetric perspective projection matrix.
    pop()
    Pops the topmost matrix off the stack.
    Pushes a copy of the topmost matrix onto the stack.
    rotateX(float degrees)
    Rotates the current matrix by an amount of DEGREES around the X-Axis.
    rotateY(float degrees)
    Rotates the current matrix by an amount of DEGREES around the Y-Axis.
    rotateZ(float degrees)
    Rotates the current matrix by an amount of DEGREES around the Z-Axis.
    scale(float x, float y, float z)
    Scales the current matrix by a set of scalars that correspond to each axis.
    set(float[] values)
    Sets the topmost matrix to another matrix.
    set(Matrix4F matrix)
    Sets the topmost matrix to another matrix.
    translate(float x, float y, float z)
    Translates the current matrix by a set of units.

    Methods inherited from class Object

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

    • MatrixStack

      public MatrixStack(int depth)
      Creates a new matrix stack. The topmost matrix is initialized with the identity matrix.
      Parameters:
      depth - the matrix stack depth in matrices.
  • Method Details

    • push

      public Matrix4F push()
      Pushes a copy of the topmost matrix onto the stack.
      Returns:
      the topmost matrix.
      Throws:
      ArrayIndexOutOfBoundsException - if there's no more room to push a new matrix.
    • pop

      public Matrix4F pop()
      Pops the topmost matrix off the stack.
      Returns:
      the topmost matrix.
      Throws:
      ArrayIndexOutOfBoundsException - if there's no matrices left to pop.
    • peek

      public Matrix4F peek()
      Returns:
      the topmost matrix.
    • set

      public Matrix4F set(float[] values)
      Sets the topmost matrix to another matrix.
      Parameters:
      values - the column-major values for the matrix.
      Returns:
      the topmost matrix.
    • set

      public Matrix4F set(Matrix4F matrix)
      Sets the topmost matrix to another matrix.
      Parameters:
      matrix - the matrix to multiply.
      Returns:
      the topmost matrix.
    • identity

      public Matrix4F identity()
      Sets the topmost matrix to the identity matrix.
      Returns:
      the topmost matrix.
    • multiply

      public Matrix4F multiply(float[] values)
      Multiplies the topmost matrix with another matrix.
      Parameters:
      values - the column-major values for the matrix.
      Returns:
      the topmost matrix.
    • multiply

      public Matrix4F multiply(Matrix4F matrix)
      Multiplies the topmost matrix with another matrix.
      Parameters:
      matrix - the matrix to multiply.
      Returns:
      the topmost matrix.
    • translate

      public Matrix4F translate(float x, float y, float z)
      Translates the current matrix by a set of units. This is applied via multiplication with the current matrix.
      Parameters:
      x - the x-axis translation.
      y - the y-axis translation.
      z - the z-axis translation.
      Returns:
      the topmost matrix.
    • rotateX

      public Matrix4F rotateX(float degrees)
      Rotates the current matrix by an amount of DEGREES around the X-Axis. This is applied via multiplication with the current matrix.
      Parameters:
      degrees - the amount of degrees.
      Returns:
      the topmost matrix.
    • rotateY

      public Matrix4F rotateY(float degrees)
      Rotates the current matrix by an amount of DEGREES around the Y-Axis. This is applied via multiplication with the current matrix.
      Parameters:
      degrees - the amount of degrees.
      Returns:
      the topmost matrix.
    • rotateZ

      public Matrix4F rotateZ(float degrees)
      Rotates the current matrix by an amount of DEGREES around the Z-Axis. This is applied via multiplication with the current matrix.
      Parameters:
      degrees - the amount of degrees.
      Returns:
      the topmost matrix.
    • scale

      public Matrix4F scale(float x, float y, float z)
      Scales the current matrix by a set of scalars that correspond to each axis. This is applied via multiplication with the current matrix.
      Parameters:
      x - the x-axis scalar.
      y - the y-axis scalar.
      z - the z-axis scalar.
      Returns:
      the topmost matrix.
    • perspective

      public Matrix4F perspective(float fov, float aspect, float near, float far)
      Multiplies the current matrix by a symmetric perspective projection matrix.
      Parameters:
      fov - front of view angle in degrees.
      aspect - the aspect ratio, usually view width over view height.
      near - the near clipping plane on the Z-Axis.
      far - the far clipping plane on the Z-Axis.
      Returns:
      the topmost matrix.
      Throws:
      ArithmeticException - if fov == 0 || aspect == 0 || near == far.
    • frustum

      public Matrix4F frustum(float left, float right, float bottom, float top, float near, float far)
      Multiplies the current matrix by a frustum projection matrix.
      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.
      near - the near clipping plane on the Z-Axis.
      far - the far clipping plane on the Z-Axis.
      Returns:
      the topmost matrix.
      Throws:
      ArithmeticException - if left == right || bottom == top || near == far.
    • ortho

      public Matrix4F ortho(float left, float right, float bottom, float top, float near, float far)
      Multiplies the current matrix by an orthographic projection matrix.
      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.
      near - the near clipping plane on the Z-Axis.
      far - the far clipping plane on the Z-Axis.
      Returns:
      the topmost matrix.
      Throws:
      ArithmeticException - if left == right || bottom == top || near == far.
    • aspectOrtho

      public Matrix4F aspectOrtho(float targetAspect, float left, float right, float bottom, float top, float near, float far)
      Multiplies the current matrix by an aspect-adjusted orthographic projection matrix using the canvas dimensions.
      Parameters:
      targetAspect - the target orthographic
      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.
      near - the near clipping plane on the Z-Axis.
      far - the far clipping plane on the Z-Axis.
      Returns:
      the topmost matrix.
      Throws:
      ArithmeticException - if left == right || bottom == top || near == far.
    • 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" matrix to the current matrix. This sets up the matrix to look at a place in the world (if modelview).
      Parameters:
      eyeX - the point to look at, X-coordinate.
      eyeY - the point to look at, Y-coordinate.
      eyeZ - the point to look at, Z-coordinate.
      centerX - the reference point to look from, X-coordinate.
      centerY - the reference point to look from, Y-coordinate.
      centerZ - the reference point to look from, Z-coordinate.
      upX - the up vector of the viewpoint, X-coordinate.
      upY - the up vector of the viewpoint, Y-coordinate.
      upZ - the up vector of the viewpoint, Z-coordinate.
      Returns:
      the topmost matrix.