setFrustumMatrix function
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);
}