begin process at 2012 05 27 19:31:01
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

OpenGL

 > SYSTÈME SOLAIRE OPEN GL AVEC BIBLIOTHÈQUE GLUT : 5 PLANETES / LUMIÈRES / ESPACE

SYSTÈME SOLAIRE OPEN GL AVEC BIBLIOTHÈQUE GLUT : 5 PLANETES / LUMIÈRES / ESPACE


 Information sur la source

Note :
6 / 10 - par 1 personne
6,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :OpenGL Classé sous :systeme, solaire, gabule, opengl, glut Niveau :Débutant Date de création :23/04/2008 Date de mise à jour :16/12/2009 20:43:12 Vu / téléchargé :8 207 / 872

Auteur : gabule

Ecrire un message privé
Ce membre participe au partage de revenus publicitaires
Commentaire sur cette source (5)
Ajouter un commentaire et/ou une note


 Description

Cliquez pour voir la capture en taille normale
Voici un petit système solaire que j'ai fait en TP à l'école.
C'est une représentation partielle du système solaire (le Soleil, Mercure, Vénus, la Terre et la Lune.
Toutes ces planètes sont sur le même plan et gravitent autour du soleil, la Lune gravitant elle autour de la terre.

J'espère qu'il vous servira.

Touches :
q  : Quitter
+ : se rapprocher
-  : s�éloigner
l : activer/désactiver les lumières

