Matrix

Creation

m: matrix[2, 3]f32

m = matrix[2, 3]f32{
    1, 9, -13,
    20, 5, -6,
}

Layout

Clarification

  • Rows and Columns begin at 0.

  • "column 1" means the 2nd column.

  • Same as an array.

Representations

Representation [x, y]
  • The representation m[x, y]  is always the same regardless of the layout (column-major vs row-major).

// row 1, column 2
elem := m[1, 2] 
Representation [x]
  • Will return an array of the values in that column/row, whichever is major .

  • For column-major (default):

// column 1
elem := m[1]
  • For row-major (with #row_major ):

// row 1
elem := m[1]
Representation [x][y]
  • m[x][y]  is just m[x]  and then indexing the y th value in the array. If the layout of m[x]  changes, so does this; in other words, this representation is affected by the layout.

  • For column-major (default):

// column 1, row 2
elem := m[1][2] 
  • For row-major (with #row_major ):

// row 1, column 2
elem := m[1][2] 

Operations

  • matrix4_perspective

    • Clip Space Z Range:

      • [-1 to +1] , just like OpenGL.

    • Clip Space Y:

      • Y Up, just like OpenGL (Vulkan is Y Down).

    • Handedness:

      • If flip_z_axis  is true :

        • Right-handed coordinate system (camera forward is -Z).

      • If flip_z_axis  is false :

        • Left-handed coordinate system (camera forward is +Z).
          ``