Jump to content
  • Advertisement
Sign in to follow this  
O-san

gluUnProject - solved

This topic is 4055 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!