Source

  • //***************************************************************************************
  • // G@BuLe - 2008
  • //***************************************************************************************
  • #include <stdio.h>
  • #include <stdlib.h>
  • #include"glut.h"
  • #include<GL/glu.h>
  • bool light =true;
  • GLubyte* data;
  • int eyex=0,eyey=25,eyez=12;
  • int width=800,height=800;
  • // Initialisation des angles
  • float angle0=0.0;
  • float angle1=0.0;
  • float angle2=0.0;
  • float angle3=0.0;
  • float angle4=0.0;
  • float angle5=0.0;
  • float angle6=0.0;
  • float angle7=0.0;
  • float angle8=0.0;
  • GLUquadricObj *obj = gluNewQuadric();
  • GLUquadricObj *obj_reverse = gluNewQuadric();
  • //Texture :
  • GLuint Nom[6];
  • //LoadBMP : charge une image 24bpp
  • #define EXIT {fclose(fichier);return -1;}
  • #define CTOI(C) (*(int*)&C) //récupère en int un nombre pointé par un char*
  • void inc_angles(){
  • (angle0 == 360.0)? angle0=0.0 : angle0 +=3.0/15;
  • (angle1 == 360.0)? angle1=0.0 : angle1 +=3.0;
  • (angle2 == 0.0)? angle2=360.0 : angle2 -=3.0;
  • (angle3 == 360.0)? angle3=0.0 : angle3 +=3;
  • (angle4 == 360.0)? angle4=0.0 : angle4 +=1.0;
  • (angle5 == 360.0)? angle5=0.0 : angle5 +=(0.088*4);
  • (angle6 == 360.0)? angle6=0.0 : angle6 +=(0.224*4);
  • (angle7 == 360.0)? angle7=0.0 : angle7 +=(3.0/365.0*40.0);
  • (angle8 == 360.0)? angle8=0.0 : angle8 +=2.0;
  • }
  • int LoadBMP(char *File)
  • {
  • unsigned char *Data;
  • FILE *fichier;
  • unsigned char Header[0x36];
  • GLuint DataPos,DataSize;
  • GLint Components;
  • GLsizei Width,Height;
  • GLenum Format,Type;
  • GLuint Name[1];
  • //Lit le fichier et son header
  • fichier = fopen(File,"rb");if (!fichier) return -1;
  • if (fread(Header,1,0x36,fichier)!=0x36) EXIT;
  • if (Header[0]!='B' || Header[1]!='M') EXIT;
  • if (CTOI(Header[0x1E])!=0) EXIT;
  • if (CTOI(Header[0x1C])!=24) EXIT;
  • //Récupère les infos du fichier
  • DataPos = CTOI(Header[0x0A]);
  • DataSize = CTOI(Header[0x22]);
  • //Récupère les infos de l'image
  • Width = CTOI(Header[0x12]);
  • Height = CTOI(Header[0x16]);
  • Type = GL_UNSIGNED_BYTE;
  • Format = GL_RGB;
  • Components = 3;
  • //!!!!
  • if (DataSize==0) DataSize=Width*Height*Components;
  • if (DataPos==0) DataPos=0x36;
  • //Charge l'image
  • fseek(fichier,DataPos,0);
  • Data = new unsigned char[DataSize];
  • if (!Data) EXIT;
  • if (fread(Data,1,DataSize,fichier)!=DataSize)
  • {
  • delete Data;
  • fclose(fichier);
  • return -1;
  • }
  • fclose(fichier);
  • //Inverse R et B
  • unsigned char t;
  • for (int x=0;x<Width*Height;x++)
  • {
  • t=Data[x*3];
  • Data[x*3]=Data[x*3+2];
  • Data[x*3+2]=t;
  • }
  • //Envoie la texture à OpenGL
  • // glPixelStorei(GL_UNPACK_ALIGNMENT,1);
  • glGenTextures(1, Name);
  • glBindTexture(GL_TEXTURE_2D, Name[0]);
  • glTexImage2D
  • (
  • GL_TEXTURE_2D, //target
  • 0, //mipmap level
  • Components, //nb couleurs
  • Width, //largeur
  • Height, //hauteur
  • 0, //largeur du bord
  • GL_RGB, //type des couleurs
  • GL_UNSIGNED_BYTE, //codage de chaque composante
  • Data //Image
  • );
  • return Name[0];
  • }
  • void init(void)
  • {
  • // initialise la buffer ou va etre rendu la scene
  • glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH );
  • // initialisation de la fenetre (taille 500x500)
  • glutInitWindowSize (800, 800);
  • // on positionne la fenetre sur l'ecran
  • glutInitWindowPosition (100, 100);
  • // on cree la fenetre
  • glutCreateWindow ("Système Planetaire .:: G@BuLe ::. || q : Quitter || + : s'approcher || - : s'éloigner || l : lumières On/OFF");
  • // couleur de remplissage lors de l'effacement du buffer
  • glClearColor (0.0, 0.0, 0.0, 0.0);
  • // model d'eclairage
  • // Crée une source de lumière
  • GLfloat position1 [] = { 0, 0.0F, 0.0F, 1.0F };
  • glLightfv(GL_LIGHT0, GL_POSITION, position1);
  • glEnable(GL_LIGHTING);
  • glEnable(GL_LIGHT0);
  • glShadeModel (GL_SMOOTH);
  • // Z Buffer pour la suppression des parties cachées
  • glEnable(GL_DEPTH_TEST);
  • glEnable(GL_COLOR_MATERIAL);
  • glEnable(GL_TEXTURE_2D);
  • glMatrixMode (GL_MODELVIEW);
  • glLoadIdentity ();
  • Nom[0] = LoadBMP("sun.bmp");
  • glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  • glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  • Nom[1] = LoadBMP("mercure.bmp");
  • glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  • glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  • Nom[2] = LoadBMP("venus.bmp");
  • glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  • glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  • Nom[3] = LoadBMP("earth.bmp");
  • glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  • glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  • Nom[4] = LoadBMP("moon.bmp");
  • glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  • glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  • Nom[5] = LoadBMP("space.bmp");
  • glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  • glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  • glDepthFunc(GL_LESS);
  • glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
  • glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  • }
  • void display(void)
  • {
  • //materiaux
  • GLfloat ambiant [4] = { 0.2, 0.2, 0.2, 1.0 };
  • GLfloat diffuse [4] = { 0.6, 0.6, 0.6, 1.0 };
  • GLfloat specular [4] = { 1.0, 1.0, 1.0, 1.0 };
  • GLfloat emission [4] = { 0.5, 0.5, 0., 0.0 };
  • GLfloat no_material [4] = {0.0,0.0,0.0,0.0};
  • GLfloat shininess []= {50.0};
  • inc_angles();
  • // Affiche l'espace
  • glLoadIdentity();
  • gluLookAt(eyex,eyey,eyez,0,0,0,0.0,0.0,1.0);
  • glClear (GL_COLOR_BUFFER_BIT);
  • glClear (GL_DEPTH_BUFFER_BIT);
  • glBindTexture(GL_TEXTURE_2D, Nom[5]);
  • glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  • glTranslatef(-0.5,-0.5,0);
  • glBegin(GL_QUADS);
  • glTexCoord2f(0.0, 0.0); glVertex3f(100.0, -10.0, -10.0);
  • glTexCoord2f(0.0, 1.0); glVertex3f(100.0, -10.0, 10.0);
  • glTexCoord2f(1.0, 1.0); glVertex3f(-100.0, -10.0, 10.0);
  • glTexCoord2f(1.0, 0.0); glVertex3f(-10.0, -10.0, -30.0);
  • glEnd();
  • // Definit les propriétés matérielles de la couleur spéculaire et du
  • // degré de brillance.
  • if (light){
  • glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambiant);
  • glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
  • glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
  • glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
  • glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, emission);
  • }
  • // le soleil
  • glPushMatrix();
  • glBindTexture(GL_TEXTURE_2D, Nom[0]);
  • gluQuadricTexture(obj, GL_TRUE );
  • gluQuadricDrawStyle(obj, GLU_FILL);
  • glTranslatef(0,0.0,0.0);
  • glRotatef(angle0,0.0,0.0,1.0);
  • gluSphere(obj,3.0,100.0,100.0);
  • glPopMatrix();
  • glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambiant);
  • glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
  • glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
  • glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
  • glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, no_material);
  • // mercure
  • glPushMatrix();
  • glBindTexture(GL_TEXTURE_2D, Nom[1]);
  • gluQuadricTexture(obj, GL_TRUE );
  • gluQuadricDrawStyle(obj, GLU_FILL);
  • glRotatef(10,1,0,0);
  • glRotatef(angle5,0.0,0.0,1.0);
  • glTranslatef(5.0,0.0,0.0);
  • glRotatef(angle1,0.0,0.0,1.0);
  • gluSphere(obj,0.55,100.0,100.0);
  • glPopMatrix();
  • // venus
  • glPushMatrix();
  • glBindTexture(GL_TEXTURE_2D, Nom[2]);
  • gluQuadricTexture(obj, GL_TRUE );
  • gluQuadricDrawStyle(obj, GLU_FILL);
  • //glColor3f (1.0, 0.0, 0.0);
  • glRotatef(340,1,0,0);
  • glRotatef(angle6,0.0,0.0,1.0);
  • glTranslatef(7.0,0.0,0.0);
  • glRotatef(angle2,0.0,0.0,1.0);
  • gluSphere(obj,0.815,100.0,100.0);
  • glPopMatrix();
  • // terre
  • glPushMatrix();
  • glBindTexture(GL_TEXTURE_2D, Nom[3]);
  • gluQuadricTexture(obj, GL_TRUE );
  • gluQuadricDrawStyle(obj, GLU_FILL);
  • glRotatef(angle7,0.0,0.0,1.0);
  • glRotatef(30,1,0,0);
  • glTranslatef(9.5,0.0,0.0);
  • glRotatef(360-angle7,0.0,0.0,1.0);
  • glRotatef(angle3,0.0,0.0,1.0);
  • glRotatef(23.0,0.0,0.0,1.0);
  • gluSphere(obj,1.0,100.0,100.0);
  • // lune
  • glPushMatrix();
  • glBindTexture(GL_TEXTURE_2D, Nom[4]);
  • gluQuadricTexture(obj, GL_TRUE );
  • gluQuadricDrawStyle(obj, GLU_FILL);
  • glColor3f (1.0,1.0,1.0);
  • glRotatef(30,1,0,0);
  • glRotatef(angle8,0.0,0.0,1.0);
  • glTranslatef(1.3,0.0,0.0);
  • glRotatef(angle4,0.0,0.0,1.0);
  • gluSphere(obj,0.05,100.0,100.0);
  • glPopMatrix();
  • glPopMatrix();
  • glutSwapBuffers();
  • glutPostRedisplay();
  • }
  • void reshape (int width,int height){
  • glViewport(0, 0, width, height);
  • glMatrixMode(GL_PROJECTION);
  • glLoadIdentity();
  • gluPerspective(45.0,width/height,1.0,3000.0);
  • glMatrixMode(GL_MODELVIEW);
  • }
  • // fonction de gestion du clavier
  • void keyboard(unsigned char key, int x, int y)
  • {
  • switch (key) {
  • case 'l':
  • if (light){
  • light=false;
  • glDisable(GL_LIGHT0);
  • }else{
  • light=true;
  • glEnable(GL_LIGHT0);
  • }
  • break;
  • case 'q':exit(0); break;
  • case '-' : eyex +=5.0 ;break;
  • case '+' : eyex -=5.0 ;break;
  • default:printf ("La touche %d n&#65533;est pas active.\n", key); break;
  • }
  • glMatrixMode(GL_MODELVIEW);
  • glutPostRedisplay();
  • }
  • int main(int argc, char** argv)
  • {
  • glutInit(&argc, argv);
  • // on initialise la scene
  • init ();
  • // definition des fonctions "callback"
  • // les 3 fonctions qui suivent permettent d'indiquer les fonctions a utilisé :
  • // lors de l'affichage
  • glutDisplayFunc(display);
  • // lors du redimensionnement de la fentre
  • glutReshapeFunc(reshape);
  • // lors d'un appui sur un touche du clavier
  • glutKeyboardFunc(keyboard);
  • // la librairie glut gere elle meme la boucle d'evenement
  • glutMainLoop();
  • return 0;
  • }
