Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Frustum Culling

This topic is 5369 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

Has any one got some really good culling code they would like to share? Ive been trying for ages to get mine working. Ive been working off the sdk example and for some reason nothing wants to draw when i cull test

Share this post

Link to post
Share on other sites
I''ve been having the same trouble. I can''t find anything that works properly. Check a couple pages back (pages 2-4) for one of my posts. It has my code for the frustum culling. I don''t know that it will help, but it should. It works somewhat for me. I just don''t have the correct function for checking spheres, boxes, etc. against the frustum planes.

Share this post

Link to post
Share on other sites
Ive extracted the planes properly but am having trouble checking if a box is inside outside or contains the frustum

Here's what i got

Ive got the frustum planes transformed into world space
And the 8 points of the containing box in world space

[edited by - kapru on March 27, 2004 11:44:20 PM]

Share this post

Link to post
Share on other sites
here''s the source to what im doing

//check if the 8 points are within the frustum

int cTerrainEngine::TerrainCullPatch(sTerrainPatch *p)
int PointsIn = 0;

for(int plane=0;plane<6;plane++)
int InCount = 8;
int PtIn = 1;
for(int i=0;i<8;i++)
//Check to see if the point is on the +ve side for the plane

float s = planeFrustum[plane].a*p->BoundingCube[i].x +
planeFrustum[plane].b*p->BoundingCube[i].y +
planeFrustum[plane].c*p->BoundingCube[i].x +
if s is over 0 the point is on the +ve side of the plane
if s is under 0 the point is on the -ve side of the plane
if s is 0 the point is on the plane

PtIn = 0;
if(InCount==0) return 0;
PointsIn +=InCount;
if(PointsIn==6) return 1;

return 2;//Probably an intersection


Extract the Frustum planes

cTerrainEngine::CreateTerrainFrustum(LPDIRECT3DDEVICE8 device)



D3DXMatrixMultiply( &mat, &matView, &matProj );
D3DXMatrixInverse( &mat, NULL, &mat );

planeFrustum[0].a = mat._14 + mat._11;
planeFrustum[0].b = mat._24 + mat._21;
planeFrustum[0].c = mat._34 + mat._31;
planeFrustum[0].d = mat._44 + mat._41;

planeFrustum[1].a = mat._14 - mat._11;
planeFrustum[1].b = mat._24 - mat._21;
planeFrustum[1].c = mat._34 - mat._31;
planeFrustum[1].d = mat._44 - mat._41;

planeFrustum[2].a = mat._14 - mat._12;
planeFrustum[2].b = mat._24 - mat._22;
planeFrustum[2].c = mat._34 - mat._32;
planeFrustum[2].d = mat._44 - mat._42;

planeFrustum[3].a = mat._14 + mat._12;
planeFrustum[3].b = mat._24 + mat._22;
planeFrustum[3].c = mat._34 + mat._32;
planeFrustum[3].d = mat._44 + mat._42;

planeFrustum[4].a = mat._13;
planeFrustum[4].b = mat._23;
planeFrustum[4].c = mat._33;
planeFrustum[4].d = mat._43;

planeFrustum[5].a = mat._14 - mat._13;
planeFrustum[5].b = mat._24 - mat._23;
planeFrustum[5].c = mat._34 - mat._33;
planeFrustum[5].d = mat._44 - mat._43;

for(int i=0;i<6;i++)

Share this post

Link to post
Share on other sites
maybe you should also add the world matrix and multiply it to the projection and view matrix, maybe than it works... (in my app it works then...)

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!