double[] proj = new double[16];
double[] model = new double[16];
double[] mousePosArr = new double[4];
try{
PGraphicsOpenGL pgl = ((PGraphicsOpenGL)applet.g);
GL gl = pgl.beginGL();
GLU glu = pgl.glu;
gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, proj, 0);
gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, model, 0);
/*
System.out.println("OpenGL ProjectionMatrix: ");
for (int i = 0; i < proj.length; i++) {
double p = proj[i];
System.out.print(p + ", ");
//if (i%4 == 0 && i==3)
if (i==3 || i== 7 || i== 11 || i==15) {
System.out.println();
}
}
*/
/*
System.out.println("OpenGL ModelviewMatrix: ");
for (int i = 0; i < model.length; i++) {
double p = model[i];
System.out.print(p + ", ");
//if (i%4 == 0 && i==3)
if (i==3 || i== 7 || i== 11 || i==15) {
System.out.println();
}
}
System.out.println();
System.out.println("\n");
*/
/*
fbUn.clear();
gl.glReadPixels((int)screenX, applet.height - (int)screenY, 1, 1, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, fbUn);
fbUn.rewind();
glu.gluUnProject((double)screenX, applet.height - (double)screenY, (double)fbUn.get(0), model, 0, proj, 0, viewport, 0, mousePosArr, 0);
*/
//FIXME test not using glReadpixel to get the depth at the location
//instead we have to build a ray with the result, from the camera location going through the resulst and check for hits ourselves
glu.gluUnProject((double)screenX, applet.height - (double)screenY, 0, model, 0, proj, 0, viewport, 0, mousePosArr, 0);
pgl.endGL();
returnVect = new Vector3D((float)mousePosArr[0], (float)mousePosArr[1], (float)mousePosArr[2]);
}catch(Exception e){
e.printStackTrace();
//System.out.println("Use method getWorldForScreenCoords only when drawing with openGL! And dont put negative screen values in!");