//***************************************************************************************

// G@BuLe - 2008

//***************************************************************************************





#include <stdio.h>

#include <stdlib.h>



#include"glut.h"

#include<GL/glu.h>



bool light =true;

GLubyte* data;

int eyex=0,eyey=25,eyez=12;

int width=800,height=800;



// Initialisation des angles

float angle0=0.0;

float angle1=0.0;

float angle2=0.0;

float angle3=0.0;

float angle4=0.0;

float angle5=0.0;

float angle6=0.0;

float angle7=0.0;

float angle8=0.0;





GLUquadricObj *obj = gluNewQuadric();

GLUquadricObj *obj_reverse = gluNewQuadric();



//Texture :

GLuint		Nom[6];



//LoadBMP : charge une image 24bpp

#define EXIT {fclose(fichier);return -1;}

#define CTOI(C) (*(int*)&C)	//récupère en int un nombre pointé par un char*



void inc_angles(){

	(angle0 == 360.0)? angle0=0.0 : angle0 +=3.0/15;

	(angle1 == 360.0)? angle1=0.0 : angle1 +=3.0;

	(angle2 == 0.0)? angle2=360.0 : angle2 -=3.0;

	(angle3 == 360.0)? angle3=0.0 : angle3 +=3;

	(angle4 == 360.0)? angle4=0.0 : angle4 +=1.0;

	(angle5 == 360.0)? angle5=0.0 : angle5 +=(0.088*4);

	(angle6 == 360.0)? angle6=0.0 : angle6 +=(0.224*4);

	(angle7 == 360.0)? angle7=0.0 : angle7 +=(3.0/365.0*40.0);

	(angle8 == 360.0)? angle8=0.0 : angle8 +=2.0;

}





