//#include #include "loader.h" //Chargement des images bmp et exploitation de ces dernieres #define PI 3.14159 /*Variables pour la visualisation et la camera*/ int angleZ; /* rotation du terrain autour d'un axe vertical passant par 0,0,0*/ GLdouble phi; /* latitude , angle de la caméra*/ GLdouble theta; /* longitude */ GLdouble xpos, ypos, zpos; /*position de la camera*/ GLdouble xcib, ycib, zcib; /*position de la cible*/ /*Valeurs initiales de ces variables*/ #define PHI0 -8.0 #define THETA0 220.0 #define XE0 132656.0; #define YE0 220.0; #define ZE0 130838.0; #define ANGLEZ0 0 /*distance entre la camera et la cible*/ #define R 10 float pas = 10.0; //pas des heightmap float alt=4.0; //echelle des altitudes des heightmaps float taille; //taille reelle d'une heightmap: SIZE*pas float rayon; //rayon du CIEL float diametre; //diametre du ciel = taille de la carte int t1 = 0, t2 = 0, fps = 0; //temps pour le nombre de frames par seconde float fog_color[4]={0.5,0.5,1.0,1.0}; //couleur du brouillard void centerPos(); /* calcul la position de la cible de vision*/ /*Calcul du nombre de frames par secondes*/ void FPS(void){ t1 = glutGet(GLUT_ELAPSED_TIME); if(t1 - t2 > 1000) { printf("%g\n", (1000.0 * fps)/(t1-t2)); t2 = t1; fps = 0; } fps++; } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /** * Fonction adaptant le dessin lors d'un redimensionnement de la fenetre */ static void resize(int width, int height){ glViewport (0, 0, (GLsizei) width, (GLsizei) height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); /* view angle, aspect ratio, near clipping plane, far clipping plane */ gluPerspective( 50.0, (GLfloat) width/(GLfloat) height, 0.1, 20000.0); glMatrixMode(GL_MODELVIEW); } //Initialisation des proprietes pour opengl et les variables du programme void init(){ int i,j; GLuint CIEL=load_texture("textures/ciel.bmp",hmt[5].texchrg+sizeof(GLuint),6);//texture ciel GLfloat L_position[3]={-1.0,16.0,-2.0}; GLfloat L_ambient[3]={0.8,0.8,0.8}; GLfloat L_diffuse[3]={1.0,1.0,1.0}; GLfloat L_specular[3]={1.0,1.0,1.0}; GLfloat M_diffuse[3]={0.8,0.8,0.8}; GLfloat M_specular[3]={0.8,0.8,0.8}; GLfloat M_shiny = 100; glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0,GL_POSITION,L_position); glLightfv(GL_LIGHT0,GL_DIFFUSE,L_diffuse); glLightfv(GL_LIGHT0,GL_SPECULAR,L_specular); glLightfv(GL_LIGHT0,GL_AMBIENT,L_ambient); glMaterialfv(GL_FRONT,GL_DIFFUSE,M_diffuse); glMaterialfv(GL_FRONT,GL_SPECULAR,M_specular); glMaterialf(GL_FRONT,GL_SHININESS,M_shiny); //Important to change the color!! glEnable(GL_COLOR_MATERIAL); //LE BROUILLARD glEnable(GL_FOG); glFogi(GL_FOG_MODE, GL_LINEAR); glFogf(GL_FOG_START, SIZE*pas*3);//debut du brouillard glFogf(GL_FOG_END, SIZE*pas*4);//fin du brouillard glFogfv(GL_FOG_COLOR,fog_color); taille=SIZE*pas;//taille finale d'une heightmap diametre=taille*N;//taille totale de la carte rayon= diametre/2;//moitie du diametre //Selection des heightmap parmi celles que nous possedons et generation des textures hmt[0].name="textures/heightmap0.bmp";//celle correspond a de l'eau uniquement hmt[0].name_texture="textures/mutitexture0.bmp"; hmt[1].name="textures/heightmap1.bmp"; hmt[1].name_texture="textures/mutitexture1.bmp"; hmt[2].name="textures/heightmap2.bmp"; hmt[2].name_texture="textures/multitexture2.bmp"; hmt[3].name="textures/heightmap3.bmp"; hmt[3].name_texture="textures/multitexture3.bmp"; hmt[4].name="textures/heightmap4.bmp"; hmt[4].name_texture="textures/multitexture4.bmp"; nbcarte=5;//nombre de texture for(i=0;i= N || j>=N) drawSolPlat(i,j,hmt[carte[0][0]]); else drawSolPlat(i,j,hmt[carte[i][j]]); choisir_texture();//selection d'une multitexture et dessine celle-ci en fonction de ses altitudes glTranslatef(xcib,ycib,zcib); glPushMatrix(); drawSky(); glRotated(phi,0.0,1.0,0.0); glRotated(-theta,1.0,.0,0.0); glRotated(angleZ,0.0,0.0,1.0); glPopMatrix(); glPopMatrix(); glFlush(); FPS(); glutSwapBuffers(); } /* Elle est lancée lorsque le système n’a plus rien à faire (affichage terminé, pas d’évènements clavier. Elle sert à faire des animations.**/ //void //Idle(void){ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* INTERACTIONS UTILISATEUR */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void keyboard(int key,int x,int y){ double deltax, deltay,deltaz; switch (key) { case '+': deltax = xcib - xpos; deltay = ycib - ypos; deltaz = zcib - zpos; xcib+=deltax; ycib+=deltay; zcib+=deltaz; xpos+=deltax; ypos+=deltay; zpos+=deltaz; glutPostRedisplay(); break; case '-': deltax = xcib - xpos; deltay = ycib - ypos; deltaz = zcib - zpos; xcib-=deltax; ycib-=deltay; zcib-=deltaz; xpos-=deltax; ypos-=deltay; zpos-=deltaz; glutPostRedisplay(); break; case GLUT_KEY_UP: phi+=2.0; if (phi>90) phi=90; centerPos(); break; case GLUT_KEY_DOWN: phi-=2.0; if (phi<-90) phi=-90; centerPos(); break; case GLUT_KEY_LEFT: theta+=2.0; if (theta>360) theta-=360; centerPos(); break; case GLUT_KEY_RIGHT: theta-=2.0; if (theta<360) theta+=360; centerPos(); break; case GLUT_KEY_PAGE_DOWN: zcib-=0.5; zpos-=0.5; break; case GLUT_KEY_PAGE_UP: zcib+=0.5; zpos+=0.5; break; case GLUT_KEY_INSERT: deltax = ycib - ypos; deltay = xpos - xcib; xpos-=deltax; ypos-=deltay; xcib-=deltax; ycib-=deltay; break; case GLUT_KEY_HOME: deltax = ycib - ypos; deltay = xpos - xcib; xpos+=deltax; ypos+=deltay; xcib+=deltax; ycib+=deltay; break; } glutPostRedisplay(); } /** * calcule la position du centre de vision en fonction de la position * de la camera et des angles phi et theta*/ void centerPos(){ xcib = xpos + R*cos(phi/180.0*PI)*cos(theta/180.0*PI); ycib = ypos + R*cos(phi/180.0*PI)*sin(theta/180.0*PI); zcib = zpos + R*sin(phi/180.0*PI); } //Fonction Main int main(int argc, char *argv[]){ glutInit(&argc, argv); glutInitWindowSize(1000,500); glutInitWindowPosition(100,100); glutCreateWindow("Paysage Naturel"); load_image(); init(); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutDisplayFunc(display); glutSpecialFunc(keyboard); glutReshapeFunc(resize); glutIdleFunc(display); glutMainLoop(); return 0; }