Matrix

Base template for all matrix - types.

struct Matrix (
type
int numCols
int numRows
) if (
(numCols > 1) &&
(numRows > 1)
) {}

Constructors

this
this(Args args)

Constructs the matrix: If a single value is passed, the matrix will be cleared with this value ( each column in each col will contain this value ). If a matrix with more cols and columns is passed, the matrix will be the upper left nxm matrix. If a matrix with less cols and columns is passed, the passed matrix will be stored in the upper left of an identity matrix. It's also allowed to pass vectors and scalars at a time, but the vectors dimension must match the number of columns and align correctly.

this
this(T mat)

Construct a Matrix from another Matrix, equal sized or bigger

this
this(T mat)

Construct a Matrix from another Matrix, smaler sized

this
this(valueType value)

Construct a Matrix from a single value

Alias This

data

Members

Aliases

det
alias det = determinant

mat2

det
alias det = determinant
Undocumented in source.
det
alias det = determinant

Returns the determinant of the current data ( 2x2, 3x3 and 4x4 matrices ).

rotationX
alias rotationX = rotationA!(1, 2)
Undocumented in source.
rotationY
alias rotationY = rotationA!(2, 0)
Undocumented in source.
rotationZ
alias rotationZ = rotationA!(0, 1)
Undocumented in source.
toPrettyString
alias toPrettyString = asPrettyString
Undocumented in source.
toString
alias toString = asString
Undocumented in source.
valueType
alias valueType = type
Undocumented in source.
vectorType
alias vectorType = Vector!(type, rows)
Undocumented in source.

Functions

clear
void clear(valueType value)

Sets all values of the matrix to value ( each column in each col will contain this value ).

invert
void invert()

Inverts the current matrix ( nxn matrices, n <= 4 ).

makeDiagonal
void makeDiagonal(valueType val)

Makes the current matrix an scaled identity matrix

makeIdentity
void makeIdentity()

Makes the current matrix an identity matrix

opBinary
auto opBinary(T s)

Componentwise binary matrix-skalar operation: addition, subtraction, multiplication, division

opBinary
auto opBinary(V vec)

Matrix-vector multiplication

opBinary
Matrix opBinary(Matrix mat)

matrix-matrix componentwise operations addition, subtraction and division, using vector-vector operations of all colums

opBinary
Matrix opBinary(M mat)

matrix-matrix multiplication, using matrix-vector multiplication for each column of mat

opBinaryRight
auto opBinaryRight(T s)

Componentwise binary skalar-matrix operation: addition, subtraction, multiplication, division

opBinaryRight
auto opBinaryRight(V vec)

Vector-Matrix multiplication

opCast
bool opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opOpAssign
void opOpAssign(T val)
Undocumented in source. Be warned that the author may not have intended to support it.
rotate
Matrix rotate(real angle)

Rotate the current matrix arround an arbitrary axis

rotate
Matrix rotate(real angle, Vector!(valueType, 3) axis)

Rotate the current matrix arround an arbitrary axis

rotateX
Matrix rotateX(real angle)

Rotates the current matrix around the x - axis and returns $( I this ) ( nxn matrices, n >= 3 ).

rotateY
Matrix rotateY(real angle)

Rotates the current matrix around the y - axis and returns $( I this ) ( nxn matrices, n >= 3 ).

rotateZ
Matrix rotateZ(real angle)

Rotates the current matrix around the z - axis and returns $( I this ) ( nxn matrices, n >= 3 ).

rotation
Matrix!(valueType, 3, 3) rotation()

Returns an identity matrix with the current rotation applied ( nxn matrices, n >= 3 ).

scale
Matrix scale(valueType x)

scale an existing matrix

scale
Matrix scale(valueType x, valueType y)

scale an existing matrix

scale
Matrix scale(valueType x, valueType y, valueType z)

Applys a scale to the current matrix and returns $( I this ) ( 3x3 and 4x4 matrices ).

scale
Matrix scale()

Returns an identity matrix with the current scale applied ( nxn matrices, n >= 3 ).

translate
Matrix translate(valueType x)

translate an existing matrix

translate
Matrix translate(valueType x, valueType y)

translate an existing matrix

translate
Matrix translate(valueType x, valueType y, valueType z)

Applys a translation on the current matrix and returns $( I this ) ( 3x3 and 4x4 matrices ).

translation
Matrix translation()

Returns an identity matrix with the current translation applied ( nxn matrices, n >= 3 ) ..

transpose
void transpose()

Transposes the current matrix TODO : as free function and use here

Properties

asPrettyString
string asPrettyString [@property getter]

Returns the current matrix as pretty formatted string. TODO : Check This

