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
|
/* inclusion des fichiers d'entete Glut */
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <math.h>
int a=0,b=0,c=5;
int inca=2,incb=2,incc=2;
void display();
void idle();
int main(int argc,char **argv)
{
/* initialisation de glut et creation
de la fenetre */
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);
glutInitWindowPosition(10,10);
glutInitWindowSize(900,900);
glutCreateWindow("Systeme solaire(lune,terre,soleil)");
/* Initialisation d'OpenGL */
glClearColor(0,0,0,0);
/* enregistrement des fonctions de rappel */
glutDisplayFunc(display);
glutInitDisplayMode (GLUT_DOUBLE);
glutIdleFunc(idle);
glEnable(GL_DEPTH_TEST);
/* Entre dans la boucle principale glut */
glutMainLoop();
return 0;
}
//Dessin des objets
void display()
{
// position lumiere
static GLfloat posi[4] = {5.0, 2.0, 9.0, 0.0};
//couleur des planetes
//static GLfloat moon[4] = {0.7, 0.7, 0.7, 0.8}; // grisatre
static GLfloat yell[4] = {1.0, 0.9, 0.3, 1.0}; // jaune orange
static GLfloat blue[4] = {0.5, 0.8, 1.0, 1.0}; // bleu "terre"
// reglage lumiere
glLightfv(GL_LIGHT0, GL_POSITION, posi);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
/* effacement de l'image avec la couleur de fond */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
/* Dessin des objets */
//soleil
glPushMatrix();
glTranslated(0,0,0);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, yell);
glutSolidSphere(0.3,50,50);
glPopMatrix();
//terre
glPushMatrix();
glRotatef(b,0,1,0);//rotation autour du soleil
glTranslated(0.8,0,0);
glRotatef(a,0,1,0); //rotation sur elle même
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
glutWireSphere(0.1,20,20);
glPopMatrix();
/* //lune
glPushMatrix();
glTranslated(0.8,0,0);
glRotatef(a,0,1,0);//rotation autour de la terre
glTranslated(0.15,0,0);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, moon);
glutWireSphere(0.03,10,10);
glPopMatrix();*/
/* on force l'affichage du resultat */
glFlush();
glutSwapBuffers();
glutPostRedisplay();
}
void idle()
{
a+=inca;
if (a>360)
a-=360;
b+=incb;
if (b>360)
b-=360;
glutPostRedisplay();
} |
Partager