Alessandro_dup1
01-28-2003, 11:12 AM
Hi, i have a simple terrain engine built on a 1024x1024 triangle strip. I'd like, when i move the mouse on a vertex, to get the x,y,z coordinates. So i coded the following mousemove routine:
xPos = LOWORD(lParam); // horizontal position of cursor
yPos = HIWORD(lParam); // vertical position of cursor
glGetIntegerv (GL_VIEWPORT, viewport);
glGetDoublev (GL_MODELVIEW_MATRIX, mvmatrix);
glGetDoublev (GL_PROJECTION_MATRIX, projmatrix);
realy = viewport[3] - (GLint) yPos - 1;
glReadPixels(xPos,viewport[3]-yPos-19,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,(void *)pixel_depth_cp);
gluUnProject ((GLdouble) xPos, (GLdouble) realy, pixel_depth_cp[0], mvmatrix, projmatrix, viewport, &wx, &wy, &wz);
Is this code correct ? I.e. wx, wy, wz really hold the vertex coordinates ? If i want to draw a simple 3d point exactly where i click the mouse, do i have to glTranslatef to wx,wy,wz. I'm trying to say that i'd like to draw a point on the vertex where the mouse currently on.
xPos = LOWORD(lParam); // horizontal position of cursor
yPos = HIWORD(lParam); // vertical position of cursor
glGetIntegerv (GL_VIEWPORT, viewport);
glGetDoublev (GL_MODELVIEW_MATRIX, mvmatrix);
glGetDoublev (GL_PROJECTION_MATRIX, projmatrix);
realy = viewport[3] - (GLint) yPos - 1;
glReadPixels(xPos,viewport[3]-yPos-19,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,(void *)pixel_depth_cp);
gluUnProject ((GLdouble) xPos, (GLdouble) realy, pixel_depth_cp[0], mvmatrix, projmatrix, viewport, &wx, &wy, &wz);
Is this code correct ? I.e. wx, wy, wz really hold the vertex coordinates ? If i want to draw a simple 3d point exactly where i click the mouse, do i have to glTranslatef to wx,wy,wz. I'm trying to say that i'd like to draw a point on the vertex where the mouse currently on.