You are on page 1of 5

#include<windows.

h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

#include <stdlib.h>
#include<time.h>
#include <math.h>

int rad=100;

void circuloc(int x, int y, int t, int radio)


{
int angulo=0;
glPointSize(t);
glBegin(GL_POINTS);
glVertex2f(x,y);
for(angulo=0;angulo<=360;angulo+=1)
{

glVertex2f(x+sin(angulo)*radio,y+cos(angulo)*radio);

}
glEnd();
}

void dibujar()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glColor3f(1.0,1.0,1.0);

circuloc(0,0,0,310);
circuloc(0,0,0,280);
circuloc(0,0,0,250);
circuloc(0,0,0,220);
circuloc(0,0,0,190);
circuloc(0,0,0,160);
circuloc(0,0,0,130);
circuloc(0,0,0,100);
circuloc(0,0,0,70);

// inicializando de variables

GLfloat rotA=0,rot1=0,rot2=0,rot3=0,rot4=0,rot5=0,rot6=0,rot7=0,rot8=0;
GLfloat rdS=30,
rd1=6,
rd2=12,
rd3=9,
rd4=6,
rd5=18,
rd6=15,
rd7=12,
rd8=12;
GLfloat posx=0,posz=0;

//Inicializacion de variables para iluminacion

GLfloat mat_diffuse [] = {0.0, 0.0, 0.0, 1.0};


GLfloat mat_specular [] = {0.5, 0.5, 0.5, 1.0};
GLfloat mat_shininess [] = {50};
GLfloat mat_emission [] = {0.5, 0.2, 0.2, 1.0};

void resize(int width, int height)


{
glViewport(0, 0, width, height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-300,300,-300,300,-300,300);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();//matriz identidad
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);

//iluminacion

void iluminacion ()
{
GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0};
glLightfv(GL_LIGHT0,GL_POSITION, light_position);

glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);


glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);

//CREACION DE LOS PLANETAS

void sol()
{
glColor3f(1.0,1.0,0.0);
glutSolidSphere(rdS,60,60);
}
void mercurio()
{
glColor3f(0.4,0.4,0.4);
glutSolidSphere(rd1,60,60);
}
void venus()
{
glColor3f(1.0,0.2,0.0);
glutSolidSphere(rd2,60,60);
}
void tierra()
{
glColor3f(0.0,0.4,1.0);
glutSolidSphere(rd3,60,60);
}
void marte()
{
glColor3f(0.2,0.4,0.3);
glutSolidSphere(rd4,60,60);
}
void jupiter()
{
glColor3f(0.2,0.2,0.2);
glutSolidSphere(rd5,60,60);
}
void saturno()
{
glColor3f(1.0,0.4,0.0);
glutSolidSphere(rd6,60,60);
}
//----------------------------------//
void urano()
{
glColor3f(0.2,1.0,0.2);
glutSolidSphere(rd7,60,60);
}
void anillos()
{
glColor3f(1,0.6,0);
glRotatef(rotA,1,0,1);
glutSolidTorus(3, 20, 10,50);
}
//----------------------------------//
void neptuno()
{
glColor3f(0.0,0.0,1.0);
glutSolidSphere(rd8,60,60);
}

//-------------------------------------//

//CREACION DE LA ESCENA

void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0);
iluminacion ();
dibujar();
sol();

glPushMatrix();
glRotatef(rot1,0,1,0);
glTranslatef(-40,0,0); //rotacion y traslacion para mercurio
mercurio();
glPopMatrix();

glPushMatrix();
glRotatef(rot2,0,1,0);
glTranslatef(60,0,0);//rotacion y traslacion para mercurio
venus();
glPopMatrix();

glPushMatrix();
glRotatef(rot3,0,1,0);
glTranslatef(0,0,-80);//rotacion y tralacion para tierra
tierra();
glPopMatrix();

glPushMatrix();
glRotatef(rot4,0,1,0);
glTranslatef(100,0,0);//rotacion y traslacion para marte
marte();
glPopMatrix();

glPushMatrix();
glRotatef(rot5,0,1,0);
glTranslatef(-120,0,0);//rotacion y traslacion para jupiter
jupiter();
glPopMatrix();

glPushMatrix();
glRotatef(rot6,0,1,0);
glTranslatef(0,0,160);//rotacion y traslacion para saturno y anillo
saturno();
anillos();
glPopMatrix();

glPushMatrix();
glRotatef(rot7,0,1,0);
glTranslatef(-170,0,0);//rotacion y traslacion para urano
urano();
glPopMatrix();

glPushMatrix();
glRotatef(rot8,0,1,0);
glTranslatef(190,0,0);//rotacion y traslacion para neptuno
neptuno();
glPopMatrix();

rotA=rotA+0.03;
rot1=rot1+0.1;
rot2=rot2+0.015;
rot3=rot3+0.013;
rot4=rot4+0.05;
rot5=rot5+0.04;
rot6=rot6+0.03;
rot7=rot7+0.02;
rot8=rot8+0.01;

glutSwapBuffers();
}

//MANEJO DE CAMARA

void key(unsigned char key, int x, int y) //funcion para uso del teclado
{
switch(key)
{
case 27 :
exit(0);
break;
default:
break;
}

glutPostRedisplay(); //redibuja el display


}

void idle()
{
glutPostRedisplay();//redibuja el display
}

int main (int argc, char *argv[])


{
glutInit(&argc, argv);
glutInitWindowSize(950,700);//tamaño de la ventana
glutInitWindowPosition(0,0);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("SISTEMA PLANETARIO SOLAR");
glClearColor(0,0,0,0);
glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutIdleFunc(idle);

glutMainLoop();
return 0;
}

You might also like