int LoadBMP(char *File)

{

	unsigned char	*Data;

	FILE			*fichier;

	unsigned char	Header[0x36];

	GLuint			DataPos,DataSize;

	GLint			Components;

	GLsizei			Width,Height;

	GLenum			Format,Type;

	GLuint			Name[1];



	//Lit le fichier et son header

	fichier = fopen(File,"rb");if (!fichier) return -1;

	if (fread(Header,1,0x36,fichier)!=0x36) EXIT;

	if (Header[0]!='B' || Header[1]!='M')	EXIT;

	if (CTOI(Header[0x1E])!=0)				EXIT;

	if (CTOI(Header[0x1C])!=24)				EXIT;



	//Récupère les infos du fichier

	DataPos			= CTOI(Header[0x0A]);

	DataSize		= CTOI(Header[0x22]);

	//Récupère les infos de l'image

	Width			= CTOI(Header[0x12]);

	Height			= CTOI(Header[0x16]);	

	Type = GL_UNSIGNED_BYTE;

	Format = GL_RGB;

	Components = 3;



	//!!!!

	if (DataSize==0) DataSize=Width*Height*Components;

	if (DataPos==0)  DataPos=0x36;



	//Charge l'image

	fseek(fichier,DataPos,0);

	Data = new unsigned char[DataSize];

	if (!Data) EXIT;



	if (fread(Data,1,DataSize,fichier)!=DataSize) 

	{

		delete Data;

		fclose(fichier);

		return -1;

	}



	fclose(fichier);



	//Inverse R et B

	unsigned char t;

	for (int x=0;x<Width*Height;x++) 

	{

		t=Data[x*3];

		Data[x*3]=Data[x*3+2];

		Data[x*3+2]=t;

	}



	//Envoie la texture à OpenGL

	//	glPixelStorei(GL_UNPACK_ALIGNMENT,1);

	glGenTextures(1, Name);

	glBindTexture(GL_TEXTURE_2D, Name[0]);





	glTexImage2D

		( 	

		GL_TEXTURE_2D, 	//target

		0,				//mipmap level

		Components,		//nb couleurs

		Width,			//largeur

		Height,			//hauteur

		0,			 	//largeur du bord

		GL_RGB,			//type des couleurs

		GL_UNSIGNED_BYTE,			//codage de chaque composante

		Data			//Image

		); 



	return Name[0];

}





