multiplyMatrix4 function

List<double> multiplyMatrix4(
  1. List<double> a,
  2. List<double> b
)

Multiply two 4x4 column-major matrices: A * B.

Implementation

List<double> multiplyMatrix4(List<double> a, List<double> b) {
  final result = List<double>.filled(16, 0);
  for (int col = 0; col < 4; col++) {
    for (int row = 0; row < 4; row++) {
      double sum = 0;
      for (int k = 0; k < 4; k++) {
        sum += a[k * 4 + row] * b[col * 4 + k];
      }
      result[col * 4 + row] = sum;
    }
  }
  return result;
}