justgook / alt-linear-algebra / AltMath.Matrix4

This library uses the convention that the prefix make is creating a new array,as without the prefix, you are applying some transform to an existing matrix.

Create


type alias Mat4 =
{ m11 : Basics.Float
, m21 : Basics.Float
, m31 : Basics.Float
, m41 : Basics.Float
, m12 : Basics.Float
, m22 : Basics.Float
, m32 : Basics.Float
, m42 : Basics.Float
, m13 : Basics.Float
, m23 : Basics.Float
, m33 : Basics.Float
, m43 : Basics.Float
, m14 : Basics.Float
, m24 : Basics.Float
, m34 : Basics.Float
, m44 : Basics.Float 
}

4x4 matrix type

identity : Mat4

A matrix with all 0s, except 1s on the diagonal.

Operations

inverse : Mat4 -> Maybe Mat4

Computes the inverse of any matrix. This is somewhat computationally intensive. If the matrix is not invertible, Nothing is returned.

inverseOrthonormal : Mat4 -> Mat4

Computes the inverse of the given matrix, assuming that the matrix is orthonormal. This algorithm is more efficient than general matrix inversion, and has no possibility of failing.

mul : Mat4 -> Mat4 -> Mat4

Matrix multiplcation: a * b

mulAffine : Mat4 -> Mat4 -> Mat4

Matrix multiplication, assuming a and b are affine: a * b

transpose : Mat4 -> Mat4

"Flip" the matrix across the diagonal by swapping row index and column index.

makeBasis : AltMath.Alternative.Record.Vector3.Vec3 -> AltMath.Alternative.Record.Vector3.Vec3 -> AltMath.Alternative.Record.Vector3.Vec3 -> Mat4

Creates a transform from a basis consisting of 3 linearly independent vectors.

transform : Mat4 -> AltMath.Alternative.Record.Vector3.Vec3 -> AltMath.Alternative.Record.Vector3.Vec3

Multiply a vector by a 4x4 matrix: m * v

Projections

makeFrustum : Basics.Float -> Basics.Float -> Basics.Float -> Basics.Float -> Basics.Float -> Basics.Float -> Mat4

Creates a matrix for a projection frustum with the given parameters.

Parameters:

makePerspective : Basics.Float -> Basics.Float -> Basics.Float -> Basics.Float -> Mat4

Creates a matrix for a perspective projection with the given parameters.

Parameters:

makeOrtho : Basics.Float -> Basics.Float -> Basics.Float -> Basics.Float -> Basics.Float -> Basics.Float -> Mat4

Creates a matrix for an orthogonal frustum projection with the given parameters.

Parameters:

makeOrtho2D : Basics.Float -> Basics.Float -> Basics.Float -> Basics.Float -> Mat4

Creates a matrix for a 2D orthogonal frustum projection with the given parameters. znear and zfar are assumed to be -1 and 1, respectively.

Parameters:

makeLookAt : AltMath.Alternative.Record.Vector3.Vec3 -> AltMath.Alternative.Record.Vector3.Vec3 -> AltMath.Alternative.Record.Vector3.Vec3 -> Mat4

Creates a transformation matrix for a camera.

Parameters:

Apply Transformations

rotate : Basics.Float -> AltMath.Alternative.Record.Vector3.Vec3 -> Mat4 -> Mat4

Concatenates a rotation in radians about an axis to the given matrix.

scale : AltMath.Alternative.Record.Vector3.Vec3 -> Mat4 -> Mat4

Concatenates a scaling to the given matrix.

scale3 : Basics.Float -> Basics.Float -> Basics.Float -> Mat4 -> Mat4

Concatenates a scaling to the given matrix.

translate : AltMath.Alternative.Record.Vector3.Vec3 -> Mat4 -> Mat4

Concatenates a translation to the given matrix.

translate3 : Basics.Float -> Basics.Float -> Basics.Float -> Mat4 -> Mat4

Concatenates a translation to the given matrix.

Create Transformations

makeRotate : Basics.Float -> AltMath.Alternative.Record.Vector3.Vec3 -> Mat4

Creates a transformation matrix for rotation in radians about the 3-element vector axis.

makeScale : AltMath.Alternative.Record.Vector3.Vec3 -> Mat4

Creates a transformation matrix for scaling each of the x, y, and z axes by the amount given in the corresponding element of the 3-element vector.

makeScale3 : Basics.Float -> Basics.Float -> Basics.Float -> Mat4

Creates a transformation matrix for scaling by 3 scalar values, one for each of the x, y, and z directions.

makeTranslate : AltMath.Alternative.Record.Vector3.Vec3 -> Mat4

Creates a transformation matrix for translating each of the x, y, and z axes by the amount given in the corresponding element of the 3-element vector.

makeTranslate3 : Basics.Float -> Basics.Float -> Basics.Float -> Mat4

Creates a transformation matrix for translating by 3 scalar values, one for each of the x, y, and z directions.

Conversions

toRecord : Mat4 -> Mat4

Convert a matrix to a record. Elements are given by their row and column indices, starting at 1, so m23 means the element in the second row, third column.

fromRecord : Mat4 -> Mat4

Convert a record to a matrix.