- private void projectTest(GL gl) {
- int viewPort[] = new int[4];
- double modelView[] = new double[16];
- double projection[] = new double[16];
- double result[] = new double[3];
- double z = 0.0;
- int yNew;
- gl.glGetIntegerv(GL.GL_VIEWPORT, viewPort, 0);
- gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, modelView, 0);
- gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projection, 0);
- yNew = viewPort[3] - mouse.y;
- glu.gluUnProject((double)mouse.x, yNew, z,
- modelView, 0,
- projection, 0,
- viewPort, 0,
- result, 0);
- gl.glPushMatrix();
- Point3D eye = cam.getEye();
- Point3D center = cam.getCenter();
- Point3D dir = new Point3D(center.x - eye.x, center.y - eye.y, center.z - eye.z);
- /*
- * 0 = result[1] + lambda * dir.y
- * lambda = -result[1] / dir.y
- */
- double lambda = -result[1] / dir.y;
- Point3D resXZ = new Point3D(result[0] + lambda * dir.x,
- /*result[1] + lambda * dir.y*/0.0f,
- result[2] + lambda * dir.z);
- gl.glTranslated(resXZ.x, resXZ.y, resXZ.z);
- gl.glDisable(GL.GL_LIGHTING);
- gl.glDisable(GL.GL_TEXTURE_2D);
- gl.glColor3f(1.0f, 0.0f, 0.0f);
- UnitForms.drawUnitSphere(gl, 10);
- gl.glEnable(GL.GL_LIGHTING);
- gl.glEnable(GL.GL_TEXTURE_2D);
- gl.glPopMatrix();
- }