View Frustrum Culling
I am sure this has been asked 1000 times, sorry to ask again. Is there a quick way to tell if a polygon is fully or partly inside a view frustrum? I have setup the projection matrix etc. using directx and need a quick and efficient test.
Regards
Ray
This tells you how to do it in OpenGL, the theory is directly transferable though, so it should still be useful.
Death of one is a tragedy, death of a million is just a statistic.
Death of one is a tragedy, death of a million is just a statistic.

If at first you don't succeed, redefine success.
Thanks very much for your reply, that''s a great little article. I have tried to code a DX version of the simple frustrum cull routine, but it doesn''t seem to be working (it culls everything... good frame rates tho, lol). Can you spot anything obviously wrong in the code?
public void RefreshProjectionPlanes(Direct3D.Device device)
{
Matrix clipMatrix=Matrix.Multiply(device.Transform.Projection, device.Transform.View);
// get right plane
frustrum[0]=new Plane(clipMatrix.M14-clipMatrix.M11, clipMatrix.M24-clipMatrix.M21, clipMatrix.M34-clipMatrix.M31, clipMatrix.M44-clipMatrix.M41);
// get left plane
frustrum[1]=new Plane(clipMatrix.M14+clipMatrix.M11, clipMatrix.M24+clipMatrix.M21, clipMatrix.M34+clipMatrix.M31, clipMatrix.M44+clipMatrix.M41);
// get bottom plane
frustrum[2]=new Plane(clipMatrix.M14+clipMatrix.M12, clipMatrix.M24+clipMatrix.M22, clipMatrix.M34+clipMatrix.M32, clipMatrix.M44+clipMatrix.M42);
// get top plane
frustrum[3]=new Plane(clipMatrix.M14-clipMatrix.M12, clipMatrix.M24-clipMatrix.M22, clipMatrix.M34-clipMatrix.M32, clipMatrix.M44-clipMatrix.M42);
// get far plane
frustrum[4]=new Plane(clipMatrix.M14-clipMatrix.M13, clipMatrix.M24-clipMatrix.M23, clipMatrix.M34-clipMatrix.M33, clipMatrix.M44-clipMatrix.M43);
// get near plane
frustrum[5]=new Plane(clipMatrix.M14+clipMatrix.M13, clipMatrix.M24+clipMatrix.M23, clipMatrix.M34+clipMatrix.M33, clipMatrix.M44+clipMatrix.M43);
// normalize all
for (int i=0; i < 6; i++)
frustrum.Normalize();
}
public bool InFrustrum(float x, float y, float z)
{
// check in front of all planes
for (int i=0; i < 6; i++)
if (frustrum.A*x + frustrum.B*y + frustrum.C*z + frustrum.D <= 0)<br> return false;<br> return true;<br> }<br><br> </i>
public void RefreshProjectionPlanes(Direct3D.Device device)
{
Matrix clipMatrix=Matrix.Multiply(device.Transform.Projection, device.Transform.View);
// get right plane
frustrum[0]=new Plane(clipMatrix.M14-clipMatrix.M11, clipMatrix.M24-clipMatrix.M21, clipMatrix.M34-clipMatrix.M31, clipMatrix.M44-clipMatrix.M41);
// get left plane
frustrum[1]=new Plane(clipMatrix.M14+clipMatrix.M11, clipMatrix.M24+clipMatrix.M21, clipMatrix.M34+clipMatrix.M31, clipMatrix.M44+clipMatrix.M41);
// get bottom plane
frustrum[2]=new Plane(clipMatrix.M14+clipMatrix.M12, clipMatrix.M24+clipMatrix.M22, clipMatrix.M34+clipMatrix.M32, clipMatrix.M44+clipMatrix.M42);
// get top plane
frustrum[3]=new Plane(clipMatrix.M14-clipMatrix.M12, clipMatrix.M24-clipMatrix.M22, clipMatrix.M34-clipMatrix.M32, clipMatrix.M44-clipMatrix.M42);
// get far plane
frustrum[4]=new Plane(clipMatrix.M14-clipMatrix.M13, clipMatrix.M24-clipMatrix.M23, clipMatrix.M34-clipMatrix.M33, clipMatrix.M44-clipMatrix.M43);
// get near plane
frustrum[5]=new Plane(clipMatrix.M14+clipMatrix.M13, clipMatrix.M24+clipMatrix.M23, clipMatrix.M34+clipMatrix.M33, clipMatrix.M44+clipMatrix.M43);
// normalize all
for (int i=0; i < 6; i++)
frustrum.Normalize();
}
public bool InFrustrum(float x, float y, float z)
{
// check in front of all planes
for (int i=0; i < 6; i++)
if (frustrum.A*x + frustrum.B*y + frustrum.C*z + frustrum.D <= 0)<br> return false;<br> return true;<br> }<br><br> </i>
check out the DXSDK framework and samples, there''s a frustum culling algorithm built in there (culling by spheres I think) - and you can pretty much copy-n-paste it into your program.
Jack
DirectX 4 VB: All you need for multimedia programming in Visual Basic
Formula 1 Championship Manager, My Game Project.
Jack
DirectX 4 VB: All you need for multimedia programming in Visual Basic
Formula 1 Championship Manager, My Game Project.
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>
Hmmm, I checked the example code, but cannot find where it converts the view and projection matrices into planes. But then I am not a c++ programmer (barely a c-sharpie). Does this example work a different way? Is it possible to convert the matrices into planes like the OGL example?
Regards
Rael
Regards
Rael
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement