Professional Documents
Culture Documents
Modelo Examen t3
Modelo Examen t3
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;
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;
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);
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;
}
void idle()
{
glutPostRedisplay();//redibuja el display
}
glutMainLoop();
return 0;
}