void init(void) 

{

	// initialise la buffer ou va etre rendu la scene 

	glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH );

	// initialisation de la fenetre (taille 500x500) 

	glutInitWindowSize (800, 800); 

	// on positionne la fenetre sur l'ecran

	glutInitWindowPosition (100, 100);

	// on cree la fenetre 

	glutCreateWindow ("Système Planetaire .:: G@BuLe ::. || q : Quitter || + : s'approcher || - : s'éloigner || l : lumières On/OFF");

	// couleur de remplissage lors de l'effacement du buffer

	glClearColor (0.0, 0.0, 0.0, 0.0);

	// model d'eclairage 



	// Crée une source de lumière

	GLfloat position1 [] = { 0, 0.0F, 0.0F, 1.0F };

	glLightfv(GL_LIGHT0, GL_POSITION, position1);

	glEnable(GL_LIGHTING);

	glEnable(GL_LIGHT0);

	glShadeModel (GL_SMOOTH);



	// Z Buffer pour la suppression des parties cachées

	glEnable(GL_DEPTH_TEST);



	glEnable(GL_COLOR_MATERIAL);



	glEnable(GL_TEXTURE_2D);

	glMatrixMode (GL_MODELVIEW);	

	glLoadIdentity ();  





	Nom[0] = LoadBMP("sun.bmp");

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);





	Nom[1] = LoadBMP("mercure.bmp");

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);



	Nom[2] = LoadBMP("venus.bmp");

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);



	Nom[3] = LoadBMP("earth.bmp");

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);



	Nom[4] = LoadBMP("moon.bmp");

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);





	Nom[5] = LoadBMP("space.bmp");

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);



	glDepthFunc(GL_LESS);

	glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );

	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

}





