PDA

View Full Version : Query about redbook picking example 12.3



virtualchetan
10-10-2003, 05:19 AM
Here is a link for redbook online: http://fly.cc.fer.hr/~unreal/theredbook/chapter12.html
Example 12.3 shows picking.

For picking it uses following code:
................
glMatrixMode (GL_PROJECTION);
glPushMatrix ();
glLoadIdentity ();
/* create 5x5 pixel picking region near cursor location */
gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] - y), 5.0, 5.0, viewport);
gluOrtho2D (0.0, 3.0, 0.0, 3.0);
drawSquares (GL_SELECT);
glPopMatrix ();
glFlush ();
........

1)As shown above, pickSquares method sets up the picking, ie. render mode, gluPickMatrix(..) etc. While doing that it changes GL_MATRIX_MODE to GL_PROJECTION, but doesn't set that back to GL_MODELVIEW. For drawing nething, the matrix mode must be GL_MODELVIEW, right? Then how does this example work?

2) In the reshape ,method it already has
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D (0.0, 3.0, 0.0, 3.0);

So, in the Projection Matrix stack there is the correct matrix for projection,
Now, while picking, that matrix is pushed down and the stack top is replaced by identity, and then gluPickMatrix().. etc. after picking its poped out.

So, WHILE picking the projection matrix-Stack
contains the original matrix at the bottom (inserted in reshapeFunc) and a new one at the top, (inserted by the picking code)
Actually the correct matrix to have is ONLY the top one..., right?
Then how does the example work correctly?


- Chetan


[This message has been edited by virtualchetan (edited 10-10-2003).]

147-2
10-10-2003, 09:22 AM
as far as I have seen, the matrix mode only affects the effect of calls such as glRotate() glTranslate() glMultMatrix() and other matrix related functions. I have never tried to draw geometry while in the projection matrix mode, nor any other mode (other than modelview) for that matter, but I can't see why it wouldn't work.
Yes, the top matrix of a stack is the only one that is regarded by OpenGL.


You caught me on that one... I try not to make sense :P

[This message has been edited by 147-2 (edited 10-13-2003).]

virtualchetan
10-10-2003, 10:00 AM
I have never tried to draw geometry while in the projection matrix mode, nor any other mode for that matter, but I can't see why it wouldn't work.

Yeah, that makes sense. It will work fine as long as u dont do ne matrix operations.


Yes, the top matrix of a stack is the only one that is regarded by OpenGL.

I see, I was under impression that the whole stack is multiplied to form the correct transformation matrix.

Thanks,

Chetan