////////////////////////////////////////////////////////////////////////////////////
//
\\
// This is a simple Frustum Function, which is for DirectX3D, its used
for \\
// tutorial purposes, and demonstrates how you can implement the Frustum
Check \\
// using DirectX. How it works is, you pass in the coordinate for the
vertex \\
// point your checking, then if its in the frustum, it will return true,
else it \\
// not, so will return false....and you can take the appropriate
action. \\
//
\\
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
bool
FrustrumCheck(float x,
float y, float
z)
{
D3DXMATRIX matWorld, matView, matProjection;
g_pd3dDevice->GetTransform(D3DTS_WORLD, &matWorld);
g_pd3dDevice->GetTransform(D3DTS_VIEW, &matView);
//g_pd3dDevice->GetTransform(D3DTS_PROJECTION, &matProjection);
// I chaned this line, so you could change the
projection view here, adjusting
// the near and far plane...alternatively you can
just use the GetTransform
// DX call, and use the pre-set one.
D3DXMatrixPerspectiveFovLH( &matProjection, D3DX_PI/2, 1.0f, 1.0f, 30.0f );
D3DXMATRIX Cull = matWorld * matView * matProjection;
D3DXVECTOR4 vNode = D3DXVECTOR4(x,y,z,1);
D3DXVECTOR4 vTestVert;
D3DXVec4Transform(&vTestVert, &vNode, &Cull);
if( abs_f(vTestVert.x) > abs_f(vTestVert.w)
) // Outside our X Frustum Plane
return
false;
if( abs_f(vTestVert.y) > abs_f(vTestVert.w)
) // Outside our Y Frustum Plane
return
false;
if( (vTestVert.z<0.0f) || (vTestVert.z>vTestVert.w))
// Outside our z Frustum Plane
return
false;
return true;
} |