void display(void)

{

	

	

	//materiaux

	GLfloat ambiant [4] = { 0.2, 0.2, 0.2, 1.0 };

	GLfloat diffuse [4] = { 0.6, 0.6, 0.6, 1.0 };

	GLfloat specular [4] = { 1.0, 1.0, 1.0, 1.0 };

	GLfloat emission [4] = { 0.5, 0.5, 0., 0.0 };

	GLfloat no_material [4] = {0.0,0.0,0.0,0.0};

	GLfloat shininess []= {50.0};







	inc_angles();



	// Affiche l'espace

	glLoadIdentity();

	gluLookAt(eyex,eyey,eyez,0,0,0,0.0,0.0,1.0);

	glClear (GL_COLOR_BUFFER_BIT);

	glClear (GL_DEPTH_BUFFER_BIT);

	glBindTexture(GL_TEXTURE_2D, Nom[5]);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);



	glTranslatef(-0.5,-0.5,0);

	glBegin(GL_QUADS);

	glTexCoord2f(0.0, 0.0); glVertex3f(100.0, -10.0, -10.0);

	glTexCoord2f(0.0, 1.0); glVertex3f(100.0, -10.0, 10.0);

	glTexCoord2f(1.0, 1.0); glVertex3f(-100.0, -10.0, 10.0);

	glTexCoord2f(1.0, 0.0); glVertex3f(-10.0, -10.0, -30.0);

	glEnd();



	// Definit les propriétés matérielles de la couleur spéculaire et du

	// degré de brillance. 

	if (light){

		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambiant);

		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse); 

		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);

		glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess);	

		glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, emission);

	}



	// le soleil

	glPushMatrix();

	glBindTexture(GL_TEXTURE_2D, Nom[0]);

	gluQuadricTexture(obj, GL_TRUE );

	gluQuadricDrawStyle(obj, GLU_FILL);

	glTranslatef(0,0.0,0.0);	

	glRotatef(angle0,0.0,0.0,1.0);

	gluSphere(obj,3.0,100.0,100.0);

	glPopMatrix();



	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambiant);

	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse); 

	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);

	glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess);	

	glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, no_material);



	// mercure

	glPushMatrix();

	glBindTexture(GL_TEXTURE_2D, Nom[1]);

	gluQuadricTexture(obj, GL_TRUE );

	gluQuadricDrawStyle(obj, GLU_FILL);

	glRotatef(10,1,0,0);

	glRotatef(angle5,0.0,0.0,1.0);

	glTranslatef(5.0,0.0,0.0);

	glRotatef(angle1,0.0,0.0,1.0);

	gluSphere(obj,0.55,100.0,100.0);

	glPopMatrix();



	// venus

	glPushMatrix();

	glBindTexture(GL_TEXTURE_2D, Nom[2]);

	gluQuadricTexture(obj, GL_TRUE );

	gluQuadricDrawStyle(obj, GLU_FILL);



	//glColor3f (1.0, 0.0, 0.0);

	glRotatef(340,1,0,0);

	glRotatef(angle6,0.0,0.0,1.0);

	glTranslatef(7.0,0.0,0.0);

	glRotatef(angle2,0.0,0.0,1.0);

	gluSphere(obj,0.815,100.0,100.0);

	glPopMatrix();



	// terre

	glPushMatrix();

	glBindTexture(GL_TEXTURE_2D, Nom[3]);

	gluQuadricTexture(obj, GL_TRUE );

	gluQuadricDrawStyle(obj, GLU_FILL);

	glRotatef(angle7,0.0,0.0,1.0);

	glRotatef(30,1,0,0);

	glTranslatef(9.5,0.0,0.0);

	glRotatef(360-angle7,0.0,0.0,1.0);

	glRotatef(angle3,0.0,0.0,1.0);

	glRotatef(23.0,0.0,0.0,1.0);

	gluSphere(obj,1.0,100.0,100.0);



	// lune

	glPushMatrix();

	glBindTexture(GL_TEXTURE_2D, Nom[4]);

	gluQuadricTexture(obj, GL_TRUE );

	gluQuadricDrawStyle(obj, GLU_FILL);

	glColor3f (1.0,1.0,1.0);

	glRotatef(30,1,0,0);

	glRotatef(angle8,0.0,0.0,1.0);

	glTranslatef(1.3,0.0,0.0);

	glRotatef(angle4,0.0,0.0,1.0);

	gluSphere(obj,0.05,100.0,100.0);

	glPopMatrix();

	glPopMatrix();



	glutSwapBuffers();

	glutPostRedisplay();

}





