Bonjour
J'éprouve quelques problèmes avec gluUnproject. Dans ma méthode de gestion à la souris, je veux retourner les coordonnées de la souris sur l'écran et dans mon "monde", d'où l'utilisation de gluUnproject:
Le code compile correctement mais lorsque j'utilise ma souris, les coordonnées sont de 0,0
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public void mousePressed(MouseEvent arg0) { this.point = arg0.getPoint(); this.mouse_state = this.PICKED; int viewport[] = new int[4]; double mvmatrix[] = new double[16]; double projmatrix[] = new double[16]; int realy = 0;// GL y coord pos double wcoord[] = new double[4];// wx, wy, wz;// returned xyz coords GLU glu = new GLU(); int x = this.point.x, y = this.point.y; 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 = (int) y - 1; System.out.println("Coordinates at cursor are (" + x + ", " + realy); glu.gluUnProject((double) x, (double) realy, 0.0, // mvmatrix, 0,// projmatrix, 0, // viewport, 0, // wcoord, 0); System.out.println("World coords at z=0.0 are ( " // + wcoord[0] + ", " + wcoord[1] + ", " + wcoord[2] + ")"); this.mw.refresh(); }
Voici mes méthodes init et reshape:
Merci d'avance de vos lumières.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 public void init(GLAutoDrawable arg0) { this.gl = arg0.getGL(); gl.glShadeModel(GL.GL_SMOOTH); // Enable Smooth Shading gl.glClearColor(1f, 1f, 1f, 1f); gl.glClearDepth(1.0f); arg0.addMouseListener(this); arg0.addMouseMotionListener(this); } public void reshape(GLAutoDrawable arg0, int x, int y, int w, int h) { this.gl = arg0.getGL(); GLU glu = new GLU(); gl.glViewport(0, 0, w, h); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glu.gluOrtho2D(-2f, 2f, -2f, 2f); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); }
@++
Partager