Hi everyone,
I'm currently trying to work out how to get world coordinates from JOGL - at the moment it only returns x = 0.0, y= 0.0 and z = 0.0 no matter where I click. What am I doing wrong?
public double[] getMousePosition(int x, int y){
int viewport[] = new int[4];
double modelview[] = new double[16];
double projection[] = new double[16];
float winX, winY, winZ;
float posX, posY, posZ;
double wcoord[] = new double[4];
gl.glGetDoublev( GL2.GL_MODELVIEW_MATRIX, modelview, 0 );
gl.glGetDoublev( GL2.GL_PROJECTION_MATRIX, projection, 0 );
gl.glGetIntegerv( GL2.GL_VIEWPORT, viewport, 0 );
winX = (float)x;
winY = (float)viewport[3] - (float)y;
float[] depth = new float[1];
// gl.glReadPixels(winX, winY, 1, 1, gl.GL_DEPTH_COMPONENT, GL2.GL_FLOAT, depth);
boolean test = glu.gluUnProject( winX, winY, 0.0, modelview, 0, projection, 0, viewport, 0, wcoord, 0);
System.out.println("x: " + wcoord[0] +"y: "+wcoord[1]+" worked? "+test);
System.out.println(modelview[0]);
return wcoord;
}
EDIT :: Forgot to mention that I noticed that glu.gluUnproject returns a boolean so I assigned it to a boolean called test which returns false.
EDIT2 :: I've added another debug statement - System.out.println(modelview[0]); and is also returning 0.0
Thank you for your help
James