Accueil > > > SYSTEM SOLAIRE AVEC LIGHTING
SYSTEM SOLAIRE AVEC LIGHTING
Information sur la source
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
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
RE : SAC A DOS RE : SAC A DOS par hadjkaddour
Cliquez pour lire la suite par hadjkaddour
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|