Matrix4x4

public struct Matrix4x4<Scalar> : SquareMatrixType, CustomStringConvertible where Scalar : DivisibleArithmetic, Scalar : Real

Plain 4-row 4-column Matrix with real components.

  • Returns a 4x4 identity matrix.

    Declaration

    Swift

    public static var identity: `Self` { get }
  • M

    The full type of this matrix’s backing, as a tuple of columns.

    Declaration

    Swift

    public typealias M = (Row, Row, Row, Row)
  • Row

    The type of this matrix’s row.

    Declaration

    Swift

    public typealias Row = (Scalar, Scalar, Scalar, Scalar)
  • The type of this matrix’s column.

    Declaration

    Swift

    public typealias Column = (Scalar, Scalar, Scalar, Scalar)
  • m

    Gets or sets all coefficients of this matrix as a single 4x4 tuple.

    Declaration

    Swift

    public var m: M
  • r0

    The first row of this matrix

    Equivalent to self.m.0.

    Declaration

    Swift

    public var r0: Row { get set }
  • r1

    The second row of this matrix

    Equivalent to self.m.1.

    Declaration

    Swift

    public var r1: Row { get set }
  • r2

    The third row of this matrix

    Equivalent to self.m.2.

    Declaration

    Swift

    public var r2: Row { get set }
  • r3

    The fourth row of this matrix.

    Equivalent to self.m.3.

    Declaration

    Swift

    public var r3: Row { get set }
  • c0

    The first column of this matrix

    Equivalent to (self.r0.0, self.r1.0, self.r2.0, self.r3.0).

    Declaration

    Swift

    public var c0: Column { get set }
  • c1

    The second column of this matrix

    Equivalent to (self.r0.1, self.r1.1, self.r2.1, self.r3.1).

    Declaration

    Swift

    public var c1: Column { get set }
  • c2

    The third column of this matrix

    Equivalent to (self.r0.2, self.r1.2, self.r2.2, self.r3.2).

    Declaration

    Swift

    public var c2: Column { get set }
  • c3

    The fourth column of this matrix

    Equivalent to (self.r0.3, self.r1.3, self.r2.3, self.r3.3).

    Declaration

    Swift

    public var c3: Column { get set }
  • Gets the first row of this matrix in a Vector4.

    Declaration

    Swift

    public var r0Vec: Vector4<Scalar> { get }
  • Gets the second row of this matrix in a Vector4.

    Declaration

    Swift

    public var r1Vec: Vector4<Scalar> { get }
  • Gets the third row of this matrix in a Vector4.

    Declaration

    Swift

    public var r2Vec: Vector4<Scalar> { get }
  • Gets the fourth row of this matrix in a Vector4.

    Declaration

    Swift

    public var r3Vec: Vector4<Scalar> { get }
  • Gets the first column of this matrix in a Vector4.

    Declaration

    Swift

    public var c0Vec: Vector4<Scalar> { get }
  • Gets the second column of this matrix in a Vector4.

    Declaration

    Swift

    public var c1Vec: Vector4<Scalar> { get }
  • Gets the third column of this matrix in a Vector4.

    Declaration

    Swift

    public var c2Vec: Vector4<Scalar> { get }
  • Gets the fourth column of this matrix in a Vector4.

    Declaration

    Swift

    public var c3Vec: Vector4<Scalar> { get }
  • Returns the number of rows in this matrix.

    For Matrix4x4 instances, this value is always 4.

    Declaration

    Swift

    public let rowCount: Int
  • Returns the number of columns in this matrix.

    For Matrix4x4 instances, this value is always 4.

    Declaration

    Swift

    public let columnCount: Int
  • Subscripts into this matrix using column/row numbers.

    Declaration

    Swift

    public subscript(column: Int, row: Int) -> Scalar { get set }
  • Returns the trace of this matrix, i.e. the sum of all the values on its diagonal:

    self[0, 0] + self[1, 1] + self[2, 2] + self[3, 3]
    

    Declaration

    Swift

    public var trace: Scalar { get }
  • Returns a String that represents this instance.

    Declaration

    Swift

    public var description: String { get }
  • Initializes an identity matrix.

    Declaration

    Swift

    public init()
  • Initializes a new matrix with the given row values.

    Declaration

    Swift

    public init(rows: (Row, Row, Row, Row))
  • Initializes a new matrix with the given Vector4 values as the values for each row.

    Declaration

    Swift

    public init<Vector: Vector4Type>(
        rows: (Vector, Vector, Vector, Vector)
    ) where Vector.Scalar == Scalar
  • Initializes a matrix with the given scalar on all positions.

    Declaration

    Swift

    public init(repeating scalar: Scalar)
  • Initializes a matrix with the given scalars laid out on the diagonal, with all remaining elements being .zero.

    Declaration

    Swift

    public init(diagonal: (Scalar, Scalar, Scalar, Scalar))
  • Initializes a matrix with the given scalar laid out on the diagonal, with all remaining elements being .zero.

    Declaration

    Swift

    public init(diagonal: Scalar)
  • Returns the determinant of this matrix.

    Declaration

    Swift

    @inlinable
    public func determinant() -> Scalar
  • Transforms a given vector as a point, applying scaling, rotation and translation to the vector.

    Declaration

    Swift

    public func transformPoint<Vector: Vector4FloatingPoint>(
        _ vec: Vector
    ) -> Vector where Vector.Scalar == Scalar
  • Transforms a given vector as a point, applying scaling, rotation and translation to the vector.

    Declaration

    Swift

    public func transformPoint<Vector: Vector3FloatingPoint>(
        _ vec: Vector
    ) -> Vector where Vector.Scalar == Scalar
  • Transforms a given vector, applying scaling, rotation and translation to the vector.

    The matrix is transformed as a vector and is not normalized by the W vector.

    Declaration

    Swift

    public func transformVector<Vector: Vector3FloatingPoint>(
        _ vec: Vector
    ) -> Vector where Vector.Scalar == Scalar
  • Returns a new Matrix4x4 that is a transposition of this matrix.

    Declaration

    Swift

    public func transposed() -> Matrix4x4<Scalar>
  • Performs an in-place transposition of this matrix.

    Declaration

    Swift

    public mutating func transpose()
  • Returns the inverse of this matrix.

    If this matrix has no inversion, nil is returned, instead.

    Declaration

    Swift

    public func inverted() -> `Self`?
  • Creates a matrix that when applied to a vector, scales each coordinate by the given amount.

    Declaration

    Swift

    public static func makeScale(x: Scalar, y: Scalar, z: Scalar) -> Matrix4x4<Scalar>
  • Creates a matrix that when applied to a vector, scales each coordinate by the corresponding coordinate on a supplied vector.

    Declaration

    Swift

    public static func makeScale<Vector: Vector3Type>(
        _ vec: Vector
    ) -> Self where Vector.Scalar == Scalar
  • Creates an X rotation matrix that when applied to a vector, rotates it around the X axis by a specified radian amount.

    Declaration

    Swift

    public static func makeXRotation(_ angleInRadians: Scalar) -> Matrix4x4<Scalar>
  • Creates an Y rotation matrix that when applied to a vector, rotates it around the Y axis by a specified radian amount.

    Declaration

    Swift

    public static func makeYRotation(_ angleInRadians: Scalar) -> Matrix4x4<Scalar>
  • Creates a Z rotation matrix that when applied to a vector, rotates it around the Z axis by a specified radian amount.

    Declaration

    Swift

    public static func makeZRotation(_ angleInRadians: Scalar) -> Matrix4x4<Scalar>
  • Creates a translation matrix that when applied to a vector, moves it according to the specified amounts.

    Declaration

    Swift

    public static func makeTranslation(x: Scalar, y: Scalar, z: Scalar) -> Matrix4x4<Scalar>
  • Creates a translation matrix that when applied to a vector, moves it according to the specified amounts.

    Declaration

    Swift

    public static func makeTranslation<Vector: Vector3Type>(
        _ vec: Vector
    ) -> Self where Vector.Scalar == Scalar
  • Performs a matrix addition between lhs and rhs and returns the result.

    Declaration

    Swift

    public static func + (lhs: `Self`, rhs: `Self`) -> Matrix4x4<Scalar>
  • Performs a matrix subtraction between lhs and rhs and returns the result.

    Declaration

    Swift

    public static func - (lhs: `Self`, rhs: `Self`) -> Matrix4x4<Scalar>
  • Negates (i.e. flips) the signs of all the values of this matrix.

    Declaration

    Swift

    public prefix static func - (value: `Self`) -> Matrix4x4<Scalar>
  • Performs a scalar multiplication between lhs and rhs and returns the result.

    Declaration

    Swift

    public static func * (lhs: `Self`, rhs: Scalar) -> Matrix4x4<Scalar>
  • Performs a scalar division between the elements of lhs and rhs and returns the result.

    Declaration

    Swift

    public static func / (lhs: `Self`, rhs: Scalar) -> Matrix4x4<Scalar>
  • Performs a matrix multiplication between lhs and rhs and returns the result.

    Declaration

    Swift

    public static func * (lhs: `Self`, rhs: `Self`) -> Matrix4x4<Scalar>
  • Performs an in-place matrix multiplication between lhs and rhs and stores the result back to lhs.

    Declaration

    Swift

    public static func *= (lhs: inout `Self`, rhs: `Self`)
  • Returns true iff all coefficients from lhs and rhs are equal.

    Declaration

    Swift

    public static func == (lhs: `Self`, rhs: `Self`) -> Bool