Hi, I posted this on the DX forum, but didn't get any replies, so I thought I might try here:
I've been having this problem with frustum culling for over a week now.
I've looked at the code over and over and over and over and over again, and theres absolutly nothing wrong with it as far as I can see.
The problem is that it returns incorrect true/falses. It just culls the wrong things.
heres some code:
bool cFrustum::Create(D3DXMATRIX mat)
{
m_Planes[0].a = mat._13; // Near
m_Planes[0].b = mat._23;
m_Planes[0].c = mat._33;
m_Planes[0].d = mat._43;
D3DXPlaneNormalize(&m_Planes[0], &m_Planes[0]);
m_Planes[1].a = mat._14 - mat._13; // Far
m_Planes[1].b = mat._24 - mat._23;
m_Planes[1].c = mat._34 - mat._33;
m_Planes[1].d = mat._44 - mat._43;
D3DXPlaneNormalize(&m_Planes[1], &m_Planes[1]);
m_Planes[2].a = mat._14 + mat._11; // Left
m_Planes[2].b = mat._24 + mat._21;
m_Planes[2].c = mat._34 + mat._31;
m_Planes[2].d = mat._44 + mat._41;
D3DXPlaneNormalize(&m_Planes[2], &m_Planes[2]);
m_Planes[3].a = mat._14 - mat._11; // Right
m_Planes[3].b = mat._24 - mat._21;
m_Planes[3].c = mat._34 - mat._31;
m_Planes[3].d = mat._44 - mat._41;
D3DXPlaneNormalize(&m_Planes[3], &m_Planes[3]);
m_Planes[4].a = mat._14 - mat._12; // Top
m_Planes[4].b = mat._24 - mat._22;
m_Planes[4].c = mat._34 - mat._32;
m_Planes[4].d = mat._44 - mat._42;
D3DXPlaneNormalize(&m_Planes[4], &m_Planes[4]);
m_Planes[5].a = mat._14 + mat._12; // Bottom
m_Planes[5].b = mat._24 + mat._22;
m_Planes[5].c = mat._34 + mat._32;
m_Planes[5].d = mat._44 + mat._42;
D3DXPlaneNormalize(&m_Planes[5], &m_Planes[5]);
return true;
}
this is the frustum plane calculation, mat is the view * proj matrices.
heres that part:
D3DXMATRIX matTmp;
D3DXMatrixMultiply(&matTmp, &m_Mat, &m_MatProj);
m_Frustum.Create(matTmp);
and heres the function for checking a sphere:
bool cFrustum::CheckSphere(float x, float y, float z, float Radius)
{
for (short i=0;i<6;i++)
if(D3DXPlaneDotCoord(&m_Planes, &D3DXVECTOR3(x, y, z)) < -Radius)
return false;
return true;
}
and finally, what calls the checkSphere:
bool cTerrain::Render(LPDIRECT3DDEVICE9 d3dDevice, cCamera *Camera)
{
if (Camera->GetFrustum()->CheckSphere(m_GX, m_GY, m_GZ, 2.5f))
{
Thanks for any help - going nuts here, quite close to ripping out hair...
[EDIT] Forgot to say, that the culling does seem to change somehow when I change the View Matrice, but it doesn't seem to have anything to do with what should be displayed, and what shouldn't.
[Edited by - sirob on October 1, 2004 10:54:44 AM]