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
|
#include <math.h>
#include <GL/glut.h>
static int paused;
GLdouble planet_view;
float SSD[10][9] = { // SSD = SOLAR SYSTEM DATA
// { R,G,B,planet_radius,orbit_radius,planet_degrees,orbit_degrees,year,day },
{ 1,0.68,0,696,0,0,7,0,30.5 }, // SOLEIL
{ 1,0,0,2.439,57900,7,28,88,58.6 }, // MERCURE
{ 1,1,0,6.050,108210,3.24,3,224.7,243 }, // VENUS
{ 1,0,1,6.378,149600,0,23.4,365.25,1 }, // TERRE
{ 0,1,1,3.397,227900,1.51,23.49,687,1.025 }, // MARS
{ 0,0,1,71.400,778340,1.18,3.05,4346.475,0.4125 }, // JUPITER
{ 0,0.5,0.5,60.300,1427000,2.39,26.44,18739.875,0.4375 }, // SATURNE
{ 0.5,0,0.5,25.650,2869000,0.46,85.5,30681,0.729166 }, // URANUS
{ 0.5,0.5,0,24.550,4490000,1.46,28.48,60193.2,0.8 }, // NEPTUNE
{ 0,0.5,0,1.150,5966000,17.1,122,90472.425,6.4 } // PLUTON
};
void createOrbit(float radius,float degrees) {
GLfloat angle;
GLint nb_sides = radius*50;
GLint i;
glPushMatrix();
glRotatef(degrees,1,0,0);
glBegin(GL_LINE_LOOP);
for (i=0;i<nb_sides;i++) {
angle = 2*M_PI*i/nb_sides;
glVertex3f(radius*2*cos(angle),0,radius*2*sin(angle));
}
glEnd();
glPopMatrix();
}
void createPlanet(float R,float G,float B,float planet_radius,float orbit_radius,float planet_degrees,float orbit_degrees,float year,float day) {
orbit_radius = orbit_radius / 1000;
glColor3f(R,G,B);
createOrbit(orbit_radius,orbit_degrees);
glPushMatrix();
glRotatef((GLint) year % 360,0,1,0);
glTranslatef(0,0,-orbit_radius);
glRotatef(planet_degrees,1,0,0);
glRotatef((GLint) day % 360,0,1,0);
glutWireSphere(planet_radius*2,planet_radius*15,planet_radius*15);
glPopMatrix();
}
void init() {
glShadeModel(GL_FLAT);
}
void display() {
GLint i;
planet_view += 0.01;
gluLookAt(0,0,-SSD[3][4]/1000,0,0,-SSD[(GLint) planet_view][4]/1000,0,1,0); // point de vue terrestre ... pointant sur chaque planète
glClear(GL_COLOR_BUFFER_BIT);
for (i=0;i<10;i++) {
if (paused % 2) {
SSD[i][7] += 10;
SSD[i][8] += 10;
}
createPlanet(SSD[i][0],SSD[i][1],SSD[i][2],SSD[i][3],SSD[i][4],SSD[i][5],SSD[i][6],SSD[i][7],SSD[i][8]);
}
glutSwapBuffers();
glutPostRedisplay();
}
void reshape(int w,int h) {
glViewport(0,0,(GLsizei) w,(GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60,(GLfloat) w/(GLfloat) h,1,1000000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void mouse(int button,int state,int x,int y) {
switch(button) {
case GLUT_LEFT_BUTTON :
if (state == GLUT_DOWN) {
paused++;
break;
}
}
}
int main(int argc,char** argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(800,600);
glutInitWindowPosition(50,50);
glutCreateWindow("Système solaire");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
} |
Partager