void reshape (int width,int height){

	glViewport(0, 0, width, height);

	glMatrixMode(GL_PROJECTION);

	glLoadIdentity();

	gluPerspective(45.0,width/height,1.0,3000.0);

	glMatrixMode(GL_MODELVIEW);

}



// fonction de gestion du clavier 

void keyboard(unsigned char key, int x, int y)

{

	switch (key) {

	  case 'l':

		  if (light){

			  light=false;

			  glDisable(GL_LIGHT0);

		  }else{

			  light=true;

			  glEnable(GL_LIGHT0);

		  }

		  break;

	  case 'q':exit(0); break;

	  case '-' : eyex +=5.0 ;break;

	  case '+' : eyex -=5.0 ;break;

	  default:printf ("La touche %d n&#65533;est pas active.\n", key); break;

	}

	glMatrixMode(GL_MODELVIEW);

	glutPostRedisplay();

}



int main(int argc, char** argv)

{

	glutInit(&argc, argv);



	// on initialise la scene

	init ();



	// definition des fonctions "callback"

	// les 3 fonctions qui suivent permettent d'indiquer les fonctions a utilisé :

	// lors de l'affichage

	glutDisplayFunc(display); 

	// lors du redimensionnement de la fentre 

	glutReshapeFunc(reshape);

	// lors d'un appui sur un touche du clavier

	glutKeyboardFunc(keyboard); 



	// la librairie glut gere elle meme la boucle d'evenement

	glutMainLoop();  



	return 0;

}


 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
  •   SystemeSolaire

Télécharger le zip


 Historique

24 avril 2008 22:42:46 :
Retification erreur : l lune tourne bien evidement autour du soleil ...
21 avril 2009 11:23:08 :
Nouvelle version avec prise en compte de la souris
16 décembre 2009 20:43:13 :
Update

 Sources du même auteur

Source avec Zip Source avec une capture DRAG & DROP ENTRE 2 CLISTCTRL ( BIBLIOTHEQUE OLE )

 Sources de la même categorie

Source avec Zip Source avec une capture AFFICHER DES COURBES DE BEZIER par shorzy
Source avec Zip Source avec une capture BASE/MOTEUR 3D EN QT/OPENGL (COMPLET ET FONCTIONNEL!) POUR U... par envi33
Source avec Zip Source avec une capture CLASSE AVEC OPENGL - OBJETS 3D ET ANIMATIONS par rasta63
Source avec Zip Source avec une capture LETTRES 3D AVEC OPENGL ET QT par opossum_farceur
Source avec Zip CUBE 3D GLUT32 VC++ ET DEVC++ par bobby03

 Sources en rapport avec celle ci

