Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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++)

	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 this post

Link to post
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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!