Bonjour.
Malgres le nombre de tuto et de post que j'ai pu trouver, aucun n'a vraiment resolu mon probleme.
J'ai un cube et je voudrai que la camera tourne autour en x et y, et puisse zoomer(donc translate en z.) sur controle des boutons
Voila le code
Ce code utilise rotate et translate, quand on appui sur "r" le cube tourne et l'angle est stocke dans "angle", et avec la souris le cube tourne sur l'axe x, angle stocke dans "anglex".
Code vb : 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 Private Sub OpenGLControl1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles OpenGLControl1.KeyPress If e.KeyChar = "r" Then GL.glRotatef(5, 0, 1, 0) 'Rotation de l'axe y angle = angle + 5 If angle > 360 Then angle = 5 ElseIf e.KeyChar = "i" Then GL.glMatrixMode(GL.GL_PROJECTION) 'reglage projection GL.glLoadIdentity() GLfovy = 50 GL.gluPerspective(GLfovy, 1, 0.1, 10)'Reinitialise la vue GL.gluLookAt(0, 0, 6, 0, 0, 0, 0, 1, 0) GL.glTranslatef(0, 0, translatez) GL.glRotatef(angle, 0, 1, 0) 'Aplliques les anciennes rotations GL.glRotatef(anglex, 1, 0, 0)'anglex provient de la souris, rotation sur x translatez += 0.1 ElseIf e.KeyChar = "o" Then 'Pareil que audessus mais en arriere (- z) GL.glMatrixMode(GL.GL_PROJECTION) 'reglage projection GL.glLoadIdentity() GLfovy = 50 GL.gluPerspective(GLfovy, 1, 0.1, 10) GL.gluLookAt(0, 0, 6, 0, 0, 0, 0, 1, 0) GL.glTranslatef(0, 0, translatez) GL.glRotatef(angle, 0, 1, 0) GL.glRotatef(anglex, 1, 0, 0) translatez -= 0.1 End If Label1.Text = angle Label2.Text = anglex OpenGLControl1.Refresh() End Sub
Puis pour le "zoom" la projection est reinitialise, puis la translation sur z se fait et le cube tourne.
Mais si l'utilisateur tourne l'axe x puis l'axe y puis de nouveau x,... le cube ne sera pas a la bonne place lors du zoom.
Jespere avoir ete clair.
Merci
EDIT :
Je viens de trouver la reponse... en modifiant je me suis embrouille.
Si ca interesse quelqu'un voila ce qu'il fallait faire :
...facile en effet...
Code vb : 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 If e.KeyChar = "r" Then angle = angle + 5 ElseIf e.KeyChar = "i" Then translatez += 0.1 ElseIf e.KeyChar = "o" Then translatez -= 0.1 End If GL.glMatrixMode(GL.GL_PROJECTION) 'reglage projection GL.glLoadIdentity() GLfovy = 50 GL.gluPerspective(GLfovy, 1, 0.1, 10) GL.gluLookAt(0, 0, 6, 0, 0, 0, 0, 1, 0) GL.glTranslatef(0, 0, translatez) GL.glRotatef(angle, 0, 1, 0) GL.glRotatef(anglex, 1, 0, 0) Label1.Text = angle Label2.Text = anglex OpenGLControl1.Refresh() End Sub
Partager