Original Post
Hello, I'm having an hard time trying to understand why gluUnProject doesn't work as expected. My app has several orthographics views (front, top, left) and I'd like to implement pan on each of them. To pan I use gluUnProject to get the object coordinates of the mouse drag, then offset my viewing volume with glOrtho. The problem is that I can pan properly in the front view; in the others I can pan only in one direction (x or y) but none both. Here's the function I use to campute object space offset of the mouse drag, oldP and newP are pixel coordinates of the mouse drag, dx and dy is the object space offset. Once I get dx and dy I offset my view volume like this: In my display function I use this simple code to set up my projection and modelview matrix: So basically, in the front view pan works ok, but in the top and in the right view I get always respectively dy and dx = 0!...don't know why. Hope some of you guys can help cos I'm really stuck. Thanks Libe P.S: I could post I little glut test to show my problem if of any help.
void ComputeDistances(int oldP[2], int newP[2], float* dx, float* dy)
{
GLdouble modelview[16];
GLdouble proj[16];
GLint view[4];
GLdouble nP[3], oP[3];
glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
glGetDoublev( GL_PROJECTION_MATRIX, proj );
glGetIntegerv( GL_VIEWPORT, view );
/* flip y to get it openGL like (0,0) bottom left */
gluUnProject( newP[0], view[3] - newP[1], 0.0f,
modelview,
proj,
view,
&nP[0],
&nP[1],
&nP[2] );
gluUnProject( oldP[0], view[3] - oldP[1], 0.0f,
modelview,
proj,
view,
&oP[0],
&oP[1],
&oP[2] );
*dx = nP[0] - oP[0];
*dy = nP[1] - oP[1];
}
orthoViews[side].cx -= dx;
orthoViews[side].cy -= dy;
void display()
{
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho(orthoViews[side].cx - 2,
orthoViews[side].cx + 2,
orthoViews[side].cy - 2,
orthoViews[side].cy + 2,
-2,
2);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
switch(side) {
case TOP:
glRotatef(90.0, 1.0, 0.0, 0.0);
break;
case RIGHT:
glRotatef(-90.0, 0.0, 1.0, 0.0);
break;
case FRONT:
/* default gl orientation */
break;
default:
break;
}
glutWireTeapot(0.5);
glutSwapBuffers();
}