Results 1 to 3 of 3

Thread: picking under mfc

  1. #1
    Junior Member Newbie
    Join Date
    May 2001
    Location
    Wichita, KS USA
    Posts
    1

    picking under mfc

    I can code simple entity picking using Win32
    programs and the glut library. However,
    when I try to code the same using an MFC
    (microsoft foundation classes) approach, the
    number of hits returned is always 0. Any
    help for this beginner would be greatly
    appreciated. I would be happy to list the
    code if helpful.

  2. #2
    Junior Member Newbie
    Join Date
    May 2001
    Location
    France
    Posts
    23

    Re: picking under mfc

    Hi,

    My solution seems to work but there is some problems when we rotate the camera. So i give you the code:

    Code :
    CWindowsGLDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
     
    CPaintDC dc(this);
     
    GLuint selectBuffer[BUFFSIZE];
    GLint hits;
    GLint viewport[4];
     
    glGetIntegerv(GL_VIEWPORT, viewport);
     
    glSelectBuffer(BUFFSIZE, selectBuffer);
    glRenderMode(GL_SELECT);
     
    glInitNames();
    glPushName(0);
     
    double size = 0.0, s;
    std::vector<Piece *>::iterator it;
    for(it = pDoc->graphics.begin(); it != pDoc->graphics.end(); it++) {
    s = (*it)->size();
    if(s > size) size = s;
    }
     
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluPickMatrix(point.x, viewport[3]-point.y, 1.0, 1.0, viewport);
    gluPerspective(30.0, 1.0, 0.01 * size, 30.0 * size);
     
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    gluLookAt(0.0, 8.0*size, 6.0*size, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    glRotated(angleYVue,1.0, 0.0, 0.0);
    glRotated(angleXVue,0.0,1.0,0.0);
     
    for(it = pDoc->graphics.begin(); it != pDoc->graphics.end(); it++)
    (*it)->internalDraw(1);
     
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
     
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
     
    hits = glRenderMode(GL_RENDER);
     
    int numPiece = Proces****s(hits, selectBuffer);
     
    for(it = pDoc->graphics.begin(); it != pDoc->graphics.end(); it++)
    if( (*it)->getNumeroGL() == numPiece ){
    pDoc->pSelected = (*it); 
    pDoc->pSelected->setSelected();
    }
    else{
    if((*it)->isSelected())
    (*it)->setSelected();
    }
     
    Invalidate(FALSE);
    </CODE>
     
    I'm using glLoadName() and to retrieve the object i'm using
     
    <CODE>
     
    int CWindowsGLView::Proces****s(GLint hits,GLuint buffer[])
    {
    int i;
    int j;
    int number;
    int name;
    GLint z1;
    GLint z2;
    int zMin = MAX_VALUE;
    GLuint *ptr;
     
    ptr = (GLuint *) buffer;
     
    for(i=0;i<hits;i++){ //for each hit
    number = *ptr;
    ptr++;
    z1 = *ptr;//zmin
    ptr++;
    z2 = *ptr;//zmax
    ptr++;
     
    if(z1<zMin){
    for(j=0;j<number;j++){ //for each name
    zMin = z1;
    name = *ptr;
    ptr++;
    }
    }
    } 
    return name;
    }
    I hope it will help you.
    TORNIERI Christophe
    Ecole Supérieure en Sciences Informatiques

  3. #3
    Junior Member Newbie
    Join Date
    May 2001
    Location
    France
    Posts
    23

    Re: picking under mfc

    Hi,

    The code i posted is correct but you must clear the buffer before after glPushName(0).

    Some explanations on the code. you must replace glPerspectice by the projection matrix you use to draw your scene. Before drawing an object make a glLoadName(identifier for this object). Use only glPushName where i'used it so only one time for initializing the stack.

    Bye.
    TORNIERI Christophe
    Ecole Supérieure en Sciences Informatiques

Similar Threads

  1. Z-buffer picking, gluUnProject picking not working
    By Icetigris in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-29-2008, 10:38 AM
  2. Picking in 3D - plz help
    By beautiful world in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-30-2002, 10:39 AM
  3. Picking
    By imported_Dominik in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-13-2002, 01:03 PM
  4. picking again.....
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-15-2002, 06:34 AM
  5. picking
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-14-2002, 05:31 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