Results 1 to 3 of 3

Thread: Query about redbook picking example 12.3

  1. #1
    Member Contributor
    Join Date
    Jun 2003
    Location
    Blacksburg, VA 24060, USA
    Posts
    59

    Query about redbook picking example 12.3

    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).]

  2. #2
    Senior Member Regular Contributor
    Join Date
    Oct 2002
    Location
    San Diego, CA, USA
    Posts
    209

    Re: Query about redbook picking example 12.3

    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).]

  3. #3
    Member Contributor
    Join Date
    Jun 2003
    Location
    Blacksburg, VA 24060, USA
    Posts
    59

    Re: Query about redbook picking example 12.3

    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

Similar Threads

  1. Redbook Ex. 2-16/17
    By Banangroda in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 02-15-2009, 10:12 AM
  2. Z-buffer picking, gluUnProject picking not working
    By Icetigris in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-29-2008, 10:38 AM
  3. Query about Selection example in the Redbook
    By virtualchetan in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-22-2003, 09:38 AM
  4. Redbook?
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-28-2001, 04:36 PM
  5. REDBOOK 1.1 & REDBOOK 1.0
    By imported_Douglas in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-30-2000, 07:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean