import { Matrix4 } from "three";

const matrix4 = new Matrix4();

/**
 *
 * @param {Camera|ThreePerspectiveCamera} camera Three.js camera object
 * @param {Frustum|THREE.Frustum|ThreeFrustum} result Three.js frustum object
 * @param update_projection
 */
export function frustum_from_camera(camera, result, update_projection = true) {
    if (update_projection) {
        camera.updateProjectionMatrix();
    }

    // construct view projection matrix
    matrix4.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);

    result.setFromProjectionMatrix(matrix4);
}
