Matrix

4x4 row-major float matrix

It

Matrix object (16 floats, initialized to identity)

struct It {
  F32 values[16]
};

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 result
  • left — First (left) matrix
  • right — Second (right) matrix

copy

Copy a matrix into another

U0 copy(Matrix src, Matrix dest)

Parameters

  • src — Source matrix
  • dest — 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 matrix
  • left — Left boundary
  • right — Right boundary
  • bottom — Bottom boundary
  • top — Top boundary
  • near — Near plane
  • far — 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 matrix
  • left — Left boundary
  • right — Right boundary
  • bottom — Bottom boundary
  • top — Top boundary
  • near — Near plane
  • far — 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 matrix
  • width — Viewport width
  • height — Viewport height
  • fov — Field of view angle in radians
  • near — Near plane distance
  • far — 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 modify
  • x — X scale factor
  • y — Y scale factor
  • z — Z scale factor
  • w — 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 modify
  • x — X translation
  • y — Y translation
  • z — Z translation
  • w — 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 modify
  • angle — Rotation angle in radians
  • x — X axis weight
  • y — Y axis weight
  • z — 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 matrix
  • eye — Camera position
  • center — Camera target point
  • up — World up direction