I have written a map viewing application that successfully views maps, so the physical coordinates look like (-74,40) with z fairly irrelevant.
Now I want to pick, so I tried to use gluunproject. In order to do it, I need the projection and modelview matrices.
So I wrote:
public void unproject(Viewer v, int x, int y) {
GL gl = v.getGL();
GLU glu = v.getGLU();
double[] projection = new double[16];
double[] model = new double[16];
gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projection);
gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, model);
System.out.println("Projection");
for (int i = 0; i < projection.length; i+= 4) {
System.out.println(projection[i] + "\t" + projection[i+1] + "\t" +projection[i+2] + "\t" +projection[i+3]);
}
System.out.println("Model");
for (int i = 0; i < model.length; i+= 4) {
System.out.println(model[i] + "\t" + model[i+1] + "\t" +model[i+2] + "\t" +model[i+3]);
}
int[] view = { viewportX, viewportY, viewportWidth, viewportHeight };
System.out.println(view[0] + "," + view[1] + "," + view[2] + "," + view[3]);
double[] px = { -1 };
double[] py = { -1 };
double[] pz = { -1 };
System.out.println(x + "," + y);
glu.gluUnProject(x, y, 0, model, projection, view, px, py, pz);
System.out.println(px[0] + "," + py[0] + "," + pz[0]);
}
The values coming out of the projection and modelview matrices are zero. How is this possible, since I am seeing the correct stuff on the screen, obviously the projections are set right?