public final class MatrixM4x4F extends Object
A 4x4 mutable matrix type with float elements.
Values of type MatrixM4x4F are backed by direct memory, with the
rows and columns of the matrices being stored in column-major format. This
allows the matrices to be passed to OpenGL directly, without requiring
transposition.
Values of this type cannot be accessed safely from multiple threads without explicit synchronization.
See "Mathematics for 3D Game Programming and Computer Graphics" 2nd Ed for the derivations of most of the code in this class (ISBN: 1-58450-277-0).
See http://en.wikipedia.org/wiki/Row_equivalence#Elementary_row_operations for the three elementary operations defined on matrices.
| Modifier and Type | Class and Description |
|---|---|
static class |
MatrixM4x4F.ContextMM4F
The
ContextMM4F type contains the minimum storage required for
all of the functions of the MatrixM4x4F class. |
| Modifier and Type | Method and Description |
|---|---|
static <M extends MatrixWritable4x4FType> |
add(MatrixReadable4x4FType m0,
MatrixReadable4x4FType m1,
M out)
Elementwise add of matrices
m0 and m1. |
static <M extends MatrixWritable4x4FType & MatrixReadable4x4FType> |
addInPlace(M m0,
MatrixReadable4x4FType m1)
Elementwise add of matrices
m0 and m1, returning the result
in m0. |
static <M extends MatrixWritable4x4FType> |
addRowScaled(MatrixM4x4F.ContextMM4F context,
MatrixReadable4x4FType m,
int row_a,
int row_b,
int row_c,
double r,
M out)
Add the values in row
row_b to the values in row row_a
scaled by r, saving the resulting row in row row_c of the
matrix out. |
static <M extends MatrixWritable4x4FType & MatrixReadable4x4FType> |
addRowScaledInPlace(MatrixM4x4F.ContextMM4F context,
M m,
int row_a,
int row_b,
int row_c,
double r)
Add the values in row
row_b to the values in row row_a
scaled by r, saving the resulting row in row row_c of the
matrix m. |
static boolean |
compareElements(MatrixReadable4x4FType m0,
MatrixReadable4x4FType m1)
Compare matrices.
|
static <M extends MatrixWritable4x4FType> |
copy(MatrixReadable4x4FType input,
M output)
Copy the contents of the matrix
input to the matrix output,
completely replacing all elements. |
static double |
determinant(MatrixReadable4x4FType m)
Calculate the determinant of the matrix
m. |
static <M extends MatrixWritable4x4FType> |
exchangeRows(MatrixM4x4F.ContextMM4F context,
MatrixReadable4x4FType m,
int row_a,
int row_b,
M out)
Exchange two rows
row_a and row row_b of the matrix
m, saving the exchanged rows to out . |
static <M extends MatrixWritable4x4FType & MatrixReadable4x4FType> |
exchangeRowsInPlace(MatrixM4x4F.ContextMM4F context,
M m,
int row_a,
int row_b)
Exchange the row
row_a and row row_b of the matrix
m, saving the exchanged rows to m. |
static int |
hashElements(MatrixReadable4x4FType m)
Hash matrices.
|
static <M extends MatrixWritable4x4FType> |
invert(MatrixM4x4F.ContextMM4F context,
MatrixReadable4x4FType m,
M out)
Calculate the inverse of the matrix
m, saving the resulting matrix
to out. |
static <M extends MatrixWritable4x4FType & MatrixReadable4x4FType> |
invertInPlace(MatrixM4x4F.ContextMM4F context,
M m)
Calculate the inverse of the matrix
m, saving the resulting matrix
to m. |
static <M extends MatrixWritable4x4FType> |
lookAt(MatrixM4x4F.ContextMM4F context,
VectorReadable3FType origin,
VectorReadable3FType target,
VectorReadable3FType up,
M out_matrix)
Calculate a matrix representing a "camera" looking from the point
origin to the point target. |
static <M extends MatrixWritable4x4FType> |
makeRotation(double angle,
VectorReadable3FType axis,
M out)
Generate a matrix that represents a rotation of
angle radians
around the axis axis and save to out. |
static <M extends MatrixWritable4x4FType> |
makeTranslation2F(VectorReadable2FType v,
M out)
Generate a matrix that represents a translation of
(v.x, v.y) from
the origin, and save to out. |
static <M extends MatrixWritable4x4FType> |
makeTranslation2I(VectorReadable2IType v,
M out)
Generate a matrix that represents a translation of
(v.x, v.y) from
the origin, and save to out. |
static <M extends MatrixWritable4x4FType> |
makeTranslation3F(VectorReadable3FType v,
M out)
Generate a matrix that represents a translation of
(v.x, v.y, v.z)
from the origin, and save to out. |
static <M extends MatrixWritable4x4FType> |
makeTranslation3I(VectorReadable3IType v,
M out)
Generate a matrix that represents a translation of
(v.x, v.y, v.z)
from the origin, and save to out. |
static <M extends MatrixWritable4x4FType> |
multiply(MatrixReadable4x4FType m0,
MatrixReadable4x4FType m1,
M out)
Multiply the matrix
m0 with the matrix m1, writing the
result to out. |
static <M extends MatrixWritable4x4FType & MatrixReadable4x4FType> |
multiplyInPlace(M m0,
MatrixReadable4x4FType m1)
Multiply the matrix
m0 with the matrix m1, writing the
result to m0. |
static <V extends VectorWritable4FType> |
multiplyVector4F(MatrixM4x4F.ContextMM4F context,
MatrixReadable4x4FType m,
VectorReadable4FType v,
V out)
Multiply the matrix
m with the vector v, writing the
resulting vector to out. |
static <M extends MatrixWritable4x4FType> |
scale(MatrixReadable4x4FType m,
double r,
M out)
Scale all elements of the matrix
m by the scaling value r,
saving the result in out. |
static <M extends MatrixWritable4x4FType & MatrixReadable4x4FType> |
scaleInPlace(M m,
double r)
Scale all elements of the matrix
m by the scaling value r,
saving the result in m. |
static <M extends MatrixWritable4x4FType> |
scaleRow(MatrixM4x4F.ContextMM4F context,
MatrixReadable4x4FType m,
int row,
double r,
M out)
Scale row
row of the matrix m by r , saving the
result to row r of out. |
static <M extends MatrixWritable4x4FType & MatrixReadable4x4FType> |
scaleRowInPlace(MatrixM4x4F.ContextMM4F context,
M m,
int row,
double r)
Scale row
row of the matrix m by r , saving the
result to row r of m. |
static <M extends MatrixWritable4x4FType> |
setIdentity(M m)
Set the given matrix
m to the identity matrix. |
static <M extends MatrixWritable4x4FType> |
setZero(M m)
Set the given matrix
m to the zero matrix. |
static void |
showElements(MatrixReadable4x4FType m,
StringBuilder sb)
Show matrices.
|
static double |
trace(MatrixReadable4x4FType m)
Return the trace of the matrix
m. |
static <M extends MatrixWritable4x4FType> |
transpose(MatrixReadable4x4FType m,
M out)
Transpose the given matrix
m, writing the resulting matrix to
out. |
static <M extends MatrixWritable4x4FType & MatrixReadable4x4FType> |
transposeInPlace(M m)
Transpose the given matrix
m, writing the resulting matrix to
m. |
public static <M extends MatrixWritable4x4FType> M add(MatrixReadable4x4FType m0, MatrixReadable4x4FType m1, M out)
m0 and m1.M - The precise type of matrixm0 - The left input matrixm1 - The right input matrixout - The output matrixoutpublic static <M extends MatrixWritable4x4FType & MatrixReadable4x4FType> M addInPlace(M m0, MatrixReadable4x4FType m1)
m0 and m1, returning the result
in m0.M - The precise type of matrixm0 - The left input matrixm1 - The right input matrixpublic static <M extends MatrixWritable4x4FType & MatrixReadable4x4FType> M addRowScaledInPlace(MatrixM4x4F.ContextMM4F context, M m, int row_a, int row_b, int row_c, double r)
Add the values in row row_b to the values in row row_a
scaled by r, saving the resulting row in row row_c of the
matrix m.
This is one of the three elementary operations defined on matrices.
M - The precise type of matrixcontext - Preallocated storagem - The input matrixrow_a - The row on the lefthand side of the additionrow_b - The row on the righthand side of the additionrow_c - The destination rowr - The scaling valuempublic static <M extends MatrixWritable4x4FType> M addRowScaled(MatrixM4x4F.ContextMM4F context, MatrixReadable4x4FType m, int row_a, int row_b, int row_c, double r, M out)
Add the values in row row_b to the values in row row_a
scaled by r, saving the resulting row in row row_c of the
matrix out. The function uses storage preallocated in context to avoid any new allocations.
This is one of the three elementary operations defined on matrices.
M - The precise type of matrixcontext - Preallocated storagem - The input matrixrow_a - The row on the lefthand side of the additionrow_b - The row on the righthand side of the additionrow_c - The destination rowr - The scaling valueout - The output matrixoutpublic static <M extends MatrixWritable4x4FType> M copy(MatrixReadable4x4FType input, M output)
input to the matrix output,
completely replacing all elements.M - The precise type of matrixinput - The input vectoroutput - The output vectoroutputpublic static double determinant(MatrixReadable4x4FType m)
m.m - The input matrixpublic static <M extends MatrixWritable4x4FType & MatrixReadable4x4FType> M exchangeRowsInPlace(MatrixM4x4F.ContextMM4F context, M m, int row_a, int row_b)
Exchange the row row_a and row row_b of the matrix
m, saving the exchanged rows to m. The function uses
storage preallocated in context to avoid allocating memory.
This is one of the three elementary operations defined on matrices.
M - The precise type of matrixcontext - Preallocated storagem - The input matrixrow_a - The first rowrow_b - The second rowmpublic static <M extends MatrixWritable4x4FType> M exchangeRows(MatrixM4x4F.ContextMM4F context, MatrixReadable4x4FType m, int row_a, int row_b, M out)
Exchange two rows row_a and row row_b of the matrix
m, saving the exchanged rows to out .
The function
uses storage preallocated in context to avoid allocating memory.
This is one of the three elementary operations defined on matrices.
M - The precise type of matrixcontext - Preallocated storagem - The input matrixrow_a - The first rowrow_b - The second rowout - The output matrixoutpublic static <M extends MatrixWritable4x4FType & MatrixReadable4x4FType> boolean invertInPlace(MatrixM4x4F.ContextMM4F context, M m)
m, saving the resulting matrix
to m. The function returns Some(out) iff it was possible to
invert the matrix, and None otherwise. It is not possible to invert
a matrix that has a determinant of 0. The function uses
preallocated storage in context to avoid allocating memory. If the
function returns None, m is untouched.M - The precise type of matrixcontext - Preallocated storagem - The input matrixtrue iff the matrix was invertibledeterminant(MatrixReadable4x4FType)public static <M extends MatrixWritable4x4FType> boolean invert(MatrixM4x4F.ContextMM4F context, MatrixReadable4x4FType m, M out)
m, saving the resulting matrix
to out. The function returns Some(out) iff it was possible
to invert the matrix, and None otherwise. It is not possible to
invert a matrix that has a determinant of 0. The function uses
preallocated storage in context to avoid allocating memory. If the
function returns None, m is untouched.M - The precise type of matrixcontext - Preallocated storagem - The input matrixout - The output matrixtrue iff the matrix was invertibledeterminant(MatrixReadable4x4FType)public static <M extends MatrixWritable4x4FType> void lookAt(MatrixM4x4F.ContextMM4F context, VectorReadable3FType origin, VectorReadable3FType target, VectorReadable3FType up, M out_matrix)
Calculate a matrix representing a "camera" looking from the point
origin to the point target. target must represent
the "up" vector for the camera. Usually, this is simply a unit vector
(0, 1, 0) representing the Y axis.
The function uses
preallocated storage from context.
The view is expressed
as a rotation and translation matrix, written to out_matrix.
M - The precise type of matrixcontext - Preallocated storageout_matrix - The output matrixorigin - The position of the viewertarget - The target being viewedup - The up vectorpublic static <M extends MatrixWritable4x4FType> M makeRotation(double angle, VectorReadable3FType axis, M out)
Generate a matrix that represents a rotation of angle radians
around the axis axis and save to out.
The function assumes a right-handed coordinate system and therefore a positive rotation around any axis represents a counter-clockwise rotation around that axis.
M - The precise type of matrixangle - The angle in radiansaxis - The axisout - The output matrixoutpublic static <M extends MatrixWritable4x4FType> M makeTranslation2F(VectorReadable2FType v, M out)
(v.x, v.y) from
the origin, and save to out.M - The precise type of matrixv - The translation vectorout - The output matrixoutpublic static <M extends MatrixWritable4x4FType> M makeTranslation2I(VectorReadable2IType v, M out)
(v.x, v.y) from
the origin, and save to out.M - The precise type of matrixv - The translation vectorout - The output matrixoutpublic static <M extends MatrixWritable4x4FType> M makeTranslation3F(VectorReadable3FType v, M out)
(v.x, v.y, v.z)
from the origin, and save to out.M - The precise type of matrixv - The translation vectorout - The output matrixoutpublic static <M extends MatrixWritable4x4FType> M makeTranslation3I(VectorReadable3IType v, M out)
(v.x, v.y, v.z)
from the origin, and save to out.M - The precise type of matrixv - The translation vectorout - The output matrixoutpublic static <M extends MatrixWritable4x4FType> M multiply(MatrixReadable4x4FType m0, MatrixReadable4x4FType m1, M out)
m0 with the matrix m1, writing the
result to out.M - The precise type of matrixm0 - The left input vectorm1 - The right input vectorout - The output vectoroutpublic static <M extends MatrixWritable4x4FType & MatrixReadable4x4FType> M multiplyInPlace(M m0, MatrixReadable4x4FType m1)
m0 with the matrix m1, writing the
result to m0.M - The precise type of matrixm0 - The left input vectorm1 - The right input vectoroutpublic static <V extends VectorWritable4FType> V multiplyVector4F(MatrixM4x4F.ContextMM4F context, MatrixReadable4x4FType m, VectorReadable4FType v, V out)
m with the vector v, writing the
resulting vector to out. The function uses preallocated storage in
context to avoid allocating memory.V - The precise type of writable vectorcontext - Preallocated storagem - The input matrixv - The input vectorout - The output vectoroutpublic static <M extends MatrixWritable4x4FType> M scale(MatrixReadable4x4FType m, double r, M out)
m by the scaling value r,
saving the result in out.M - The precise type of matrixout - The output matrixm - The input matrixr - The scaling valueoutpublic static <M extends MatrixWritable4x4FType & MatrixReadable4x4FType> M scaleInPlace(M m, double r)
m by the scaling value r,
saving the result in m.M - The precise type of matrixm - The input matrixr - The scaling valuempublic static <M extends MatrixWritable4x4FType & MatrixReadable4x4FType> M scaleRowInPlace(MatrixM4x4F.ContextMM4F context, M m, int row, double r)
Scale row row of the matrix m by r , saving the
result to row r of m. The function uses preallocated
storage in context to avoid allocating memory.
This is one of the three elementary operations defined on matrices.
M - The precise type of matrixcontext - Preallocated storagem - The input matrixrow - The index of the row (0 <= row < 4)r - The scaling valuempublic static <M extends MatrixWritable4x4FType> M scaleRow(MatrixM4x4F.ContextMM4F context, MatrixReadable4x4FType m, int row, double r, M out)
Scale row row of the matrix m by r , saving the
result to row r of out. The function uses preallocated
storage in context to avoid allocating memory.
This is one of the three elementary operations defined on matrices.
M - The precise type of matrixcontext - Preallocated storagem - The input matrixrow - The index of the row (0 <= row < 4)r - The scaling valueout - The output matrixoutpublic static <M extends MatrixWritable4x4FType> M setIdentity(M m)
m to the identity matrix.M - The precise type of matrixm - The input matrixmpublic static <M extends MatrixWritable4x4FType> M setZero(M m)
m to the zero matrix.M - The precise type of matrixm - The matrixmpublic static double trace(MatrixReadable4x4FType m)
m. The trace is defined as the sum
of the diagonal elements of the matrix.m - The input matrixpublic static <M extends MatrixWritable4x4FType> M transpose(MatrixReadable4x4FType m, M out)
m, writing the resulting matrix to
out.M - The precise type of matrixm - The input matrixout - The output matrixoutpublic static <M extends MatrixWritable4x4FType & MatrixReadable4x4FType> M transposeInPlace(M m)
m, writing the resulting matrix to
m.M - The precise type of matrixm - The input matrixmpublic static boolean compareElements(MatrixReadable4x4FType m0, MatrixReadable4x4FType m1)
m0 - The left matrixm1 - The right matrixtrue if all elements of m0 are equal to m1.public static int hashElements(MatrixReadable4x4FType m)
m - The input matrixmpublic static void showElements(MatrixReadable4x4FType m, StringBuilder sb)
m in square-bracketed
matrix form.m - The input matrixsb - The string builderCopyright © 2015 <code@io7m.com> http://io7m.com