begin process at 2012 05 27 19:30:28
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

OpenGL

 > SYSTEM SOLAIRE AVEC LIGHTING

SYSTEM SOLAIRE AVEC LIGHTING


 Information sur la source

Note :
2 / 10 - par 3 personnes
2,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :OpenGL Niveau :Débutant Date de création :02/05/2003 Date de mise à jour :03/05/2003 03:13:44 Vu :3 990

Auteur : BenjaminRare

Ecrire un message privé
Commentaire sur cette source (1)
Ajouter un commentaire et/ou une note

 Description

Voila mon premier programme en OpenGL qui utilise glRotate(), glTranslate(), etc pour illustré le mouvement de la terre autour du soleil et de la lune autour de la terre .... j'ai ajoute du lighting pour donner un effect plus réel mais c pas encore ca ...

PS: desole pour les commentaires en anglais  

Source

  • #include <windows.h>
  • #include <gl\glut.h>
  • float g_LightPosition[3] = {0, 0, -300};
  • float g_bLight = true;
  • void RenderScene (void)
  • {
  • //angle of revolution for moon/earth
  • static float fMoonRot = 0.0f;
  • static float fEarthRot = 0.0f;
  • //clear the screen with current clearing color
  • glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  • //Save matrix state and the rotations
  • glMatrixMode(GL_MODELVIEW);
  • glPushMatrix();
  • glLightfv( GL_LIGHT0, GL_POSITION, g_LightPosition );
  • // Translate view 300 units 'into' the screen
  • glTranslatef(0.0f, 0.0f, -300.0f);
  • //Set material color, Red
  • //Sun
  • glColor3ub(255, 255, 0);
  • glutSolidSphere(18.0f, 15, 15);
  • //Rotate coordinate system for the earth
  • glRotatef(fEarthRot, 0.0, 1.0f, 0.0f);
  • //Draw the Earth
  • glColor3ub(0, 0, 255); //blue color
  • glTranslatef(105.0f, 0.0f, 0.0f);
  • glutSolidSphere(10.0f, 15, 15);
  • // Moon Rotation from earth-based coordinated
  • glColor3ub(200,200,200);
  • glRotatef(fMoonRot, 0.0f, 1.0f, 0.0f);
  • glTranslatef(30.0f, 0.0f, 0.0f);
  • fMoonRot += 1.0f;
  • if (fMoonRot > 360.0f )
  • fMoonRot = 0.0f;
  • glutSolidSphere(5.0f, 15, 15);
  • //Restore the matrix
  • glPopMatrix();
  • //Step earth orbit 5 degrees
  • fEarthRot += 1.0f;
  • if ( fEarthRot > 360.0f )
  • fEarthRot = 0.0f;
  • glutSwapBuffers();
  • glutPostRedisplay();
  • }
  • void SetupRC (void)
  • {
  • glEnable(GL_DEPTH_TEST);
  • glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  • float ambience[4] = {0.5f, 0.5f, 0.5f, 1.0};
  • float diffuse[4] = {0.5f, 0.5f, 0.5f, 1.0};
  • glLightfv( GL_LIGHT0, GL_AMBIENT, ambience );
  • glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse );
  • glLightfv( GL_LIGHT0, GL_POSITION, g_LightPosition );
  • glEnable( GL_LIGHT0 );
  • glEnable( GL_LIGHTING );
  • glEnable(GL_COLOR_MATERIAL);
  • }
  • void ChangeSize (GLsizei w, GLsizei h)
  • {
  • GLfloat fAspect;
  • //prevent a divide by zero
  • if ( h == 0)
  • h = 1;
  • // Set viewport to window dimensions
  • glViewport(0, 0, w, h);
  • // Calculate the ratio of aspect
  • fAspect = (GLfloat)w / (GLfloat)h;
  • //Set the perspective coordinate system
  • glMatrixMode(GL_PROJECTION);
  • glLoadIdentity();
  • gluPerspective(45.0f, fAspect, 1.0, 450.0 );
  • glMatrixMode(GL_MODELVIEW);
  • glLoadIdentity();
  • }
  • void main (void)
  • {
  • glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  • glutCreateWindow("Solar System");
  • glutDisplayFunc(RenderScene);
  • glutReshapeFunc(ChangeSize);
  • SetupRC();
  • glutMainLoop();
  • }
