Projection matrix for picking.

I guess, this is more a math-problem. But since the math forum is hardly visited, I try my luck here…

I have to generate a projection matrix for picking. This matrix builds the frustum around a pixel at a given 2D viewport coordinate. Until now I could generate this matrix from knowns like fov, aspect ratio, near and farplane (symmetric projection), just like I would use glFrustum().

Now I´m facing the problem that I do not know aspect, fov etc. anymore. The only thing I got left is a projection matrix (arbitrary; could be projective, orthographic symmetric or asymmetric)that I get handed over. The challenge is to manipulate that given projection matrix in order to achieve the same effect (i.e. bound the frustum around the pixel that the user clicked on.)

I´m not good at maths in homogeneous coordinates. But I was hoping that I could easily “move” the frustum-planes in clipspace by just manipulating some of the values in the projection matrix. Any hints are welcome.

What about using the gluPickMatrix function?

Picking projection looks something like this

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPickMatrix(x, viewport[3] - y, pickWidth, pickHeight, viewport);
gluPerspective(...); // or whatever your projection matrix setup is.

You’ll find examples on the web.

Thank you, I just figured this out. The thing is that I need the maths in order to calculate the matrices myself.

But now as I know how gluPickMatrix is supposed to work, I can come up with the maths myself:

  1. map the given viewport-subregion into clipspace (assuming that the given viewport covers -1…1)
  2. compute a matrix which scales and translates this clipspace-subregion to cover the whole area of -1…1 in X and Y
  3. no changes are made to the depthvalues

Am I right?

Source is here:
http://oss.sgi.com/cgi-bin/cvsweb.cgi/~c…=text%2Fplain

The cool thing is, I´ve come to the same math and understand how/why it works.

The bad thing is, its so easy that I feel kinda dumb now :smiley: