Hi guys,

I create my point cloud viewer and now i’m trying to implement mouse points picking. I find a lot of tutorials about this issue but i have some problems.

i draw on the screen my point cloud by:

```
GLsizei vx, vy;
vx = glutGet( GLUT_WINDOW_WIDTH );
vy = glutGet( GLUT_WINDOW_HEIGHT );
double aspect = double(vx)/double(vy);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective( 45*zoomFactor, aspect, 1, 100. );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt ( 0, 0, 10., 0., 0., 0., 0., 1., 0. );
```

glMultMatrixf(matrix);

glPointSize(3.0);

glBegin(GL_POINTS);

for(int i = 0; i < content->nvertex; i++){

glVertex3f(content->vertexes[i].x, content->vertexes[i].y, content->vertexes[i].z);

}

glEnd();

glutSwapBuffers();

glFlush();

where matrix is a rotation matrix calculate by trackball.

When I click on the screen I’m able to get (x,y) screen coordinate and then i want get 3D world-coordinate by:

GLdouble sx, sy, sz; GLdouble ex, ey, ez;

```
GLint viewport[4];
GLdouble modelview[16];
GLdouble projection[16];
GLsizei vx, vy;
vx = glutGet( GLUT_WINDOW_WIDTH );
vy = glutGet( GLUT_WINDOW_HEIGHT );
double aspect = double(vx)/double(vy);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45*zoomFactor, aspect, 1, 100. );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt ( 0, 0, 10., 0., 0., 0., 0., 1., 0. );
glMultMatrixf(matrix);
GLint realy;
glGetIntegerv(GL_VIEWPORT,viewport);
glGetDoublev(GL_MODELVIEW_MATRIX,modelview);
glGetDoublev(GL_PROJECTION_MATRIX,projection);
realy = viewport[3] - y;//viewport[3] - y;
gluUnProject( (double) x, realy, 0.0, // Near
modelview, projection, viewport,
&sx, &sy, &sz );
cout << sx << ", " << sy<< ", " << sz<< ", " << endl;
gluUnProject( (double) x, realy, 1.0f, // Far
modelview, projection, viewport,
&ex, &ey, &ez );
```

and I pick a point by ray tracing.

I create a simple example where a set of points (1,0,0) (2,0,0) (3,0,0) (4,0,0) … (10,0,0) are drawn on the screen but i can pick the point only if i move the mouse between first point and second one. If I rotate this points by trackball i have similar problem. I’m not to be able to find a solution. I search on google for long times but nothing help me to solve this problem.

Please help me!!

bye

G.