#include <windows.h>
#include <gl\glut.h>

float g_LightPosition[3] = {0, 0, -300};
float g_bLight = true;	

void RenderScene (void)
{
	//angle of revolution for moon/earth
	static float fMoonRot = 0.0f;
	static float fEarthRot = 0.0f;



	//clear the screen with current clearing color
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

	//Save matrix state and the rotations
	glMatrixMode(GL_MODELVIEW);

	glPushMatrix();

	
	glLightfv( GL_LIGHT0, GL_POSITION, g_LightPosition );	

	// Translate view 300 units 'into' the screen
	glTranslatef(0.0f, 0.0f, -300.0f);

	//Set material color, Red
	//Sun
	glColor3ub(255, 255, 0);

	glutSolidSphere(18.0f, 15, 15);

	//Rotate coordinate system for the earth
	glRotatef(fEarthRot, 0.0, 1.0f, 0.0f);

	//Draw the Earth
	glColor3ub(0, 0, 255); //blue color
	glTranslatef(105.0f, 0.0f, 0.0f);
	glutSolidSphere(10.0f, 15, 15);

	// Moon Rotation from earth-based coordinated
	glColor3ub(200,200,200);
	glRotatef(fMoonRot, 0.0f, 1.0f, 0.0f);
	glTranslatef(30.0f, 0.0f, 0.0f);

	fMoonRot += 1.0f;
	if (fMoonRot > 360.0f )
		fMoonRot = 0.0f;

	glutSolidSphere(5.0f, 15, 15);

	//Restore the matrix
	glPopMatrix();

	//Step earth orbit 5 degrees
	fEarthRot += 1.0f;
	if ( fEarthRot > 360.0f )
		fEarthRot = 0.0f;

	glutSwapBuffers();
	glutPostRedisplay();

}

void SetupRC (void)
{

	glEnable(GL_DEPTH_TEST);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

	float ambience[4] = {0.5f, 0.5f, 0.5f, 1.0};		
	float diffuse[4] = {0.5f, 0.5f, 0.5f, 1.0};

	glLightfv( GL_LIGHT0, GL_AMBIENT,  ambience );
	
	glLightfv( GL_LIGHT0, GL_DIFFUSE,  diffuse );	
	
	glLightfv( GL_LIGHT0, GL_POSITION, g_LightPosition );

	glEnable(  GL_LIGHT0   );

	glEnable(  GL_LIGHTING );

	glEnable(GL_COLOR_MATERIAL);

}


void ChangeSize (GLsizei w, GLsizei h)
{
	GLfloat fAspect;

	//prevent a divide by zero
	if ( h == 0)
		h = 1;

	// Set viewport to window dimensions
	glViewport(0, 0, w, h);

	// Calculate the ratio of aspect
	fAspect = (GLfloat)w / (GLfloat)h;

	//Set the perspective coordinate system
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	gluPerspective(45.0f, fAspect, 1.0, 450.0 );

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

}

void main (void)
{
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutCreateWindow("Solar System");
	glutDisplayFunc(RenderScene);
	glutReshapeFunc(ChangeSize);

	SetupRC();

	glutMainLoop();
}


 



 Sources du même auteur

EFFECT TRANSPARENT ( TOUJOURS AVEC CAMERA ET SPIN )
CUBE TOURNANT AVEC CAMERA MOVEMENT ET ECLAIRAGE
PASSWORD MASKING
EQUATION QUADRATIQUE

 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

Commentaires et avis

Commentaire de LordBob le 03/05/2003 01:25:45

un zip ca aurrait été pas mal avec ca non???

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

Photothèque

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,406 sec (3)

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