frustum culling behaving strange

This topic is 3556 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hello everyone, I have the following problem: I use frustum culling together with object selection. when an object is selected, a square is placed around it. When I turn so the object is offscreen, the square should not be placed on screen. this works, but only partly. when the object is straight behind me, the culling thinks that the object is visible, and draws an empty square on screen. I use the following code for the culling:

D3DXMATRIX vp = matView * matProj;
D3DXPLANE frustum[6];

//left plane
frustum[0].a = vp._14 + vp._11;
frustum[0].b = vp._24 + vp._21;
frustum[0].c = vp._34 + vp._31;
frustum[0].d = vp._44 + vp._41;

//right plane
frustum[1].a = vp._14 - vp._11;
frustum[1].b = vp._24 - vp._21;
frustum[1].c = vp._34 - vp._31;
frustum[1].d = vp._44 - vp._41;

//top plane
frustum[2].a = vp._14 - vp._12;
frustum[2].b = vp._24 - vp._22;
frustum[2].c = vp._34 - vp._32;
frustum[2].d = vp._44 - vp._42;

//top plane
frustum[3].a = vp._14 + vp._12;
frustum[3].b = vp._24 + vp._22;
frustum[3].c = vp._34 + vp._32;
frustum[3].d = vp._44 + vp._42;

//near plane
frustum[4].a = vp._13;
frustum[4].b = vp._23;
frustum[4].c = vp._33;
frustum[4].d = vp._43;

//far plane
frustum[5].a = vp._14 - vp._13;
frustum[5].b = vp._24 - vp._23;
frustum[5].c = vp._34 - vp._33;
frustum[5].d = vp._44 - vp._43;

for(int i = 0; i <6; i++)
{
D3DXPlaneNormalize(&frustum,&frustum);
}

float fDistance; // Calculated distance

// Test against a plane
for(int i=0; i<6; ++i)
{
fDistance=D3DXPlaneDotCoord(&frustum, &pos);

{
return 0; // not visible
}
}
return 1; // visible


If anyone has an idea as to what is wrong here? THANKS

Share on other sites
I don't know D3DXPlaneDotCoord very well, but it seems that since the near and far planes' normals point in the same direction, the distance to the near plane might have the wrong sign if the object is right behind the camera.

1. 1
2. 2
3. 3
Rutin
24
4. 4
JoeJ
18
5. 5

• 14
• 23
• 11
• 11
• 9
• Forum Statistics

• Total Topics
631766
• Total Posts
3002232
×