Salut,

voila j'essaye de faire un petit simulateur de vol en opengl avec glut sous VC++
pour le moment j'en suis au debut
j'ai implenté un terrain (simple carre pour le moment) avec une piste histoire de se reperer
j'ai ajouté les deplacements avant/arriere (ouais je sais qui y a pas de marche arriere sur les avions) et les rotations.
Pour les rotations j'ai un souci, elles fonctionnent seulement jusqu'a 90°, (en fait je ne me retrouve jamais avec le terrain au dessus) ce qui fait que si je tourne sur 360° je fait 2 tours complets.
Et je vois pas pourquoi.

ci-joint le code
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
 
#pragma comment(lib, "opengl32.lib") //-> Librairie OpenGL.
#pragma comment(lib, "glu32.lib")  //-> Librairie GLU.
#pragma comment(lib, "glut32.lib")  //-> Librairie GLUT.
 
#include <GL/glut.h>
 
#include <iostream>
#include <string>
#include <cmath>
 
using namespace std;
 
static GLfloat roulis = 0.0;
static GLfloat tangage = 0.0;
static GLfloat cap = 0.0;
static GLfloat translation = 0.0;
 
static GLdouble posX = 0;
static GLdouble posY = 0;
static GLdouble posZ = 0;
static GLdouble ptX = 0;
static GLdouble ptY = 0;
static GLdouble ptZ = -1;
static GLdouble vhX = 0;
static GLdouble vhY = 1;
static GLdouble vhZ = 0;
 
 
void Affichage();
void Redimensionnement(int, int);
void Key(unsigned char key, int x, int y);
void Special(int key, int x, int y);
 
int main(int argc, char** argv)
{
 glutInit(&argc, argv);
 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
 glutInitWindowPosition(200, 150);
 glutInitWindowSize(640, 480);
 glutCreateWindow("Simulateur de vol");
 glutDisplayFunc(Affichage);
 glutReshapeFunc(Redimensionnement);
 glutKeyboardFunc(Key);
 glutSpecialFunc(Special);
 glutMainLoop();
 
 return 0;
}
 
void Affichage()
{
 glClearColor(0, 0, 1, 0);
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();
 gluLookAt(posX, posY, posZ, ptX, ptY, ptZ, vhX, vhY, vhZ);
 
 // terrain
 glPushMatrix();
 glRotated(roulis, 0.0, 0.0, 1.0);
 glRotated(tangage, 0.0, 1.0, 0.0);
 glRotated(cap, 1.0, 0.0, 0.0);
 glTranslated(0, -1000, translation);
 
 glColor3f(0.0, 1.0, 0.0);
 glBegin(GL_QUADS);
  glVertex3d(-5000, 0, 5000);
  glVertex3d(5000, 0, 5000);
  glVertex3d(5000, 0, -5000);
  glVertex3d(-5000, 0, -5000);
 glEnd();
 glColor3f(0.0, 0.0, 0.0);
 glBegin(GL_QUADS);
  glVertex3d(-250, 0, 0);
  glVertex3d(250, 0, 0);
  glVertex3d(250, 0, -3000);
  glVertex3d(-250, 0, -3000);
 glEnd();
 glPopMatrix();
 glutSwapBuffers();
}
 
 
void Redimensionnement(int x, int y)
{
 glViewport(0,0,x,y);
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 gluPerspective(45.0, 1.5, 0.0, 15000);
 glutPostRedisplay();
}
 
 
void Key(unsigned char key, int x, int y)
{
 switch (key)
 {
      case 27:   // Touche 'ECHAP'
         glutDestroyWindow(glutGetWindow());   // Détruit la fenêtre OpenGL
         exit (0);
 
   case 'a':
   case 'A':
  translation = translation+50;
  cout << translation << endl;
  glutPostRedisplay();
  break;
 
   case 'q':
   case 'Q':
  translation = translation-50;
  cout << translation << endl;
  glutPostRedisplay();
  break;
 
   case 'r':
   case 'R':
    translation = 0;
    roulis = tangage = cap = 0;
    glutPostRedisplay();
    break;
 
   case 'x':
   case 'X' :
    tangage = tangage+1;
    if (tangage > 360.0) tangage = tangage-360.0;
    cout << "tourne a gauche" << tangage <<  endl;
    glutPostRedisplay();
    break;
 
   case 'w':
   case 'W' :
    tangage = tangage-1;
    if (tangage  < -360.0) tangage = tangage+360.0;
    cout << "tourne a droite" << tangage << endl;
    glutPostRedisplay();
    break;
 
 
   }
}
 
 
void Special(int key, int x, int y)
{
 switch (key)
 {
   case GLUT_KEY_LEFT:
  roulis = roulis+1.0;
  if (roulis > 360.0) roulis=roulis-360.0;
  cout << "lateral gauche" << roulis << endl;
  glutPostRedisplay();
    //glutIdleFunc(left);
  break;
 
   case GLUT_KEY_RIGHT:
  roulis = roulis-1.0;
  //if (roulis > 90 ){
  // vhY=-1;
  // roulis = 0;
   //vhX=-1;
  //}
  if (roulis < -360.0) roulis=roulis+360.0;
  cout << "lateral droit" << roulis << endl;
  glutPostRedisplay();
    //glutIdleFunc(right)
  break;
 
   case GLUT_KEY_UP:
  cap = cap+1;
  if (cap > 360.0) cap=cap-360.0;
  cout << "avant" << cap << endl;
  glutPostRedisplay();
  break;
 
   case GLUT_KEY_DOWN:
  cap = cap-1;
  if (cap < -360.0) cap=cap+360.0;
  cout << "arriere" << cap << endl;
  glutPostRedisplay();
  break;
 }
}