setFromProjectionMatrix method

CSMFrustumVerts setFromProjectionMatrix(
  1. Matrix4 projectionMatrix,
  2. double maxFar
)

Implementation

CSMFrustumVerts setFromProjectionMatrix(Matrix4 projectionMatrix, double maxFar) {
	final isOrthographic = projectionMatrix.storage[ 2 * 4 + 3 ] == 0;

	inverseProjectionMatrix.setFrom( projectionMatrix ).invert();

	// 3 --- 0  vertices.near/far order
	// |     |
	// 2 --- 1
	// clip space spans from [-1, 1]

	vertices.near[ 0 ].setValues( 1, 1, - 1 );
	vertices.near[ 1 ].setValues( 1, - 1, - 1 );
	vertices.near[ 2 ].setValues( - 1, - 1, - 1 );
	vertices.near[ 3 ].setValues( - 1, 1, - 1 );
	vertices.near.forEach(( v ) {
		v.applyMatrix4( inverseProjectionMatrix );
	});

	vertices.far[ 0 ].setValues( 1, 1, 1 );
  vertices.far[ 1 ].setValues( 1, - 1, 1 );
	vertices.far[ 2 ].setValues( - 1, - 1, 1 );
	vertices.far[ 3 ].setValues( - 1, 1, 1 );
	vertices.far.forEach(( v ) {
		v.applyMatrix4( inverseProjectionMatrix );

		final absZ = v.z.abs();
		if ( isOrthographic ) {
			v.z *= math.min( maxFar / absZ, 1.0 );
		} else {
			v.scale( math.min( maxFar / absZ, 1.0 ) );
		}
	} );

	return vertices;
}