Professional Documents
Culture Documents
Programa Equipo 4
Programa Equipo 4
Programa Equipo 4
#include <windows.h>
#include <C:\GLUT\include\GL\glut.h>
#include <cstdlib>
#include <iostream>
#include <math.h>
int hazPerspectiva = 0;
float x = 1.5;
void rotacion(float l) {
glTranslatef(x, y, 0);
}
void reshape(int width, int heigth)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (hazPerspectiva)
else
glMatrixMode(GL_MODELVIEW);
alto = width;
ancho = heigth;
void setMaterial(GLfloat ambientR, GLfloat ambientG, GLfloat ambientB, GLfloat diffuseR, GLfloat
diffuseG, GLfloat diffuseB, GLfloat specularR, GLfloat specularG, GLfloat specularB, GLfloat
shininess)
void draw() {
glPushMatrix();
glTranslatef(0, 0, 0);
rotacion(anguloCubox);
glTranslatef(x, 0, 0);
glColor3f(0.3, 0, 0.3);
glPopMatrix();
//anillo
glPushMatrix();
glTranslatef(0, 0, 0);
rotacion(anguloCubox);
glTranslatef(x, 0, 0);
glTranslatef(0, 0, 0);
glTranslatef(0, 0, 0);
setMaterial(0.0, 0.0, 0.0, 0.7, 0.0, 0.3, 0.1, 0.1, 0.1, 0.0);
setMaterial(0.0, 0.0, 0.0, 0.7, 0.0, 0.3, 0.1, 0.1, 0.1, 0.0);
setMaterial(0.0, 0.0, 0.0, 0.7, 0.0, 0.3, 0.1, 0.1, 0.1, 0.0);
glPopMatrix();
//Luna
glPushMatrix();
glColor3f(1, 1, 1);
glTranslatef(0, 0, 0);
rotacion(anguloCubox);
glTranslatef(x, 0, 0);
glPushMatrix();
glTranslatef(0.7, 0, 0);
glTranslatef(0, 0, 0);
glPopMatrix();
glPopMatrix();
void display()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
hazPerspectiva = 1;
glTranslatef(0.0f, 0.0f, -0.5f);
//Materiales esfera 1
setMaterial(0.35, 0.0, 0.0, 0.3, 0.3, 0.0, 0.7, 0.7, 0.7, 0.6);
//esfera 1
draw();
glLoadIdentity();
glFlush();
glutSwapBuffers();
void init()
glClearColor(0, 0, 0, 0);
glEnable(GL_DEPTH_TEST);
ancho = 400;
alto = 400;
void idle()
display();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(100,100);
glutInitWindowSize(ancho, alto);
glutCreateWindow("Cosmos");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glEnable(GL_LIGHTING);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambcolor);
glEnable(GL_LIGHT0);
glutMainLoop();
return 0;