Jump to content
  • Advertisement

Archived

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

steg

Sphere in Frustum

This topic is 6091 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 implemented some View frustum culling (thanks to Mark Morleys tutorial), but in my SphereInFrustum method I pass in the objects world x,y and z position as opposed to the centre of the spheres x,y,z coordinate as he suggests but it still works perfectly, in fact, passing in the sphere's x,y,z coordinate gives strange results ?! Here is my method : BOOL CD3DManager::SphereInFrustum( float x, float y, float z, float radius ) { int p; for( p = 0; p < 6; p++ ) { if( frustum[p][0] * x + frustum[p][1] * y + frustum[p][2] * z + frustum[p][3] <= -radius ) return false; } return true; } This is how I precompute the objects sphere : j = 0; while(j!=OBJECTAMOUNT) { DWORD dwBufStart = g_Objects[j].nVertexBufferStart; d3dManager.SetBoundingSphere(&MyVertices[dwBufStart], g_Objects[j].dwVertexAmount, CUSTOM_VERTEX, g_Objects[j].pCenter,&g_Objects[j].radius); j++; } Then my rendering code which checks if object is visible (this shows I'm passing the objects world x,y,z position): j = 0; while(j!=OBJECTAMOUNT) { if(bCulling || d3dManager.SphereInFrustum(g_Objects[j].XPos, g_Objects[j].YPos, g_Objects[j].ZPos, g_Objects[j].radius )) { MakeWorldMatrix(&WorldMatrix, g_Objects[j]); g_pDevice->SetTransform( D3DTS_WORLD, &WorldMatrix ); g_pDevice->DrawPrimitive(g_Objects[j].nType, g_Objects[j].nVertexBufferStart, g_Objects[j].nVertexBufferEnd); } j++; } Just to re-iterate, I'm passing in the objects world x,y and z position - can anyone explain why this works ? If this is the case I don't need the sphere's x,y,z ?! Kind regards, sTeVe Edited by - steg on February 3, 2002 4:56:55 PM Edited by - steg on February 3, 2002 4:58:49 PM Edited by - steg on February 3, 2002 5:00:58 PM

Share this post


Link to post
Share on other sites
Advertisement
The sphere may not in 0,0,0 in the object''s local coordinate frame, so you need to add them together.

Share this post


Link to post
Share on other sites
I think void means that if your object isn''t centred at 0,0,0 you need to add that to your x,y,z parameters.

Neil


WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!

Share this post


Link to post
Share on other sites
Sorry - I wasn''t as clear as i meant to be.

Try this

BOOL CD3DManager::SphereInFrustum( Object )
{
int p;

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

Neil

(not sure but you might have to subtract th centre pos - just done quickly for you)

WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!

Share this post


Link to post
Share on other sites
Thanks Thedo,

I''ll try it tonight when I get home from work if I have time!

Reg''ds,
sTeVe

Share this post


Link to post
Share on other sites
Just had time to try it out, method now is :

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;
}

where x,y,z are objects world coordinates and rx,ry,rz are the spheres centre coordinates, this works fine but am still confused why the other way also worked (i.e, not having the spheres centre coordinates) ?

Thanks,
sTeVe

Share this post


Link to post
Share on other sites
Possibly your object was already centred at 0,0,0. That way the transforming by the centre coord (0,0,0) would produce exactly the same result. That would explain it. If not then I really don''t know.

Neil

WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!

Share this post


Link to post
Share on other sites
I hope you also didn''t calculate the frustum planes like mark morley because he''s using it for opengl. You need to take the column instead for directx.

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!