problem around picking. isn't precise...


public static void computeViewRay( int[] mousePos){
        double[] eyeModelview = new double[16], eyeProjectionView = new double[16];
        gl.glGetDoublev( GL.GL_MODELVIEW_MATRIX, eyeModelview );
        gl.glGetDoublev( GL.GL_PROJECTION_MATRIX, eyeProjectionView );
        gl.glGetIntegerv( GL.GL_VIEWPORT, rayViewport );

        glu.gluUnProject( mousePos[0], rayViewport[3]-mousePos[1],0,eyeModelview,eyeProjectionView,rayViewport,nx,ny,nz); //mouse world position at near poly
        glu.gluUnProject( mousePos[0], rayViewport[3]-mousePos[1],1,eyeModelview,eyeProjectionView,rayViewport,fx,fy,fz); //mouse world position at far poly

        ray[0] = eye;
        ray[1] = new Vector34f( (float)(fx[0]-nx[0]),(float)(fy[0]-ny[0]),(float)(fz[0]-nz[0]) );
    }

in close distance, it works well, but far away the ray computation “moves away”, it will be approx 32 pixel distance between my mouse pos and computed position.
How can i correct this?

Thanks…

Use gluPickMatrix instead

http://www.mevis.de/opengl/gluPickMatrix.html

Thanks, but i have to use picking ray to able to use it on terrain.

I had an incorrect computation. Here is the correct one:


glu.gluUnProject( mousePos[0], rayViewport[3]-mousePos[1]   - 1  ,0,eyeModelview,eyeProjectionView,rayViewport,nx,ny,nz); //mouse world position at near poly
glu.gluUnProject( mousePos[0], rayViewport[3]-mousePos[1]   - 1  ,1,eyeModelview,eyeProjectionView,rayViewport,fx,fy,fz); //mouse world position at far poly