For my first project using jogl I decided to make just a simple 3d checkers game, but I have been having trouble with gluUnProject
Here is the code I am currently using:
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
gl.glLoadIdentity();
glu.gluLookAt(-150.0f, 150.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
int viewport[] = new int[4];
double mvmatrix[] = new double[16];
double projmatrix[] = new double[16];
int realy = 0;// GL y coord pos
double wcoordN[] = new double[4];
double wcoordF[] = new double[4];
if (mouse != null){
int x = mouse.getX(), y = mouse.getY();
gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix, 0);
gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projmatrix, 0);
// note viewport[3] is height of window in pixels
realy = viewport[3] - (int) y - 1;
glu.gluUnProject((double) x, (double) realy, 0.4, mvmatrix, 0, projmatrix, 0, viewport, 0, wcoordN, 0);
glu.gluUnProject((double) x, (double) realy, 0.9, mvmatrix, 0, projmatrix, 0, viewport, 0, wcoordF, 0);
}
The problem is I can’t seem to figure out what to actually do with the results of gluUnProject… or even if I am getting the right results. Any help would be appreciated