viewMatrix method

Matrix4 viewMatrix()

Returns a column-major OpenGL view matrix (world → camera).

Implementation

Matrix4 viewMatrix() {
  final R = rotation; // camera -> world
  final t = position;

  // Upper-left 3×3 = R^T; translation = -R^T * t
  return Matrix4(
    R.row0.x,
    R.row0.y,
    R.row0.z,
    0,
    R.row1.x,
    R.row1.y,
    R.row1.z,
    0,
    R.row2.x,
    R.row2.y,
    R.row2.z,
    0,
    -t.x * R.row0.x - t.y * R.row1.x - t.z * R.row2.x,
    -t.x * R.row0.y - t.y * R.row1.y - t.z * R.row2.y,
    -t.x * R.row0.z - t.y * R.row1.z - t.z * R.row2.z,
    1,
  );
}