Package org.sunflow.math

## Class Matrix4

- java.lang.Object
- - org.sunflow.math.Matrix4

-     public final class Matrix4
      extends java.lang.Object

  This class is used to represent general affine transformations in 3D. The bottom row of the matrix is assumed to be [0,0,0,1]. Note that the rotation matrices assume a right-handed convention.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static Matrix4` | `IDENTITY` |
    `static Matrix4` | `ZERO` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Matrix4​(float[] m, boolean rowMajor)` | Initialize a matrix from the specified 16 element array.
    `Matrix4​(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23)` | Creates a matrix with the specified elements

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `float[]` | `asColMajor()` |
    `float[]` | `asRowMajor()` |
    `static Matrix4` | `blend​(Matrix4 m0, Matrix4 m1, float t)` |
    `float` | `determinant()` | Compute the matrix determinant.
    `boolean` | `equals​(Matrix4 m)` |
    `static Matrix4` | `fromBasis​(OrthoNormalBasis basis)` | Creates a rotation matrix from an OrthonormalBasis.
    `Matrix4` | `inverse()` | Compute the inverse of this matrix and return it as a new object.
    `boolean` | `isIndentity()` |
    `static Matrix4` | `lookAt​(Point3 eye, Point3 target, Vector3 up)` | Creates a camera positioning matrix from the given eye and target points and up vector.
    `Matrix4` | `multiply​(Matrix4 m)` | Computes this*m and return the result as a new Matrix4
    `static Matrix4` | `rotate​(float x, float y, float z, float theta)` | Creates a rotation matrix about the specified axis.
    `static Matrix4` | `rotateX​(float theta)` | Creates a rotation matrix about the X axis.
    `static Matrix4` | `rotateY​(float theta)` | Creates a rotation matrix about the Y axis.
    `static Matrix4` | `rotateZ​(float theta)` | Creates a rotation matrix about the Z axis.
    `static Matrix4` | `scale​(float s)` | Create a uniform scaling matrix.
    `static Matrix4` | `scale​(float sx, float sy, float sz)` | Creates a non-uniform scaling matrix.
    `BoundingBox` | `transform​(BoundingBox b)` | Transforms each corner of the specified axis-aligned bounding box and returns a new bounding box which incloses the transformed corners.
    `Point3` | `transformP​(Point3 p)` | Computes this*p and returns the result as a new Point3 object.
    `float` | `transformPX​(float x, float y, float z)` | Computes the x component of this*(x,y,z,1).
    `float` | `transformPY​(float x, float y, float z)` | Computes the y component of this*(x,y,z,1).
    `float` | `transformPZ​(float x, float y, float z)` | Computes the z component of this*(x,y,z,1).
    `Vector3` | `transformTransposeV​(Vector3 v)` | Computes (this^T)*v and returns the result as a new Vector3 object.
    `float` | `transformTransposeVX​(float x, float y, float z)` | Computes the x component of (this^T)*(x,y,z,0).
    `float` | `transformTransposeVY​(float x, float y, float z)` | Computes the y component of (this^T)*(x,y,z,0).
    `float` | `transformTransposeVZ​(float x, float y, float z)` | Computes the z component of (this^T)*(x,y,z,0).
    `Vector3` | `transformV​(Vector3 v)` | Computes this*v and returns the result as a new Vector3 object.
    `float` | `transformVX​(float x, float y, float z)` | Computes the x component of this*(x,y,z,0).
    `float` | `transformVY​(float x, float y, float z)` | Computes the y component of this*(x,y,z,0).
    `float` | `transformVZ​(float x, float y, float z)` | Computes the z component of this*(x,y,z,0).
    `static Matrix4` | `translation​(float x, float y, float z)` | Create a translation matrix for the specified vector.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### ZERO

          public static final Matrix4 ZERO

    - #### IDENTITY

          public static final Matrix4 IDENTITY

  - ### Constructor Detail

    - #### Matrix4

          public Matrix4​(float m00,
                         float m01,
                         float m02,
                         float m03,
                         float m10,
                         float m11,
                         float m12,
                         float m13,
                         float m20,
                         float m21,
                         float m22,
                         float m23)

      Creates a matrix with the specified elements
      Parameters:
        `m00` - value at row 0, col 0
        `m01` - value at row 0, col 1
        `m02` - value at row 0, col 2
        `m03` - value at row 0, col 3
        `m10` - value at row 1, col 0
        `m11` - value at row 1, col 1
        `m12` - value at row 1, col 2
        `m13` - value at row 1, col 3
        `m20` - value at row 2, col 0
        `m21` - value at row 2, col 1
        `m22` - value at row 2, col 2
        `m23` - value at row 2, col 3

    - #### Matrix4

          public Matrix4​(float[] m,
                         boolean rowMajor)

      Initialize a matrix from the specified 16 element array. The matrix may be given in row or column major form.
      Parameters:
        `m` - a 16 element array in row or column major form
        `rowMajor` - `true` if the array is in row major form, `false`if it is in column major form

  - ### Method Detail

    - #### isIndentity

          public final boolean isIndentity()

    - #### equals

          public final boolean equals​(Matrix4 m)

    - #### asRowMajor

          public final float[] asRowMajor()

    - #### asColMajor

          public final float[] asColMajor()

    - #### determinant

          public final float determinant()

      Compute the matrix determinant.
      Returns:
        determinant of this matrix

    - #### inverse

          public final Matrix4 inverse()

      Compute the inverse of this matrix and return it as a new object. If the matrix is not invertible, `null` is returned.
      Returns:
        the inverse of this matrix, or `null` if not invertible

    - #### multiply

          public final Matrix4 multiply​(Matrix4 m)

      Computes this*m and return the result as a new Matrix4
      Parameters:
        `m` - right hand side of the multiplication
      Returns:
        a new Matrix4 object equal to `this*m`

    - #### transform

          public final BoundingBox transform​(BoundingBox b)

      Transforms each corner of the specified axis-aligned bounding box and returns a new bounding box which incloses the transformed corners.
      Parameters:
        `b` - original bounding box
      Returns:
        a new BoundingBox object which encloses the transform version of b

    - #### transformV

          public final Vector3 transformV​(Vector3 v)

      Computes this*v and returns the result as a new Vector3 object. This method assumes the bottom row of the matrix is `[0,0,0,1]`.
      Parameters:
        `v` - vector to multiply
      Returns:
        a new Vector3 object equal to `this*v`

    - #### transformTransposeV

          public final Vector3 transformTransposeV​(Vector3 v)

      Computes (this^T)*v and returns the result as a new Vector3 object. This method assumes the bottom row of the matrix is `[0,0,0,1]`.
      Parameters:
        `v` - vector to multiply
      Returns:
        a new Vector3 object equal to `(this^T)*v`

    - #### transformP

          public final Point3 transformP​(Point3 p)

      Computes this*p and returns the result as a new Point3 object. This method assumes the bottom row of the matrix is `[0,0,0,1]`.
      Parameters:
        `p` - point to multiply
      Returns:
        a new Point3 object equal to `this*v`

    - #### transformVX

          public final float transformVX​(float x,
                                         float y,
                                         float z)

      Computes the x component of this*(x,y,z,0).
      Parameters:
        `x` - x coordinate of the vector to multiply
        `y` - y coordinate of the vector to multiply
        `z` - z coordinate of the vector to multiply
      Returns:
        x coordinate transformation result

    - #### transformVY

          public final float transformVY​(float x,
                                         float y,
                                         float z)

      Computes the y component of this*(x,y,z,0).
      Parameters:
        `x` - x coordinate of the vector to multiply
        `y` - y coordinate of the vector to multiply
        `z` - z coordinate of the vector to multiply
      Returns:
        y coordinate transformation result

    - #### transformVZ

          public final float transformVZ​(float x,
                                         float y,
                                         float z)

      Computes the z component of this*(x,y,z,0).
      Parameters:
        `x` - x coordinate of the vector to multiply
        `y` - y coordinate of the vector to multiply
        `z` - z coordinate of the vector to multiply
      Returns:
        z coordinate transformation result

    - #### transformTransposeVX

          public final float transformTransposeVX​(float x,
                                                  float y,
                                                  float z)

      Computes the x component of (this^T)*(x,y,z,0).
      Parameters:
        `x` - x coordinate of the vector to multiply
        `y` - y coordinate of the vector to multiply
        `z` - z coordinate of the vector to multiply
      Returns:
        x coordinate transformation result

    - #### transformTransposeVY

          public final float transformTransposeVY​(float x,
                                                  float y,
                                                  float z)

      Computes the y component of (this^T)*(x,y,z,0).
      Parameters:
        `x` - x coordinate of the vector to multiply
        `y` - y coordinate of the vector to multiply
        `z` - z coordinate of the vector to multiply
      Returns:
        y coordinate transformation result

    - #### transformTransposeVZ

          public final float transformTransposeVZ​(float x,
                                                  float y,
                                                  float z)

      Computes the z component of (this^T)*(x,y,z,0).
      Parameters:
        `x` - x coordinate of the vector to multiply
        `y` - y coordinate of the vector to multiply
        `z` - z coordinate of the vector to multiply
      Returns:
        zcoordinate transformation result

    - #### transformPX

          public final float transformPX​(float x,
                                         float y,
                                         float z)

      Computes the x component of this*(x,y,z,1).
      Parameters:
        `x` - x coordinate of the vector to multiply
        `y` - y coordinate of the vector to multiply
        `z` - z coordinate of the vector to multiply
      Returns:
        x coordinate transformation result

    - #### transformPY

          public final float transformPY​(float x,
                                         float y,
                                         float z)

      Computes the y component of this*(x,y,z,1).
      Parameters:
        `x` - x coordinate of the vector to multiply
        `y` - y coordinate of the vector to multiply
        `z` - z coordinate of the vector to multiply
      Returns:
        y coordinate transformation result

    - #### transformPZ

          public final float transformPZ​(float x,
                                         float y,
                                         float z)

      Computes the z component of this*(x,y,z,1).
      Parameters:
        `x` - x coordinate of the vector to multiply
        `y` - y coordinate of the vector to multiply
        `z` - z coordinate of the vector to multiply
      Returns:
        z coordinate transformation result

    - #### translation

          public static final Matrix4 translation​(float x,
                                                  float y,
                                                  float z)

      Create a translation matrix for the specified vector.
      Parameters:
        `x` - x component of translation
        `y` - y component of translation
        `z` - z component of translation
      Returns:
        a new Matrix4 object representing the translation

    - #### rotateX

          public static final Matrix4 rotateX​(float theta)

      Creates a rotation matrix about the X axis.
      Parameters:
        `theta` - angle to rotate about the X axis in radians
      Returns:
        a new Matrix4 object representing the rotation

    - #### rotateY

          public static final Matrix4 rotateY​(float theta)

      Creates a rotation matrix about the Y axis.
      Parameters:
        `theta` - angle to rotate about the Y axis in radians
      Returns:
        a new Matrix4 object representing the rotation

    - #### rotateZ

          public static final Matrix4 rotateZ​(float theta)

      Creates a rotation matrix about the Z axis.
      Parameters:
        `theta` - angle to rotate about the Z axis in radians
      Returns:
        a new Matrix4 object representing the rotation

    - #### rotate

          public static final Matrix4 rotate​(float x,
                                             float y,
                                             float z,
                                             float theta)

      Creates a rotation matrix about the specified axis. The axis vector need not be normalized.
      Parameters:
        `x` - x component of the axis vector
        `y` - y component of the axis vector
        `z` - z component of the axis vector
        `theta` - angle to rotate about the axis in radians
      Returns:
        a new Matrix4 object representing the rotation

    - #### scale

          public static final Matrix4 scale​(float s)

      Create a uniform scaling matrix.
      Parameters:
        `s` - scale factor for all three axes
      Returns:
        a new Matrix4 object representing the uniform scale

    - #### scale

          public static final Matrix4 scale​(float sx,
                                            float sy,
                                            float sz)

      Creates a non-uniform scaling matrix.
      Parameters:
        `sx` - scale factor in the x dimension
        `sy` - scale factor in the y dimension
        `sz` - scale factor in the z dimension
      Returns:
        a new Matrix4 object representing the non-uniform scale

    - #### fromBasis

          public static final Matrix4 fromBasis​(OrthoNormalBasis basis)

      Creates a rotation matrix from an OrthonormalBasis.
      Parameters:
        `basis` -

    - #### lookAt

          public static final Matrix4 lookAt​(Point3 eye,
                                             Point3 target,
                                             Vector3 up)

      Creates a camera positioning matrix from the given eye and target points and up vector.
      Parameters:
        `eye` - location of the eye
        `target` - location of the target
        `up` - vector pointing upwards
      Returns:

    - #### blend

          public static final Matrix4 blend​(Matrix4 m0,
                                            Matrix4 m1,
                                            float t)