Matrix
4x4 row-major float matrix
It
Matrix object (16 floats, initialized to identity)
self {
F32 values[16]
bool operator==(const It& o) { for (int i=0;i<16;i++) if (values[i]!=o.values[i]) return false; return true; }
It operator+(const It& o) { It r; for (int i=0;i<16;i++) r.values[i]=values[i]+o.values[i]; return r; }
It operator-(const It& o) { It r; for (int i=0;i<16;i++) r.values[i]=values[i]-o.values[i]; return r; }
It operator*(const It& o) { It r; for (int row=0;row<4;row++) for (int col=0;col<4;col++) { r.values[row*4+col]=0.0f; for (int k=0;k<4;k++) r.values[row*4+col]+=values[row*4+k]*o.values[k*4+col]; } return r; }
It operator*(float s) { It r; for (int i=0;i<16;i++) r.values[i]=values[i]*s; return r; }
}setIdentity
Reset a matrix to the identity matrix
U0 setIdentity(Matrix mat)Parameters
mat— The matrix to reset
multiply
Multiply two matrices and store the result
U0 multiply(Matrix result, Matrix left, Matrix right)Parameters
result— Matrix to store the resultleft— First (left) matrixright— Second (right) matrix
copy
Copy a matrix into another
U0 copy(Matrix src, Matrix dest)Parameters
src— Source matrixdest— Destination matrix
ortho2D
Build a 2D orthographic projection matrix
U0 ortho2D(Matrix mat, F32 left, F32 right, F32 bottom, F32 top, F32 near, F32 far)Parameters
mat— Output matrixleft— Left boundaryright— Right boundarybottom— Bottom boundarytop— Top boundarynear— Near planefar— Far plane
ortho2DVk
Build a 2D orthographic projection matrix adjusted for Vulkan's coordinate system
U0 ortho2DVk(Matrix mat, F32 left, F32 right, F32 bottom, F32 top, F32 near, F32 far)Parameters
mat— Output matrixleft— Left boundaryright— Right boundarybottom— Bottom boundarytop— Top boundarynear— Near planefar— Far plane
projection
Build a 3D perspective projection matrix
U0 projection(Matrix mat, F32 width, F32 height, F32 fov, F32 near, F32 far)Parameters
mat— Output matrixwidth— Viewport widthheight— Viewport heightfov— Field of view angle in radiansnear— Near plane distancefar— Far plane distance
scale
Apply a scale transform to a matrix
U0 scale(Matrix mat, F32 x, F32 y, F32 z, F32 w)Parameters
mat— Matrix to modifyx— X scale factory— Y scale factorz— Z scale factorw— W scale factor
translate
Apply a translation transform to a matrix
U0 translate(Matrix mat, F32 x, F32 y, F32 z, F32 w)Parameters
mat— Matrix to modifyx— X translationy— Y translationz— Z translationw— W translation
rotate
Apply a rotation transform to a matrix
U0 rotate(Matrix mat, F32 angle, F32 x, F32 y, F32 z)Parameters
mat— Matrix to modifyangle— Rotation angle in radiansx— X axis weighty— Y axis weightz— Z axis weight
lookAt
Build a view matrix from eye position, target, and up vector
U0 lookAt(Matrix mat, VectorF eye, VectorF center, VectorF up)Parameters
mat— Output view matrixeye— Camera positioncenter— Camera target pointup— World up direction
add
Add two matrices element-wise
U0 add(Matrix result, Matrix a, Matrix b)Parameters
result— Matrix to store the resulta— First matrixb— Second matrix
sub
Subtract two matrices element-wise
U0 sub(Matrix result, Matrix a, Matrix b)Parameters
result— Matrix to store the resulta— Minuend matrixb— Subtrahend matrix
mul
Multiply two matrices (matrix product)
U0 mul(Matrix result, Matrix a, Matrix b)Parameters
result— Matrix to store the resulta— Left matrixb— Right matrix
inverse
Compute the inverse of a 4x4 matrix
U8 inverse(Matrix result, Matrix src)Parameters
result— Matrix to store the inversesrc— Source matrix to invert
Returns — 1 on success, 0 if matrix is singular