1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| void GetOGLPos(int x, int y, JTextField textField)
{
double winX, winY,winZ;
java.nio.ByteBuffer buffer = BufferUtil.newByteBuffer(4);
double position[]=new double[3];;
gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix, 0);
gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projmatrix, 0);
gl.glEnable(GL.GL_DEPTH_TEST);
winX = (float)x;
winY = (float)viewport[3] - (float)y;
gl.glReadPixels( x, (int)winY, 1, 1, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, buffer );
glu.gluUnProject((double) winX, (double) winY, (double)buffer.getFloat(), //
mvmatrix, 0,
projmatrix, 0,
viewport, 0,
position, 0);
DecimalFormat df = new DecimalFormat ( ) ;
df.setMaximumFractionDigits ( 3 ) ; //arrondi à 2 chiffres apres la virgules
textField.setText(
df.format(position[0] + " || " +
df.format(position[1] + " || " +
df.format(position[2] +
);
mousePosition[0] = position[0];
mousePosition[1] = position[1];
mousePosition[2] = position[2];
} |
Partager