Jump to content
  • Advertisement
Sign in to follow this  
BytePtr

Frustum Culling problem

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

Im drawing simple boxes within current viewport (X1,X2, Y1, Y2) and using gluLookat.
Drawing is limited to specific screen portions only but still i would like to add extra frustum culling.

I added this but i get weird results, like on this PIC:
Click:

Bad Frustum Culling

But it should look always like this:

Click
Good Frustum Culling


The last pic is made with culling disabled.

This is what i basically use:

// calc the frustum....
frustum.CalculateFrustum();

// then my loops

// and then...
if (!frustum.BlockInFrustum(0.5f+j, 0.5f+i, 0.5f))
continue;


And then i draw the box.

This problem hit me twice and i started rewriting code and again, it doesn't cull correctly.


What can cause such culling?
Wrong viewport? Wrong camera rotation?

It tries to cull in "triangular" way and it looks ugly and completely wrong.
Because if i move camera, then all boxes just disappear in one moment.

Any ideas for me, how to fix it or what could cause this?


Thanks..

Share this post


Link to post
Share on other sites
Advertisement
I dunno why, but it's amazing how posting a programming problem to some forum, immediately solves it.

Frustum culling BlockInFrustum code had to be rewritten like this:

bool AFrustum::BlockInFrustum(float x, float z, float size) {

const float b_height = 6.0f;
for(int i = 0; i < 6; i++ )
{
if(m_Frustum[A] * (x - size) + m_Frustum * 0.0f + m_Frustum[C] * (z - size) + m_Frustum[D] > 0)
continue;
if(m_Frustum[A] * (x + size) + m_Frustum * 0.0f + m_Frustum[C] * (z - size) + m_Frustum[D] > 0)
continue;


if(m_Frustum[A] * (x - size) + m_Frustum * b_height + m_Frustum[C] * (z - size) + m_Frustum[D] > 0)
continue;
if(m_Frustum[A] * (x + size) + m_Frustum * b_height + m_Frustum[C] * (z - size) + m_Frustum[D] > 0)
continue;


if(m_Frustum[A] * (x - size) + m_Frustum * 0.0f + m_Frustum[C] * (z + size) + m_Frustum[D] > 0)
continue;
if(m_Frustum[A] * (x + size) + m_Frustum * 0.0f + m_Frustum[C] * (z + size) + m_Frustum[D] > 0)
continue;
if(m_Frustum[A] * (x - size) + m_Frustum * b_height + m_Frustum[C] * (z + size) + m_Frustum[D] > 0)
continue;
if(m_Frustum[A] * (x + size) + m_Frustum * b_height + m_Frustum[C] * (z + size) + m_Frustum[D] > 0)
continue;

//It isn't in the frustum
return false;
}
return true;
}


Maybe it will be useful to someone.

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.

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!