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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
private void getCoordInRealWorld(GL gl, double x, double y, double z) {
GLU glu = new GLU();
int viewport[] = new int[4];
double mvmatrix[] = new double[16];
double projmatrix[] = new double[16];
double wcoord[] = new double[4];// wx, wy, wz;// returned xyz coords
//int realy = 0;// GL y coord pos
gl.glGetIntegerv(gl.GL_VIEWPORT, viewport, 0);
gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, mvmatrix, 0);
gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, projmatrix, 0);
boolean b = glu.gluProject(x, y, z, //
mvmatrix, 0,//
projmatrix, 0, //
viewport, 0, //
wcoord, 0);
System.out.println(b);
for(int i=0; i<wcoord.length; i++){
System.out.print(wcoord[i]+"\t");
}
System.out.println();
}
public void display(GLAutoDrawable drawable) {
gl = drawable.getGL();
// Clear the drawing area
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, zoom);
gl.glColor3f(1.0f, 0.0f, 0.0f);
gl.glBegin(gl.GL_POLYGON);
gl.glVertex3f(-1.0f, 1.0f, 0.0f);
getCoordInRealWorld(gl, -1.0f, 1.0f, 0.0f);
gl.glVertex3f(1.0f, 1.0f, 0.0f);
getCoordInRealWorld(gl, 1.0f, 1.0f, 0.0f);
gl.glVertex3f(1.0f, -1.0f, 0.0f);
getCoordInRealWorld(gl, 1.0f, -1.0f, 0.0f);
gl.glVertex3f(-1.0f, -1.0f, 0.0f);
getCoordInRealWorld(gl, -1.0f, -1.0f, 0.0f);
gl.glEnd();
// Flush all drawing operations to the graphics card
gl.glFlush();
} |
Partager