Class Matrix4f

java.lang.Object
dev.prozilla.pine.common.math.matrix.Matrix4f

public class Matrix4f extends Object
Represents a 4x4-Matrix. GLSL equivalent to mat4.
  • Constructor Details

    • Matrix4f

      public Matrix4f()
      Creates a 4x4 identity matrix.
    • Matrix4f

      public Matrix4f(Vector4f col1, Vector4f col2, Vector4f col3, Vector4f col4)
      Creates a 4x4 matrix with specified columns.
      Parameters:
      col1 - Vector with values of the first column
      col2 - Vector with values of the second column
      col3 - Vector with values of the third column
      col4 - Vector with values of the fourth column
  • Method Details

    • setIdentity

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

      public Matrix4f add(Matrix4f other)
      Adds this matrix to another matrix.
      Parameters:
      other - The other matrix
      Returns:
      Sum of this + other
    • negate

      public Matrix4f negate()
      Negates this matrix.
      Returns:
      Negated matrix
    • subtract

      public Matrix4f subtract(Matrix4f other)
      Subtracts this matrix from another matrix.
      Parameters:
      other - The other matrix
      Returns:
      Difference of this - other
    • multiply

      public Matrix4f multiply(float scalar)
      Multiplies this matrix with a scalar.
      Parameters:
      scalar - The scalar
      Returns:
      Scalar product of this * scalar
    • multiply

      public Vector4f multiply(Vector4f vector)
      Multiplies this matrix to a vector.
      Parameters:
      vector - The vector
      Returns:
      Vector product of this * other
    • multiply

      public Matrix4f multiply(Matrix4f other)
      Multiplies this matrix to another matrix.
      Parameters:
      other - The other matrix
      Returns:
      Matrix product of this * other
    • transpose

      public Matrix4f transpose()
      Transposes this matrix.
      Returns:
      Transposed matrix
    • toBuffer

      public void toBuffer(FloatBuffer buffer)
      Stores the matrix in a given Buffer.
      Parameters:
      buffer - The buffer to store the matrix data
    • orthographic

      public static Matrix4f orthographic(float left, float right, float bottom, float top, float near, float far)
      Creates a orthographic projection matrix. Similar to glOrtho(left, right, bottom, top, near, far).
      Parameters:
      left - Coordinate for the left vertical clipping pane
      right - Coordinate for the right vertical clipping pane
      bottom - Coordinate for the bottom horizontal clipping pane
      top - Coordinate for the bottom horizontal clipping pane
      near - Coordinate for the near depth clipping pane
      far - Coordinate for the far depth clipping pane
      Returns:
      Orthographic matrix
    • frustum

      public static Matrix4f frustum(float left, float right, float bottom, float top, float near, float far)
      Creates a perspective projection matrix. Similar to glFrustum(left, right, bottom, top, near, far).
      Parameters:
      left - Coordinate for the left vertical clipping pane
      right - Coordinate for the right vertical clipping pane
      bottom - Coordinate for the bottom horizontal clipping pane
      top - Coordinate for the bottom horizontal clipping pane
      near - Coordinate for the near depth clipping pane, must be positive
      far - Coordinate for the far depth clipping pane, must be positive
      Returns:
      Perspective matrix
    • perspective

      public static Matrix4f perspective(float fovy, float aspect, float near, float far)
      Creates a perspective projection matrix. Similar to gluPerspective(fovy, aspec, zNear, zFar).
      Parameters:
      fovy - Field of view angle in degrees
      aspect - The aspect ratio is the ratio of width to height
      near - Distance from the viewer to the near clipping plane, must be positive
      far - Distance from the viewer to the far clipping plane, must be positive
      Returns:
      Perspective matrix
    • translate

      public static Matrix4f translate(float x, float y, float z)
      Creates a translation matrix. Similar to glTranslate(x, y, z).
      Parameters:
      x - x coordinate of translation vector
      y - y coordinate of translation vector
      z - z coordinate of translation vector
      Returns:
      Translation matrix
    • rotate

      public static Matrix4f rotate(float angle, float x, float y, float z)
      Creates a rotation matrix. Similar to glRotate(angle, x, y, z).
      Parameters:
      angle - Angle of rotation in degrees
      x - x coordinate of the rotation vector
      y - y coordinate of the rotation vector
      z - z coordinate of the rotation vector
      Returns:
      Rotation matrix
    • scale

      public static Matrix4f scale(float x, float y, float z)
      Creates a scaling matrix. Similar to glScale(x, y, z).
      Parameters:
      x - Scale factor along the x coordinate
      y - Scale factor along the y coordinate
      z - Scale factor along the z coordinate
      Returns:
      Scaling matrix