Skip to content

Instantly share code, notes, and snippets.

@BitPuffin
Created August 4, 2013 16:00
Show Gist options
  • Save BitPuffin/6150802 to your computer and use it in GitHub Desktop.
Save BitPuffin/6150802 to your computer and use it in GitHub Desktop.
type
TMatrix[T; R, C: range] = array[C, array[R, T]] # A Column major matrix because that's how GLSL stores them [C][R]
proc row*[T; R, C: range](m: TMatrix[T, R, C], row: range[R]): TVector[T, R] {.noSideEffect.} =
for i in R:
result[i] = m[i][row]
template col*[T; R, C: range](m: TMatrix[T, R, C], col: range[C]): TVector[T, C] =
m[col].TVector
proc mul*[T; R, N, C: range](a: TMatrix[T, R, N], b: TMatrix[T, N, C]): TMatrix[T, R, C] {.noSideEffect.} =
for i in R:
for j in C:
result[j][i] = a.row(i).dot(b.col(j))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment