Sign in to follow this  
EvilProgrammer

Creating Frustum for selection box

Recommended Posts

I'm trying to create a system to allow the user to select some objects in 3d space by dragging a box around them, RTS style. I decided to turn the 2d selection box into a 3d frustum, and use frustum culling to determine whether things were in the box. I already have a system for this set up, because I use frustum culling for my rendering. I have a plane class that can create a plane out of three points. I'm using OpenGL, so I decided to grab 8 points in 3d space using GluUnProject on my two sets of mouse coordinates, and using different depth coordinates of 1.0 and 0.0 to get the far and near corners of the frustum. I realize it may be possible to construct the frustum with less than 8 points, but out of laziness I just went ahead and got all 8. So then I went and got 6 planes out of my 8 points. Obviously it's not working or I probably wouldn't be posting this. I think the problem has to do with the fact that the normals of all the planes must be pointing either into our out of the frustum. If one plane is off, it won't work. So I'm trying to figure out how to make sure that all the planes are facing the proper direction. My first idea was to find a point that I knew was inside the frustum, and check it's distance to all the planes. If the result did not come out positive, I flipped it. I believe the way to do this is to multiply the Normal and shift value by -1. If this is wrong, please tell me. The way I got a point I "knew was in the frustum" was to use GluUnProject in this manner: gluUnProject((sx-mx)*.5 + mx,(sy-my)*.5+my,0.5,mdl,proj,view,&ptx,&pty,&ptz); The screen coordinates are the center of the selection box, and the depth value is set to 0.5 for somewhere in between. Please tell me if there is something wrong with this method, because I don't think this is working either (I ran my frustum routine to see if the point was inside, and it appears sometimes it isn't (?)). So, final question: Is there some mathematical way to make sure 6 planes are all pointing the "same" way? (I also thought of taking the dot product of the normals of the planes that were across from each other to see if they were facing each other. I'm confused about it, though, and I think there may be more to it).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this