#### Archived

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

# Frustrum culling question

This topic is 6945 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''ve been reading up on frustrum culling and so far everything I found either does more than I want or I just plain don''t understand what''s going on. Basically what I want to know is if a bounding box is completely outside the viewing frustrum, if it''s partially inside or fully inside is not important only if its completely outside. The bounding box is difined as: minx maxx miny maxy minz maxz The viewing frustrum is: fov 90 aspect ratio 0.75 near z clipping 0.1 far z clipping 5000.0 I dont understand mathematical formulas very well, if anyone could help me out with good ol c code I''d be most gratefull =) Rick

##### Share on other sites
You''ve 4 clipping plans.
Check your bounding sphere against each plan(discard it as soon as you can, that is if it failed the first test don''t go further) and then do discard it if you need to.

Clipping plans equations can be found in any good 3d book, like Direct3D, or OpenGL books.

-* Sounds, music and story makes the difference between good and great games *-

##### Share on other sites
6 clippng planes... sorry, because the 2 others are so easy to find I always forget them.
Near and far clipping plane are simply Z=? and Z=??

If you don''t find any infos about those plans, tell me I''ll look @ my books to wrote them down.

-* Sounds, music and story makes the difference between good and great games *-

##### Share on other sites
Yes actually Direct3D has a function ComputeSphereVisibility, but I need it to be a box not an sphere. And I guess it is 4 planes, all I need to know is if this box is outside all 4 "side" planes of the frustrum. And no I don''t have any books on the subject =)

And yes I know that if I check the box against the 4 planes and find it''s "outside" in all cases, then I''d have my answer, problem is I don''t know the maths required.

Rick

##### Share on other sites
quote:
Original post by md2ge

And yes I know that if I check the box against the 4 planes and find it''s "outside" in all cases, then I''d have my answer, problem is I don''t know the maths required.

No, you only have to know if it''s outside 1 plane - if it''s outside 1 plane, it doesn''t matter about the others as it is not in view. In fact, if you are needing it to be outside all planes, you''ll never manage it. (You can''t be left of the left plane and right of the right plane at the same time.) You will rarely have to check more than the first plane before being able to say it''s out of view.

##### Share on other sites
Why a cube ?
I use control cube but compute sphere for clipping.
(Using OpenGL)
You must check against one of the 4 side clipping planes, then against the 2 Z clipping plans to fin if it''s in or out your view frustrum.

We''re using a sphere because it''s aasier to compute visibility, after all if distance between the center and the plan is bigger than the radius then it''s out or in, but not crossing :o)

Use inequations instead of equations to do proper clipping.
(That is to know on which side the object is.)

I''ll post soon the inequations you need.

-* Sounds, music and story makes the difference between good and great games *-

##### Share on other sites
Doh! I guess you''re right if it''s out of 1 plane then it''s out altogether, simpler things escape me first =)

Anyhow I was playing around with this problem last night and found something interesting.

If I set my fov to 90 and aspect ratio to .75*(w/h) then every point in camera space z == -x ... so if I have a point at z 1.0 it will go out of the frustum if x == -1.0 I thought this was pretty cool and fast! Only problem is that my objects are not in camera space =( argh new problem!

To get a point into camera space I''m guessing I have to multiply two matrix the one I send to D3DTRANSFORMSTATE_WORLD and D3DTRANSFORMSTATE_VIEW, is this correct? if so what''s this operation called? vector multiply by matrix? I guess I could find out by trial and error.

The reason I want a box not sphere is because I''m using it for a quadtree terrain thingy I''m writing, a box better resembles the shape. So when I reach a note I want to check if it''s fully outside view and cull the whole thing if not I can keep going with next nodes.

Rick

##### Share on other sites
Clipp each of the 8 vertexes of your box with this formula
and you will know if there is any point inside or outside your frustrum. And for your camera problem rotate the clipping frustrum to the world and clipp before you rotate anything..then you wont rotate anything unnecesary

x1,y1,z1 the Vertexposition
x2,y2,z2,d the plane to clipp to

if(((x1*x2)+(y1*y2)+(z1*z2))>d)printf("The vertex is in front of the plane!");
else
printf("The vertex is on the outside of the plane");

• 16
• 9
• 15
• 10
• 13