Hi,
I have a fairly simple question (I think), on which I'm afraid I'm thinking to simple.
Here's what I want to achieve:
Class: camera
Members:
6 frustumplanes (mFrustumPlane[6])
2 d3dxvector3's (XYZ), pVtx, nVtx (positive and negative extents of a bounding box)
Struct:
bounding box
Members:
2 d3dxvector3's (XYZ) with min and max extens of a bounding box
What do I do know:
- for each bounding box check, I check which X, Y, Z from the min/max vertices I need to use to fill the pVtx/nVtx
- this is done for each of the 6 planes, within each bounding box check
- the normal per plane determines which X, Y, Z I need to use from the min and max vertices of the box
What do I want to do:
- for each frame, determine which min/ max X Y Z values I need to use
- reuse this information for each bounding box check
So I have to find a way to do the following:
- within update frustum function: determine per plane if the X, Y and Z are positive or negative (and save this information)
- withing bounding box check function: continue directly using the correct min and max XYZ vertices values, based on the normal per plane (positive or negative X Y Z)
I thought of doing thing by creatig a X, Y, Z bool per plane of the frustum, and set to true when the X/ Y or Z is positive and to false, when it's negative. Then I don't need to check this for each bounding box check.
The only thing is, that I would then still need to check the bool values for each box check.
Can someone help me in the right direction?
Here's the current code of the bounding box check function:
int CD3dcam::BoxInFrustum(BOUNDINGBOX *pBoundingBox)
{
bool intersect = false;
float dist;
for(int i=0;i<6;++i)
{
// find the nearest and farthest point along normal direction
_pvtx = pBoundingBox->min;
if(mFrustumPlane.a >= 0) _pvtx.x = pBoundingBox->max.x;
if(mFrustumPlane.b >= 0) _pvtx.y = pBoundingBox->max.y;
if(mFrustumPlane.c >= 0) _pvtx.z = pBoundingBox->max.z;
_nvtx = pBoundingBox->max;
if(mFrustumPlane.a >= 0) _nvtx.x = pBoundingBox->min.x;
if(mFrustumPlane.b >= 0) _nvtx.y = pBoundingBox->min.y;
if(mFrustumPlane.c >= 0) _nvtx.z = pBoundingBox->min.z;
// check positive vertex; further along the normal's direction
dist = D3DXPlaneDotCoord(&mFrustumPlane, &_pvtx);
if(dist < 0) return OUTSIDE; // wrong side of plane, completely outside
// check negative vertex; less far along the normal's direction
dist = D3DXPlaneDotCoord(&mFrustumPlane, &_nvtx);
if(dist < 0) intersect = true; // return INTERSECT; // intersecting, negative vertex within frustum
}
if(intersect) return INTERSECT;
return INSIDE;
}