00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00032 #include <sstream>
00033 #include <string.h>
00034 #include <iostream>
00035
00036 #ifdef WIN32
00037 #include <string.h>
00038 #else
00039 #include <strings.h>
00040 #endif
00041
00042
00043
00045
00046 #include <GLUT/glut.h>
00047
00048
00049
00050
00052 #include "trackball.h"
00053
00055 #include "Navigation.h"
00056
00058 #include "Noeuds.h"
00059 #include "Scene.h"
00060 #include "Mesh.h"
00061 #include "ObjetSimule.h"
00062
00063
00065 int trackballBeginX, trackballBeginY;
00066
00067 GLuint trackballWidth, trackballHeight;
00068 GLint trackballButton = GLUT_LEFT_BUTTON;
00069 bool trackballTracking = false;
00070
00071 GLuint trackballLastTime;
00072 float currentQuaternion[4];
00073 float newQuaternion[4];
00074
00075 float scale_factor = 1.0;
00076 GLint xGL, yGL;
00077
00078 eShading shadingMode = SHADING_SMOOTH;
00079
00080 bool normalDisplaying = false;
00081
00082
00083
00085 Scene *S;
00086
00088 int _NbObj;
00089
00091 std::string _Affichage = "fil";
00092
00094 int Tps = 0;
00095
00096
00097
00098
00102 void display(void)
00103 {
00104
00105 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
00106
00107 glPushMatrix();
00108 GLfloat m[4][4];
00109 build_rotmatrix(m, currentQuaternion);
00110 glMultMatrixf(&m[0][0]);
00111 glScalef(scale_factor, scale_factor, scale_factor);
00112
00113 glDisable(GL_LIGHTING);
00114
00115
00117 glLineWidth (2);
00118 glColor3f(1.0, 0.0, 0.0);
00119 glBegin(GL_LINES);
00120 glVertex3f(0.0,0.0,0.0);
00121 glVertex3f(1.0,0.0,0.0);
00122 glEnd();
00123
00124 glLineWidth (2);
00125 glColor3f(0.0, 1.0, 0.0);
00126 glBegin(GL_LINES);
00127 glVertex3f(0.0,0.0,0.0);
00128 glVertex3f(0.0,1.0,0.0);
00129 glEnd();
00130
00131 glLineWidth (2);
00132 glColor3f(0.0, 0.0, 1.0);
00133 glBegin(GL_LINES);
00134 glVertex3f(0.0,0.0,0.0);
00135 glVertex3f(0.0,0.0,1.0);
00136 glEnd();
00137
00139
00140
00141 if (_Affichage == "fil")
00142 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
00143
00144
00145 else if (_Affichage == "remplissage")
00146 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00147
00148
00149 else if (_Affichage == "texture")
00150 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00151
00152
00153
00154
00155 S->affiche();
00156
00157 glutSwapBuffers() ;
00158 glPopMatrix() ;
00159 glFlush() ;
00160
00161 }
00162
00163
00167 void idle(void)
00168 {
00169
00170 S->Simulation(Tps);
00171 Tps = Tps + 1;
00172
00173 glutPostRedisplay();
00174 }
00175
00176
00180 int main(int argc, char *argv[])
00181 {
00182
00188
00189 std::string *Fichier_Param;
00190
00192 if (argc >= 2)
00193 {
00194
00195 _NbObj = atoi(argv[1]);
00196 std::cout << "Nombre d objets dans la scene : " << _NbObj << std::endl;
00197
00198
00199
00200
00201 Fichier_Param = new std::string[_NbObj+1];
00202
00203
00204
00205
00206 for (int i=0; i<= _NbObj; i++)
00207 Fichier_Param[i] = argv[i+2];
00208 }
00209
00210 else
00211 {
00212
00213 std::cout << "Usage : ObjetDeformable NbObj <Fichier_Param_Anim> <Fichier_Param_Obj1> <Fichier_Param_Obj2> ..." << std::endl;
00214
00215
00216 exit(1);
00217
00218 }
00219
00221 S = new Scene(Fichier_Param[0]);
00222
00224 for (int i=1; i<= _NbObj; i++)
00225 S->attache(new ObjetSimule(Fichier_Param[i]));
00226
00227
00229
00230 S->init();
00231
00232
00234 std::cout << "Simulation Begin...." << std::endl;
00235 S->Simulation(Tps);
00236
00237
00242 int win;
00243
00244
00245 glutInit(&argc, argv);
00246
00247 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
00248
00249
00250 glutInitWindowSize(400,500);
00251
00252
00253 win = glutCreateWindow("Animation 3D");
00254
00255
00256
00257 glClearColor(0.0,0.0,0.0,0.0);
00258
00259
00260 gluOrtho2D(0,400,0,500);
00261
00262
00263 glutDisplayFunc(display);
00264
00265
00266 glutKeyboardFunc(keyboard);
00267 glutReshapeFunc(reshape);
00268 glutMotionFunc(motion);
00269 glutMouseFunc(mouse);
00270 glutVisibilityFunc(visible);
00271
00272 glutCreateMenu(menu);
00273 glutAddMenuEntry("Menu", 0);
00274 glutAddMenuEntry("", 0);
00275 glutAddMenuEntry("[f] Toggle fullscreen on/off", 'f');
00276 glutAddMenuEntry("[z] Zoom out", 'z');
00277 glutAddMenuEntry("[Z] Zoom in", 'Z');
00278 glutAddMenuEntry("[s] switch shading mode", 's');
00279 glutAddMenuEntry("[n] normal displaying", 'n');
00280 glutAddMenuEntry("[Esc] Quit", 27);
00281 glutAttachMenu(GLUT_RIGHT_BUTTON);
00282
00283 trackball(currentQuaternion, 0.0, 0.0, 0.0, 0.0);
00284
00285
00286 glutMainLoop();
00287
00288
00289 return 0;
00290 }