setFrustumMatrix function

void setFrustumMatrix(
  1. Matrix4 perspectiveMatrix,
  2. double left,
  3. double right,
  4. double bottom,
  5. double top,
  6. double near,
  7. double far,
)

Constructs an OpenGL perspective projection matrix in perspectiveMatrix.

left, right specify the coordinates for the left and right vertical clipping planes. bottom, top specify the coordinates for the bottom and top horizontal clipping planes. near, far specify the coordinates to the near and far depth clipping planes.

Implementation

void setFrustumMatrix(
  Matrix4 perspectiveMatrix,
  double left,
  double right,
  double bottom,
  double top,
  double near,
  double far,
) {
  final double twoNear = 2.0 * near;
  final double rightMinusLeft = right - left;
  final double topMinusBottom = top - bottom;
  final double farMinusNear = far - near;
  perspectiveMatrix
    ..setZero()
    ..setEntry(0, 0, twoNear / rightMinusLeft)
    ..setEntry(1, 1, twoNear / topMinusBottom)
    ..setEntry(0, 2, (right + left) / rightMinusLeft)
    ..setEntry(1, 2, (top + bottom) / topMinusBottom)
    ..setEntry(2, 2, -(far + near) / farMinusNear)
    ..setEntry(3, 2, -1.0)
    ..setEntry(2, 3, -(twoNear * far) / farMinusNear);
}