Jump to content
  • Advertisement

Archived

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

steg

Object level culling

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

Hi, I''ve done some object level culling (removing entire objects from the graphics pipeline). I multiply the projection matrix by the view matrix to get the viewing frustum. My problem is the method PointInFrustum - it works well but obviously isn''t perfect as sometimes part of the object could be within the viewing frustum. What are the best alternatives to this, is it to use a bounding sphere from the object or a bounding cube ? Also, the obvious reason I am doing this is I want to implement a quadtree or maybe an octree for some terrain code I want to do - I guess this is a good step towards doing one ? Any help is much appreciated! Reg''ds, sTeVe Code : D3DXMATRIX CD3DManager::GetViewMatrix() { D3DXMATRIX view; m_pDevice->GetTransform(D3DTS_VIEW, &view); return view; } D3DXMATRIX CD3DManager::GetProjectionMatrix() { D3DXMATRIX projection; m_pDevice->GetTransform(D3DTS_PROJECTION, &projection); return projection; } D3DXMATRIX CD3DManager::GetViewFrustum() { D3DXMATRIX ViewFrustum; D3DXMatrixMultiply( &ViewFrustum, &GetViewMatrix(), &GetProjectionMatrix() ); return ViewFrustum; } void CD3DManager::ExtractFrustum() { float t; D3DXMATRIX clip; clip = GetViewFrustum(); // RIGHT PLANE frustum[0][0] = clip._14 - clip._11; frustum[0][1] = clip._24 - clip._21; frustum[0][2] = clip._34 - clip._31; frustum[0][3] = clip._44 - clip._41; t = sqrt( frustum[0][0] * frustum[0][0] + frustum[0][1] * frustum[0][1] + frustum[0][2] * frustum[0][2] ); frustum[0][0] /= t; frustum[0][1] /= t; frustum[0][2] /= t; frustum[0][3] /= t; // LEFT PLANE frustum[1][0] = clip._14 + clip._11; frustum[1][1] = clip._24 + clip._21; frustum[1][2] = clip._34 + clip._31; frustum[1][3] = clip._44 + clip._41; t = sqrt( frustum[1][0] * frustum[1][0] + frustum[1][1] * frustum[1][1] + frustum[1][2] * frustum[1][2] ); frustum[1][0] /= t; frustum[1][1] /= t; frustum[1][2] /= t; frustum[1][3] /= t; // BOTTOM PLANE frustum[2][0] = clip._14 + clip._12; frustum[2][1] = clip._24 + clip._22; frustum[2][2] = clip._34 + clip._32; frustum[2][3] = clip._44 + clip._42; t = sqrt( frustum[2][0] * frustum[2][0] + frustum[2][1] * frustum[2][1] + frustum[2][2] * frustum[2][2] ); frustum[2][0] /= t; frustum[2][1] /= t; frustum[2][2] /= t; frustum[2][3] /= t; // TOP PLANE frustum[3][0] = clip._14 - clip._12; frustum[3][1] = clip._24 - clip._22; frustum[3][2] = clip._34 - clip._32; frustum[3][3] = clip._44 - clip._42; t = sqrt( frustum[3][0] * frustum[3][0] + frustum[3][1] * frustum[3][1] + frustum[3][2] * frustum[3][2] ); frustum[3][0] /= t; frustum[3][1] /= t; frustum[3][2] /= t; frustum[3][3] /= t; // FAR PLANE frustum[4][0] = clip._14 - clip._13; frustum[4][1] = clip._24 - clip._23; frustum[4][2] = clip._34 - clip._33; frustum[4][3] = clip._44 - clip._43; t = sqrt( frustum[4][0] * frustum[4][0] + frustum[4][1] * frustum[4][1] + frustum[4][2] * frustum[4][2] ); frustum[4][0] /= t; frustum[4][1] /= t; frustum[4][2] /= t; frustum[4][3] /= t; // NEAR PLANE frustum[5][0] = clip._14 + clip._13; frustum[5][1] = clip._24 + clip._23; frustum[5][2] = clip._34 + clip._33; frustum[5][3] = clip._44 + clip._43; t = sqrt( frustum[5][0] * frustum[5][0] + frustum[5][1] * frustum[5][1] + frustum[5][2] * frustum[5][2] ); frustum[5][0] /= t; frustum[5][1] /= t; frustum[5][2] /= t; frustum[5][3] /= t; } BOOL CD3DManager:ointInFrustum( float x, float y, float z ) { int p; for( p = 0; p < 6; p++ ) { if( frustum[p][0] * x + frustum[p][1] * y + frustum[p][2] * z + frustum[p][3] <= 0 ) return false; } return true; }

Share this post


Link to post
Share on other sites
Advertisement
yep, you use bounding spheres or boxes. For example for octrees bounding boxes are perfect as they exactly describe the part of world that is interesting you. You can find a tut about ocrees and frustrum clipping at www.gametutorials.com (tutorials , opengl , last page)
good luck

With best regards,
Mirek Czerwiñski
http://kris.top.pl/~kherin/

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.

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!