rotating a globe on mouse drag is not smooth

Hello All
I have a map wrapped on a sphere using textures. have implemented rotation of the sphere on dragging of mouse. but the rotation is not happening properly. the code to rotate is attached .

any ideas what is wrong . thanks in advance

schiz

   public void move(GL gl, GLU glu) {
        
        gl.glGetDoublev( GL.GL_MODELVIEW_MATRIX, modelview,0 );
        gl.glGetDoublev( GL.GL_PROJECTION_MATRIX, projection,0 );
        gl.glGetIntegerv( GL.GL_VIEWPORT, viewport ,0);
        
        double winX = clickX;
        double winY = viewport[3] - clickY;
        float[] winZ = new float[1];
        FloatBuffer buf = FloatBuffer.wrap(winZ);
        gl.glReadPixels( clickX, (int)winY, 1, 1, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, buf );
        winZ[0] = buf.get(0);
        
        
        double[]    worldX = new double[1];
        double[]    worldY = new double[1];
        double[]    worldZ = new double[1];
        double[]    world  = new double[3];
        
        
        glu.gluUnProject( winX, winY, (double)winZ[0], modelview,0, projection,0, viewport,0, world, 0 );
        
        Vec3d worldVec = new Vec3d(world[0], world[1], world[2]);
        Vec3d prevVec = new Vec3d(prevX,prevY,prevZ);
        Vec3d normal = prevVec.cross(worldVec);
        normal.normalize();
        
        //double angle = Math.acos(worldVec.dot(prevVec) / ( worldVec.length() * prevVec.length() )) ;
        
        
       // Rotf rotate = new Rotf(normal.toFloat(),(float)angle);
        
        
        Vec3d from = new Vec3d(prevX,prevY,prevZ);
        Vec3d to = new Vec3d(world[0], world[1], world[2]);
        
        System.out.println("PREV " + from.toString());
        System.out.println("To " + to.toString());
        prevX = world[0];
        prevY = world[1];
        prevZ = world[2];
        
        
        
        Rotf rot = new Rotf(from.toFloat() , to.toFloat());
        rot.normalize();
        
        orientation = orientation.times(rot.inverse());
        
        
        
        double r = Math.sqrt( world[0] * world[0] + world[1] * world[1] + world[2] * world[2] );
        double lon = Math.toDegrees( Math.atan2( world[2], world[0] ) );
        double lat = 90 - Math.toDegrees( Math.acos( world[1] / r ) );
        dragged = false;
        
        
    }

Hi,
I have made the same code sample and my call to gluUnproject is rather


glu.gluUnProject ( winX, winY, (double)winZ[0], model_view, projection, viewport, worldX, worldY, worldZ );

Once you have the lat and lon for the clicked point (obtained via the previuos code) you just have to do


                gl.glRotated( nextLat, 1.0,0.0, 0.0 );
                gl.glRotated( -nextLon, 0.0,1.0, 0.0 );   

At least it’s my understanding, hope it helps.