Jump to content
  • Advertisement

Archived

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

steg

Sphere in Frustum

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

Advertisement
Hi,
Objects are at various world positions (they are static).

The code I use to get the planes is converted to dx as shown below :

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()
{
double 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;
}

Does this look correct, it all works, but again, I still don''t need the sphere''s centre coordinates in the following method : ?!

BOOL CD3DManager::SphereInFrustum( float x, float y, float z, float radius, float rx, float ry, float rz )
{
int p;

for( p = 0; p < 6; p++ )
{
if( frustum[p][0] * (x + rx) + frustum[p][1]
* (y + ry) + frustum[p][2]
* (z + rz) + frustum[p][3] <= -radius )
return false;
}
return true;
}

This is really weird ?!?!?

Reg''ds,
sTeVe

Share this post


Link to post
Share on other sites
Thats some pretty interesting stuff. I would like to use boxes so I can calculate my visibility in my world on the fly.

Moe''s Site

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!