Skip to main content
GameDev.net gamedev.net
🔒 Locked

Frustrum culling question

Started by md2ge Apr 13, 2000 at 12:30 AM 6 replies 650+ views
Original Post
md2ge
md2ge
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
Ingenu
Ingenu
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 *-
-* So many things to do, so little time to spend. *-
Ingenu
Ingenu
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 *-
-* So many things to do, so little time to spend. *-
md2ge
md2ge
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
Kylotan
Kylotan
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.
Ingenu
Ingenu
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 *-
-* So many things to do, so little time to spend. *-
md2ge
md2ge
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
MatsG
MatsG
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");

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.