Source avec Zip CUBE 3D GLUT32 VC++ ET DEVC++ par bobby03
Source avec Zip Source avec une capture DEMO OPENGL par JeanCodeS
Source avec Zip Source avec une capture ATTRACTEURS DE FAMILLES DE CONTRACTIONS EN ÉCRAN DE VEILLE par Forman
Source avec Zip Source avec une capture SUDOKU EN C++ OPENGL, GLUT ET GLUI. par pelenalu
Source avec Zip Source avec une capture BESOIN D'AIDE ET D'AVIS POUR JEU ROBOT POUSSE-PUCK par Heyho

Commentaires et avis

Commentaire de gamemonde le 23/04/2008 23:38:32

outes ces planètes sont sur le même plan et gravitent autour du soleil, la Lune gravitant elle autour du soleil.

serai pas autour de la terre

Commentaire de gabule le 24/04/2008 07:26:34

non c'est bien autour du soleil.

Commentaire de Patrice99 le 24/04/2008 16:17:11

La lune gravite autour de la terre, meme si le système Terre-Lune gravite autour du soleil.
Voir aussi :
GRAVITY.NET : L'ÉCRAN DE VEILLE CHAOTIQUE EN VB.NET
www.vbfrance.com/codes/GRAVITY-NET-ECRAN-VEILLE-CHAOTIQUE-VB-NET_4486.aspx

Commentaire de gabule le 24/04/2008 22:44:15

Desolé "gamemonde" tu avais raison.
J'ai rectifié.

Merci

Commentaire de ENSAF le 29/01/2009 17:08:25 6/10

bien!!

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

glut - openGL [ par loss ] Quels sont les fichiers necessaires pour utiliser glut(je compile avec VC++)?Ou est ce que je peux les telecharger?Merci d avance. Gestion de la souris OpenGL SANS GLUT [ par Xentor ] Comment faire pour connaitre le déplacement de la souris sans utiliser Glut ? (Savoir si on la déplace en haut, à gauche, etc...) J'ai fait plusieurs OpenGl, glut et Dev c++ 4 [ par fabienGL ] J'envoie un message car je passait au moin 3 heures sur le forums j'ai essayé tout ce ki à était di mé rien à faire ... j'utilise DEV C++ 4 et je sui OpenGl & glut avec Dev c++ 4 et WinXP [ par fabienGL ] J'envoie un message car je passait au moin 3 heures sur le forums j'ai essayé tout ce ki à était di mé rien à faire ... j'utilise DEV C++ 4 et j'ai Wi glut et opengl [ par MiTcH37 ] voila ce que j'ai lorsque je compile un prog avec du glut.h...C:\DOCUME~2\Mitch1\LOCALS~1\Temp\cc6Pbaaa.o(.text+0xcc):souris2.cpp: undefined reference opengl [ par MiTcH37 ] J'aimerais bien faire de l'opengl, mais ça marche pas... voila ce que j'ai lorsque je compile un prog avec du glut.h...C:\DOCUME~2\Mitch1\LOCALS~1\Tem devc++ [ par MiTcH37 ] qqun se sert de devc++ ?J'aimerais bien faire de l'opengl, mais ça marche pas... &gt; &gt; &gt; &gt; voila ce que j'ai lorsque je compile un prog avec erreur de compile d une source opengl utilisant glut [ par kribler ] KR!Bl3Rg lerreur suivante qui s afffiche :LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16quelqun pourrai maidermerci d Pb Dev C++ 5 et OpenGl [ par guillaume21 ] J'ai installé glut avec Dev c++ 5. J'ai mis glut.h dans include, glut32.lib dans lib et le dll dans system32 (et mem ds lib lol).J'ai aussi ajouté les Mélanger OpenGL et Glut [ par tintin72 ] SalutJ'aimerai me servir des fonctions d'entrée clavier/souris proposées par Glut, mais j'ai vu que Glut s'initialise avec une fonction main façon C.i


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,858 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales