Measuring Distance Between Object's Bounding Box and Camera's Left FOV Plane

I need to calculate the distance between the left edge of an object’s bounding box and the left plane of the camera’s FOV. The objective is to determine the precise moment when the object begins to intersect or touch the left boundary of the camera’s FOV. This calculation is crucial for a project where objects in the scene are dynamically positioned and their interactions with the camera’s view are significant.

This calculation will help me understand at what point the object will start to disappear from view if it moves towards the left

You can get the 6 frustum planes from scene.frustumPlanes. I don’t know where the left plane is in the array, you will have to do some testing! Then, it’s a matter of testing the vertices of the bounding box against this plane.

Here’s what BoundingBox is doing to check if it is in the frustum:

public isCompletelyInFrustum(frustumPlanes: Array<DeepImmutable<Plane>>): boolean {
    return BoundingBox.IsCompletelyInFrustum(this.vectorsWorld, frustumPlanes);
}

public static IsCompletelyInFrustum(boundingVectors: Array<DeepImmutable<Vector3>>, frustumPlanes: Array<DeepImmutable<Plane>>): boolean {
    for (let p = 0; p < 6; ++p) {
        const frustumPlane = frustumPlanes[p];
        for (let i = 0; i < 8; ++i) {
            if (frustumPlane.dotCoordinate(boundingVectors[i]) < 0) {
                return false;
            }
        }
    }
    return true;
}

In your case, you would only have to check a single plane, not 6.

1 Like

Thank you!