Package toxi.geom

Class Matrix4x4

java.lang.Object
toxi.geom.Matrix4x4

public class Matrix4x4 extends Object
Implements a simple row-major 4x4 matrix class, all matrix operations are applied to new instances. Use transpose() to convert from column-major formats...
  • Field Details

    • matrix

      public double[][] matrix
  • Constructor Details

    • Matrix4x4

      public Matrix4x4()
    • Matrix4x4

      public Matrix4x4(double v11, double v12, double v13, double v14, double v21, double v22, double v23, double v24, double v31, double v32, double v33, double v34, double v41, double v42, double v43, double v44)
    • Matrix4x4

      public Matrix4x4(double[] array)
      Initialising constructor from a 1d array. Assumes row-major ordering (column index increases faster).
      Parameters:
      array -
    • Matrix4x4

      public Matrix4x4(Matrix4x4 m)
  • Method Details

    • add

      public Matrix4x4 add(Matrix4x4 rhs)
    • addSelf

      public Matrix4x4 addSelf(Matrix4x4 m)
    • applyTo

      public Vec3D applyTo(ReadonlyVec3D v)
      Creates a copy of the given vector, transformed by this matrix.
      Parameters:
      v -
      Returns:
      transformed vector
    • applyToSelf

      public Vec3D applyToSelf(Vec3D v)
    • copy

      public Matrix4x4 copy()
    • getInverted

      public Matrix4x4 getInverted()
    • getRotatedAroundAxis

      public Matrix4x4 getRotatedAroundAxis(ReadonlyVec3D axis, double theta)
    • getRotatedX

      public Matrix4x4 getRotatedX(double theta)
    • getRotatedY

      public Matrix4x4 getRotatedY(double theta)
    • getRotatedZ

      public Matrix4x4 getRotatedZ(double theta)
    • getTransposed

      public Matrix4x4 getTransposed()
    • identity

      public Matrix4x4 identity()
    • invert

      public Matrix4x4 invert()
      Matrix Inversion using Cramer's Method Computes Adjoint matrix divided by determinant Code modified from http://www.intel.com/design/pentiumiii/sml/24504301.pdf
      Returns:
      itself
    • lookAt

      public Matrix4x4 lookAt(ReadonlyVec3D eye, ReadonlyVec3D target, ReadonlyVec3D up)
    • multiply

      public Matrix4x4 multiply(double factor)
    • multiply

      public Matrix4x4 multiply(Matrix4x4 mat)
      Matrix-Matrix Right-multiplication.
      Parameters:
      mat -
      Returns:
      product as new matrix
    • multiplySelf

      public Matrix4x4 multiplySelf(double factor)
      In-place matrix-scalar multiplication.
      Parameters:
      factor -
      Returns:
      product applied to this matrix.
    • multiplySelf

      public Matrix4x4 multiplySelf(Matrix4x4 mat)
    • rotateAroundAxis

      public Matrix4x4 rotateAroundAxis(ReadonlyVec3D axis, double theta)
      Applies rotation about arbitrary axis to matrix
      Parameters:
      axis -
      theta -
      Returns:
      rotation applied to this matrix
    • rotateX

      public Matrix4x4 rotateX(double theta)
      Applies rotation about X to this matrix.
      Parameters:
      theta - rotation angle in radians
      Returns:
      itself
    • rotateY

      public Matrix4x4 rotateY(double theta)
      Applies rotation about Y to this matrix.
      Parameters:
      theta - rotation angle in radians
      Returns:
      itself
    • rotateZ

      public Matrix4x4 rotateZ(double theta)
    • scale

      public Matrix4x4 scale(double scale)
    • scale

      public Matrix4x4 scale(double scaleX, double scaleY, double scaleZ)
    • scale

      public Matrix4x4 scale(ReadonlyVec3D scale)
    • scaleSelf

      public Matrix4x4 scaleSelf(double scale)
    • scaleSelf

      public Matrix4x4 scaleSelf(double scaleX, double scaleY, double scaleZ)
    • scaleSelf

      public Matrix4x4 scaleSelf(ReadonlyVec3D scale)
    • set

      public Matrix4x4 set(double a, double b, double c, double d, double e, double f, double g, double h, double i, double j, double k, double l, double m, double n, double o, double p)
    • set

      public Matrix4x4 set(Matrix4x4 mat)
    • setFrustum

      public Matrix4x4 setFrustum(double left, double right, double top, double bottom, double near, double far)
    • setOrtho

      public Matrix4x4 setOrtho(double left, double right, double top, double bottom, double near, double far)
    • setPerspective

      public Matrix4x4 setPerspective(double fov, double aspect, double near, double far)
    • setPosition

      public Matrix4x4 setPosition(double x, double y, double z)
    • setScale

      public Matrix4x4 setScale(double scaleX, double scaleY, double scaleZ)
    • sub

      public Matrix4x4 sub(Matrix4x4 m)
    • subSelf

      public Matrix4x4 subSelf(Matrix4x4 mat)
    • toArray

      public double[] toArray(double[] result)
      Copies all matrix elements into an linear array.
      Parameters:
      result - array (or null to create a new one)
      Returns:
      matrix as 16 element array
    • toFloatArray

      public float[] toFloatArray(float[] result)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toTransposedFloatArray

      public float[] toTransposedFloatArray(float[] result)
    • translate

      public Matrix4x4 translate(double dx, double dy, double dz)
    • translate

      public Matrix4x4 translate(ReadonlyVec3D trans)
    • translateSelf

      public Matrix4x4 translateSelf(double dx, double dy, double dz)
    • translateSelf

      public Matrix4x4 translateSelf(ReadonlyVec3D trans)
    • transpose

      public Matrix4x4 transpose()
      Converts the matrix (in-place) between column-major to row-major order (and vice versa).
      Returns:
      itself