I am confused about the Plane dot product result
the source code about BountingBox.IsInFrustum is
/**
* Tests if a bounding box defined with 8 vectors intersects frustum planes
* @param boundingVectors defines an array of 8 vectors representing a bounding box
* @param frustumPlanes defines the frustum planes to test
* @returns true if there is an intersection
*/
public static IsInFrustum(boundingVectors: Array<DeepImmutable<Vector3>>, frustumPlanes: Array<DeepImmutable<Plane>>): boolean {
for (let p = 0; p < 6; ++p) {
let canReturnFalse = true;
const frustumPlane = frustumPlanes[p];
for (let i = 0; i < 8; ++i) {
if (frustumPlane.dotCoordinate(boundingVectors[i]) >= 0) {
canReturnFalse = false;
break;
}
}
if (canReturnFalse) {
return false;
}
}
return true;
}
the frustums plane facing the frustums inside
so the dot products >= 0 means the points is in the frustum
And I have refer the BoundingShere.isInFrustum to prove this
public isInFrustum(frustumPlanes: Array<DeepImmutable<Plane>>): boolean {
const center = this.centerWorld;
const radius = this.radiusWorld;
for (let i = 0; i < 6; i++) {
if (frustumPlanes[i].dotCoordinate(center) <= -radius) {
return false;
}
}
return true;
}
Is there a bug?
Hi @Tobepeter and welcome to the forum
Nop, no bug here.
1st code, test each points of a box. if any of them is not in front on a frustum plane, then is means a portion of the box is intersected with the frustum. And that is might be visible.
2nd code check more or less the same: that the center of the sphere is in front of each frustum plane but there is a twist. It’s not enough to be in front, is need to be far enough (at radius distance).
sorry I am still confuse
,I think frustumPlane.dotCoordinate(boundingVectors[i]) >= 0
it means that the box have one point in the frustum(maybe not completely)
so it should return true rather than false?
here is another code IsCompletelyInFrustum to compare
/**
* Tests if a bounding box defined with 8 vectors is entirely inside frustum planes
* @param boundingVectors defines an array of 8 vectors representing a bounding box
* @param frustumPlanes defines the frustum planes to test
* @returns true if there is an inclusion
*/
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;
}
/**
* Tests if a bounding box defined with 8 vectors intersects frustum planes
* @param boundingVectors defines an array of 8 vectors representing a bounding box
* @param frustumPlanes defines the frustum planes to test
* @returns true if there is an intersection
*/
public static IsInFrustum(boundingVectors: Array<DeepImmutable<Vector3>>, frustumPlanes: Array<DeepImmutable<Plane>>): boolean {
for (let p = 0; p < 6; ++p) {
let canReturnFalse = true;
const frustumPlane = frustumPlanes[p];
for (let i = 0; i < 8; ++i) {
if (frustumPlane.dotCoordinate(boundingVectors[i]) >= 0) {
canReturnFalse = false;
break;
}
}
if (canReturnFalse) {
return false;
}
}
return true;
}
a frustum is a volume described by 6 planes. if a point is in front of every plane, then it’s outside of that volume. If there is at least 1 point with its distance <0, then it’s potentialy inside that volume.
dotCoordinate compute the distance of a point in space to that plan.
1 Like