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 two_near = 2.0 * near;
  final right_minus_left = right - left;
  final top_minus_bottom = top - bottom;
  final far_minus_near = far - near;
  perspectiveMatrix
    ..setZero()
    ..setEntry(0, 0, two_near / right_minus_left)
    ..setEntry(1, 1, two_near / top_minus_bottom)
    ..setEntry(0, 2, (right + left) / right_minus_left)
    ..setEntry(1, 2, (top + bottom) / top_minus_bottom)
    ..setEntry(2, 2, -(far + near) / far_minus_near)
    ..setEntry(3, 2, -1.0)
    ..setEntry(2, 3, -(two_near * far) / far_minus_near);
}