asString
string asString [@property getter]

Returns the current matrix formatted as flat string.

determinant
valueType determinant [@property getter]

mat2

determinant
valueType determinant [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
determinant
valueType determinant [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
identity
Matrix identity [@property getter]

Returns a identity matrix.

inverse
Matrix inverse [@property getter]

Returns an inverted copy of the current matrix ( nxn matrices, n <= 4 ).

ok
bool ok [@property getter]

Returns true if all values are not nan and finite, otherwise false.

ptr
auto ptr [@property getter]

Returns the pointer to the stored values as OpenGL requires it. Note this will return a pointer to a $( RED column - major ) matrix, $( RED this is the OpneGL convention and expected in programs via Uniforms or UBOs ).

transposed
Matrix transposed [@property getter]

Returns a transposed copy of the matrix. TODO : Remove this, create a function which returns a transposed matrix like Wrong logic anyway, as transpose( mat3x2 ) = mat2x3

Static functions

inverseOrthographic
Matrix inverseOrthographic(valueType left, valueType right, valueType bottom, valueType top, valueType near, valueType far)

Returns an inverse ortographic matrix ( 4x4 and floating - point matrices only ).

inversePerspective
Matrix inversePerspective(valueType fovy, valueType aspect, valueType near, valueType far)

Construct an inverse, symmetric perspective matrix ( 4x4 and floating - point matrices only ).

inversePerspective
Matrix inversePerspective(valueType left, valueType right, valueType bottom, valueType top, valueType near, valueType far)

Construct an inverse, optionally non-symmetric perspective matrix

isCompatibleMatrixImpl
void isCompatibleMatrixImpl(Matrix!(valueType, col, row) mat)
Undocumented in source. Be warned that the author may not have intended to support it.
isCompatibleVectorImpl
void isCompatibleVectorImpl(Vector!(valueType, dim) vec)
Undocumented in source. Be warned that the author may not have intended to support it.
lookAt
Matrix lookAt(Vector!(valueType, 3) eye, Vector!(valueType, 3) target, Vector!(valueType, 3) up)

Construct a look at matrix ( 4x4 and floating - point matrices only ).

orthographic
Matrix orthographic(valueType left, valueType right, valueType bottom, valueType top, valueType near, valueType far)

Construct an orthographic matrix ( 4x4 and floating - point matrices only ).

perspective
Matrix perspective(valueType fovy, valueType aspect, valueType near, valueType far)

Construct a symmetric perspective matrix ( 4x4 and floating - point matrices only ).

perspective
Matrix perspective(valueType left, valueType right, valueType bottom, valueType top, valueType near, valueType far)

Construct an optionally non-symmetric perspective matrix

rotation
Matrix rotation(real angle)

Returns an identity matrix with an applied 2D rotation.

rotation
Matrix rotation(real angle, Vector!(valueType, 3) axis)

Returns an identity matrix with an applied rotate_axis around an arbitrary axis ( nxn matrices, n >= 3 ).

rotation
Matrix rotation(real angle, valueType x, valueType y, valueType z)
Undocumented in source. Be warned that the author may not have intended to support it.
rotationA
Matrix rotationA(real angle)

Returns an identity matrix with an applied rotation around the A-Canonical - axis ( nxn matrices, n >= 3 ).

scaling
Matrix scaling(valueType x)

scaling, static construction of a scaling matrix

scaling
Matrix scaling(valueType x, valueType y)

scaling, static construction of a scaling matrix

scaling
Matrix scaling(valueType x, valueType y, valueType z)

Returns a scaling matrix ( 3x3 and 4x4 matrices );

translation
Matrix translation(valueType x)

translation, static construction of a translation matrix

translation
Matrix translation(valueType x, valueType y)

translation, static construction of a translation matrix

translation
Matrix translation(valueType x, valueType y, valueType z)

Returns a translation matrix ( 3x3 and 4x4 matrices ).

Static variables

cols
int cols;

Holds the number of cols;

rows
int rows;

Holds the number of columns;

Templates

isCompatibleMatrix
template isCompatibleMatrix(T)
Undocumented in source.
isCompatibleVector
template isCompatibleVector(T)
Undocumented in source.

Variables

data
vectorType[cols] data;

Holds the matrix $( RED column - major ) in memory. +//// Each Column is Vector of length row

Parameters

type

the value type of each matrix element

numCols

count of columns of the matrix

numRows

count of rows of the matrix

Examples

- - - alias Matrix!( float, 4, 4 ) mat4; alias Matrix!( double, 3, 4 ) mat34d; alias Matrix!( real, 2, 2 ) mat2r; - - -

Meta