in modules/core/src/utils/math-utils.js [39:118]
export function getFrustumPlanes({aspect, near, far, fovyRadians, position, direction, up, right}) {
cameraDirection.copy(direction);
// Account for any scaling of the z axis (e.g. in
// mercator view matrix)
const nearFarScale = 1 / cameraDirection.len();
cameraDirection.normalize();
cameraPosition.copy(position);
cameraUp.copy(up);
// Account for scaling of the xy axis
const widthScale = 1 / cameraUp.len();
cameraUp.normalize();
cameraRight.copy(right).normalize();
const nearHeight = 2 * Math.tan(fovyRadians / 2) * near * widthScale;
const nearWidth = nearHeight * aspect;
nearCenter
.copy(cameraDirection)
.scale(near * nearFarScale)
.add(cameraPosition);
farCenter
.copy(cameraDirection)
.scale(far * nearFarScale)
.add(cameraPosition);
let normal = cameraDirection.clone().negate();
let distance = normal.dot(nearCenter);
const planes = {
near: {
distance,
normal
},
far: {
distance: cameraDirection.dot(farCenter),
normal: cameraDirection.clone()
}
};
a.copy(cameraRight)
.scale(nearWidth * 0.5)
.add(nearCenter)
.subtract(cameraPosition)
.normalize();
normal = new Vector3(a).cross(cameraUp);
distance = cameraPosition.dot(normal);
planes.right = {normal, distance};
a.copy(cameraRight)
.scale(-nearWidth * 0.5)
.add(nearCenter)
.subtract(cameraPosition)
.normalize();
normal = new Vector3(cameraUp).cross(a);
distance = cameraPosition.dot(normal);
planes.left = {normal, distance};
a.copy(cameraUp)
.scale(nearHeight * 0.5)
.add(nearCenter)
.subtract(cameraPosition)
.normalize();
normal = new Vector3(cameraRight).cross(a);
distance = cameraPosition.dot(normal);
planes.top = {normal, distance};
a.copy(cameraUp)
.scale(-nearHeight * 0.5)
.add(nearCenter)
.subtract(cameraPosition)
.normalize();
normal = new Vector3(a).cross(cameraRight);
distance = cameraPosition.dot(normal);
planes.bottom = {normal, distance};
return planes;
}