Hi,
I think I'm overseeing something when moving from 8 point check to extents/limits checking a bounding box.
All 8 points and the min and max I checked (also by checking against D3DX function to generate bounding box extents).
The sympton:
- when i check against all 8 point, result is OK / as expected
- when i check against the extents (2 points) result is not OK (culled to early, strange behaviour, some meshes OK/ not OK)
Here's the difference in the code.
Really hope someone can help me out/ in the right direction.
// checking all 8 points, OK
bool CD3dcam::BoxInFrustum(BOUNDINGBOX *pBoundingBox)
{
int iTotalIn = 0;
for(int i=0;i<6;++i)
{
int iInCount = 8;
int iPtIn = 1;
for(int bc=0;bc<8;++bc)
{
if(D3DXPlaneDotCoord(&mFrustumPlane, &pBoundingBox->boxArray[bc]) < 0)
{
iPtIn = 0;
iInCount--;
}
}
if(iInCount == 0) return false;
iTotalIn += iPtIn;
}
if(iTotalIn == 0) return false;
else return true;
}
// checking only extents, array index 0 and 1
bool CD3dcam::BoxInFrustum(BOUNDINGBOX *pBoundingBox)
{
int iTotalIn = 0;
for(int i=0;i<6;++i)
{
int iInCount = 2;
int iPtIn = 1;
for(int bc=0;bc<2;++bc)
{
if(D3DXPlaneDotCoord(&mFrustumPlane, &pBoundingBox->boxArray[bc]) < 0)
{
iPtIn = 0;
iInCount--;
}
}
if(iInCount == 0) return false;
iTotalIn += iPtIn;
}
if(iTotalIn == 0) return false;
else return true;
}
// generating the bounding box
void CalcBoundingBox(TVERTEX *pVtxArray, DWORD pStart, DWORD pNr, BOUNDINGBOX *pBox)
{
pBox->min.x = pVtxArray[pStart].position.x;
pBox->min.y = pVtxArray[pStart].position.y;
pBox->min.z = pVtxArray[pStart].position.z;
pBox->max.x = pVtxArray[pStart].position.x;
pBox->max.y = pVtxArray[pStart].position.y;
pBox->max.z = pVtxArray[pStart].position.z;
for(DWORD vc=pStart;vc<pStart+pNr;++vc)
{
if(pVtxArray[vc].position.x < pBox->min.x) pBox->min.x = pVtxArray[vc].position.x;
if(pVtxArray[vc].position.x > pBox->max.x) pBox->max.x = pVtxArray[vc].position.x;
if(pVtxArray[vc].position.y < pBox->min.y) pBox->min.y = pVtxArray[vc].position.y;
if(pVtxArray[vc].position.y > pBox->max.y) pBox->max.y = pVtxArray[vc].position.y;
if(pVtxArray[vc].position.z < pBox->min.z) pBox->min.z = pVtxArray[vc].position.z;
if(pVtxArray[vc].position.z > pBox->max.z) pBox->max.z = pVtxArray[vc].position.z;
}
// full 8 points of the AABB (0 and 1 == min and max for i.e. culling)
pBox->boxArray[0].x = pBox->min.x;
pBox->boxArray[0].y = pBox->min.y;
pBox->boxArray[0].z = pBox->min.z;
pBox->boxArray[1].x = pBox->max.x;
pBox->boxArray[1].y = pBox->max.y;
pBox->boxArray[1].z = pBox->max.z;
pBox->boxArray[2].x = pBox->max.x;
pBox->boxArray[2].y = pBox->max.y;
pBox->boxArray[2].z = pBox->min.z;
pBox->boxArray[3].x = pBox->min.x;
pBox->boxArray[3].y = pBox->max.y;
pBox->boxArray[3].z = pBox->min.z;
pBox->boxArray[4].x = pBox->min.x;
pBox->boxArray[4].y = pBox->min.y;
pBox->boxArray[4].z = pBox->max.z;
pBox->boxArray[5].x = pBox->max.x;
pBox->boxArray[5].y = pBox->min.y;
pBox->boxArray[5].z = pBox->max.z;
pBox->boxArray[6].x = pBox->max.x;
pBox->boxArray[6].y = pBox->min.y;
pBox->boxArray[6].z = pBox->min.z;
pBox->boxArray[7].x = pBox->min.x;
pBox->boxArray[7].y = pBox->max.y;
pBox->boxArray[7].z = pBox->max.z;
// dimensions
pBox->width = pBox->max.x - pBox->min.x;
pBox->height = pBox->max.y - pBox->min.y;
pBox->depth = pBox->max.z - pBox->min.z;
}