Matrix

Base template for all matrix-types.

struct Matrix (
type
int rows_
int cols_
) if (
(rows_ > 0) &&
(cols_ > 0)
) {}

Constructors

this
this(Args args)
this(T mat)
this(mt value)

Constructs the matrix: If a single value is passed, the matrix will be cleared with this value (each column in each row will contain this value). If a matrix with more rows and columns is passed, the matrix will be the upper left nxm matrix. If a matrix with less rows 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.

Alias This

matrix

Members

Aliases

mt
alias mt = type
Undocumented in source.
ok
deprecated alias ok = isFinite
Undocumented in source.

Functions

clear
void clear(mt value)

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

det
mt det()
Undocumented in source. Be warned that the author may not have intended to support it.
det
mt det()
Undocumented in source. Be warned that the author may not have intended to support it.
det
mt det()

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

inverse
Matrix inverse()

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

invert
void invert()

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

isFinite
bool isFinite()

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

makeIdentity
void makeIdentity()

Makes the current matrix an identity matrix.

opBinary
Matrix!(mt, rows, T.cols) opBinary(T inp)
Undocumented in source. Be warned that the author may not have intended to support it.
opBinary
Vector!(mt, rows) opBinary(T inp)
Undocumented in source. Be warned that the author may not have intended to support it.
opBinary
Matrix opBinary(mt inp)
Undocumented in source. Be warned that the author may not have intended to support it.
opBinary
Matrix opBinary(Matrix inp)
Undocumented in source. Be warned that the author may not have intended to support it.
opBinaryRight
Matrix opBinaryRight(mt inp)
Undocumented in source. Be warned that the author may not have intended to support it.
opOpAssign
void opOpAssign(mt inp)
Undocumented in source. Be warned that the author may not have intended to support it.
opOpAssign
void opOpAssign(Matrix inp)
Undocumented in source. Be warned that the author may not have intended to support it.
opOpAssign
void opOpAssign(Matrix inp)
Undocumented in source. Be warned that the author may not have intended to support it.
ptr
auto ptr()

Returns the pointer to the stored values as OpenGL requires it. Note this will return a pointer to a row-major matrix, this means you've to set the transpose argument to GL_TRUE when passing it to OpenGL.

rotate
Matrix rotate(real alpha, Vector!(mt, 3) axis)
Undocumented in source. Be warned that the author may not have intended to support it.
rotateX
Matrix rotateX(real alpha)

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

rotateY
Matrix rotateY(real alpha)

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

rotateZ
Matrix rotateZ(real alpha)

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

rotation
void rotation(Matrix!(mt, 3, 3) rot)

Copies rot into the upper left corner, the translation (nxn matrices, n >= 3).

rotation
Matrix!(mt, 3, 3) rotation()

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

scale
Matrix scale(mt x, mt y)
Undocumented in source. Be warned that the author may not have intended to support it.
scale
Matrix scale(mt x, mt y, mt z)

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

scale
void scale(mt[] values)

Sets the scale of the matrix (nxn matrices, n >= 3).

scale
void scale(Matrix mat)

Copyies the scale from mat to the current matrix (nxn matrices, n >= 3).

scale
Matrix scale()

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

toPrettyString
string toPrettyString()

Returns the current matrix as pretty formatted string.

toString
string toString()

Returns the current matrix formatted as flat string.

translate
Matrix translate(mt x, mt y, mt z)
Matrix translate(Vector!(mt, 3) v)

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

translation
void translation(mt[] values)

Sets the translation of the matrix (nxn matrices, n >= 3).

translation
void translation(Matrix mat)

Copyies the translation from mat to the current matrix (nxn matrices, n >= 3).

translation
Matrix translation()

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

transpose
void transpose()

Transposes the current matrix;

transposed
Matrix!(mt, cols, rows) transposed()

Returns a transposed copy of the matrix.

Static functions

identity
Matrix identity()

Returns a identity matrix.

isCompatibleMatrixImpl
void isCompatibleMatrixImpl(Matrix!(mt, r, c) m)
Undocumented in source. Be warned that the author may not have intended to support it.
isCompatibleVectorImpl
void isCompatibleVectorImpl(Vector!(mt, d) vec)
Undocumented in source. Be warned that the author may not have intended to support it.
lookAt
Matrix lookAt(Vector!(mt, 3) eye, Vector!(mt, 3) target, Vector!(mt, 3) up)

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

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

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

orthographicInverse
Matrix orthographicInverse(mt left, mt right, mt bottom, mt top, mt near, mt far)

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

perspective
Matrix perspective(mt width, mt height, mt fov, mt near, mt far)
Matrix perspective(mt left, mt right, mt bottom, mt top, mt near, mt far)

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

persperctiveInverse
Matrix persperctiveInverse(mt width, mt height, mt fov, mt near, mt far)
Matrix persperctiveInverse(mt left, mt right, mt bottom, mt top, mt near, mt far)

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

rotation
Matrix rotation(real alpha, Vector!(mt, 3) axis)
Matrix rotation(real alpha, mt x, mt y, mt z)

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

scaling
Matrix scaling(mt x, mt y)
Undocumented in source. Be warned that the author may not have intended to support it.
scaling
Matrix scaling(mt x, mt y, mt z)

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

translation
Matrix translation(mt x, mt y, mt z)
Matrix translation(Vector!(mt, 3) v)

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

xRotation
Matrix xRotation(real alpha)

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

yRotation
Matrix yRotation(real alpha)

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

zRotation
Matrix zRotation(real alpha)

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

Static variables

cols
int cols;

Holds the number of columns;

rows
int rows;

Holds the number of rows;

Templates

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

Variables

matrix
mt[cols][rows] matrix;

Holds the matrix row-major in memory.

Parameters

type

all values get stored as this type

rows_

rows of the matrix

cols_

columns of the matrix

Examples

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

Meta