Bonjour
J'ai mis au point un système de mouse pan avec la souris. En gros, tant que je clique, ma caméra se déplace sur les X et les Y de ma scène.
Voici un extrait de code:
Or, mon problème est que si je déplace une fois avec la souris, OK, tout va bien. Mais je reclique, je me rend à nouveau au centre de ma scène.
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public void display(GLAutoDrawable arg0) { final GL gl = arg0.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); //other stuff if (firstDraw) { this.mustCenter = true; this.firstDraw = false; } else if (mustCenter) { setWrap(); wrap.setCenter(); qX = startX - wrap.centerX; qY = startY - wrap.centerY; x_f = y_f = 0; mustCenter = false; last_x = qX + x_f; last_y = qY + y_f; } else { //travelling with mouse if(travelling){ if(this.movePoint!=null){ lastx = this.movePoint.getX(); lasty = this.movePoint.getY(); double[]wcoord = Utils.convertIntoGL(gl, lastx, lasty); last_x = (float)wcoord[0]; last_y = (float)-wcoord[1]; } } //travelling with keyboard else{ last_x+=x_f; last_y+=y_f; x_f = y_f = 0; } } gl.glTranslatef(last_x, last_y, 0); //drawing a marvellous scene } public void mouseDragged(MouseEvent arg0) { if (picking) { if (arg0.getButton() == 0) { this.point = arg0.getPoint(); this.mouse_state = this.PICKED; } } else if (travelling) { movePoint = arg0.getPoint(); } }
Comment résoudre ce problème ?
Merci d'avance de votre aide.
@++
Partager