lishaak
Junior Newbie
|
 |
«
Posted
2007-09-28 11:21:02 » |
|
I have a problem with GLU.gluUnProject() function. I am traying to unproject mouse coordinates in the viewport to the ZX plane in my 3D scene. I wrote the following code:
public Point3D.Double DPtoLP(int x, int y) { GLContext context = this.getContext(); context.makeCurrent(); final GL OpenGL = context.getGL(); float winX = (float)x; float winY = (float)y; int[] viewport = new int[4]; double[] modelview = new double[16]; double[] projection = new double[16]; OpenGL.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0); OpenGL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, modelview, 0); OpenGL.glGetDoublev(GL.GL_PROJECTION_MATRIX, projection, 0); winY = (float)viewport[3] - winY; double[] nearPos = new double[3]; double[] farPos = new double[3]; glu.gluUnProject(winX, winY, 0.0, modelview, 0, projection, 0, viewport, 0, nearPos, 0); glu.gluUnProject(winX, winY, 1.0, modelview, 0, projection, 0, viewport, 0, farPos, 0); double sx = farPos[0] - nearPos[0]; double sy = farPos[1] - nearPos[1]; double sz = farPos[2] - nearPos[2]; double a = nearPos[0] - (nearPos[1]/sy)*sx; double b = nearPos[2] - (nearPos[1]/sy)*sz; context.release(); return new Point3D.Double(a, 0.0, b); }
Variables a, b should be x, z coordinates on the XZ plane. But when I execute this code there is complete rubbish in a,b variables. Has anyone any idea why this code does not work? Maybe am making some very silly mistake....
|