Object selection frustum

Started by
3 comments, last by LowCalorieSoftDrink 17 years, 2 months ago
Hi, I'll get straight to the point. I know it's possible to derive the 6 planes of a frustum from the combination of your model-view and projection matrix and I have a system set up to do this. If I drag a rectangle over my 3d window of an arbitrary size and position can I calculate a projection matrix that I can use to construct a frustum that represents this object selection volume in 3d? I also know it's possible to project the rectangle onto the near and far plane and construct the 6 planes from these points. That is a reasonable fall back method if the above isn't possible. However if it is possible, from a curiosity point of view, and to aid my understanding of how projection matrices work and are derived I would appreciate any pointers in the right direction. I'm using DirectX in case that is important. Thanks in advance for any help!
Advertisement
The projection matrix basically transforms the frustum into a cube. When you draw a rectangle, you are drawing it on one side of the cube which represents the near plane (at z = 0). You also want to replicate that rectangle on the far plane (at z = 1 since this is a unit cube). I always forget what the clip-ranges are for DirectX and OpenGL, so it could be z = -0.5 for the near plane and z = 0.5 for the far plane. At any rate, you transform each of the 8 points (which are 4D homogeneous coordinates with W = 1) by the inverse projection matrix into homogeneous camera-space. Perform the homogeneous divide to get the actual 3D coordinate values, you can use them to calculate the frustum planes.

Edit: Changed world-space to camera-space.

[Edited by - Zipster on February 15, 2007 6:03:49 AM]
Thanks for the answer.

I have already found this suggested method in a previous forum post on the subject. I know it will give me the desired result but I was interested to find out if it was possible to derive a projection matrix for the screen space rectangle based on the windows projection and use this in the algorithm outlined in the "plane extraction" paper by Gil Gribb and Klaus Hartmann.

If not then I'll use your suggestion
Ah sorry, I misread your post [smile]

It's possible to generate such a frustum. The D3DX function D3DXMatrixPerspectiveOffCenterLH does just that, based on (left,right,top,bottom,near,far) values. If you want to code it yourself, that link shows how the matrix is generated. The assumption is that (0,0,0) is the eye point, so you still need to unproject the clip-space rectangle to camera-space. But it's still better than all the vector operations you'd be stuck doing otherwise (as you well know).
So if I project the screen space rectangle onto the near plane, then use the top-left x and y as the left and top parameters of PerspectiveOffCenterLH and similarly the bottom-right x and y as the bottom and right parameters that should be the correct perspective matrix?

Thanks for the help, exactly what I was looking for :)

Edit: I can't type

This topic is closed to new replies.

Advertisement