gluUnProject - solved

Started by
1 comment, last by O-san 16 years, 11 months ago
Hello! I'm having trouble using gluUnProject with my orthographic camera. The function gives me values that I don't expect (dx,dy,dz) although it returns success. Maybe it's because I'm not using gluLookAt()? I've used gluUnProject before but always together with gluLookAt. This is my code for setting up the the view (isometric):
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-width/2, width/2, -height/2, height/2, -1000, 1000);

    // Rotate view to 2:1 isometric
    glRotated(-60, 1, 0, 0);
    glRotated(45, 0, 0, 1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();



This is my gluUnProject code inside WM_MOUSEMOVE:

    double mvmatrix[16], projmatrix[16], dx, dy, dz;
    int viewport[4];
    double mouseX = LOWORD(lParam); // 0 at left side
    double mouseY = height-HIWORD(lParam); // 0 at bottom

    glGetIntegerv(GL_VIEWPORT, viewport);	
    glGetDoublev (GL_MODELVIEW_MATRIX, mvmatrix);
    glGetDoublev (GL_PROJECTION_MATRIX, projmatrix);

    gluUnProject (mouseX, mouseY, 0.0,
                  mvmatrix, projmatrix, viewport,
                  &dx, &dy, &dz);



Any help appreciated! [Edited by - O-san on May 15, 2007 4:24:36 AM]
Advertisement
mouseY, mouseX, 0.0

this 0.0 needs to contain the depth value ( u can get it by doing a readpixels DEPTH at mouseX, mouseY

also

// Rotate view to 2:1 isometric
glRotated(-60, 1, 0, 0);
glRotated(45, 0, 0, 1);

these should be done in the modelview, the projection only contains the projection matrix (in this case the glOrtho one)
Thanks works excellent now! :D

This topic is closed to new replies.

Advertisement