Programa Equipo 4

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Programa del sistema solar

#include <windows.h>

#include <C:\GLUT\include\GL\glut.h>

#include <cstdlib>

#include <iostream>

#include <math.h>

GLfloat anguloCubox = 0.0f;

GLfloat angle = 0.0f;

GLint ancho = 400;

GLint alto = 400;

GLfloat lightpos[] = { 0.0, 0.0, -3.9 };

GLfloat lightcolor[] = { 1.0, 1.0, 1.0 };

GLfloat ambcolor[] = { 0.2, 0.2, 0.2 };

int hazPerspectiva = 0;

float x = 1.5;

float VELOCIDAD = 0.2;

void rotacion(float l) {

glRotatef(l, 0.0, 1.0, 0.0);

void traslacion(float x, float y) {

glTranslatef(x, y, 0);

}
void reshape(int width, int heigth)

glViewport(0, 0, width, heigth);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

if (hazPerspectiva)

gluPerspective(60.0f, (GLfloat)width / (GLfloat)heigth, 1.0f, 20.0f);

else

glOrtho(-4, 4, -4, 4, 1, 10);

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)

GLfloat ambient[] = { ambientR,ambientG,ambientB };

GLfloat diffuse[] = { diffuseR,diffuseG,diffuseB };

GLfloat specular[] = { specularR,specularG,specularB };

glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);

glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);

glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);

glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);

void draw() {
glPushMatrix();

glTranslatef(0, 0, 0);

rotacion(anguloCubox);

glTranslatef(x, 0, 0);

glColor3f(0.3, 0, 0.3);

setMaterial(0.0, 0.0, 0.0, 0.3, 0.3, 0.3, 0.2, 0.2, 0.2,0.2);

glutSolidSphere(0.2, 50, 50);

glPopMatrix();

//anillo

glPushMatrix();

glTranslatef(0, 0, 0);

rotacion(anguloCubox);

glTranslatef(x, 0, 0);

glTranslatef(0, 0, 0);

glRotatef(anguloCubox, -1.0f, 0.0f, -1.0f);

glTranslatef(0, 0, 0);

glColor3f(0.8, 0.8, 0.8);

setMaterial(0.0, 0.0, 0.0, 0.7, 0.0, 0.3, 0.1, 0.1, 0.1, 0.0);

glutSolidTorus(0.02, 0.5, 100, 100);

glColor3f(0.9, 0.9, 0.9);

setMaterial(0.0, 0.0, 0.0, 0.7, 0.0, 0.3, 0.1, 0.1, 0.1, 0.0);

glutSolidTorus(0.02, 0.40, 100, 100);

glutSolidTorus(0.02, 0.39, 100, 100);

glutSolidTorus(0.02, 0.38, 100, 100);


glColor3f(0.6, 0.6, 0.6);

setMaterial(0.0, 0.0, 0.0, 0.7, 0.0, 0.3, 0.1, 0.1, 0.1, 0.0);

glutSolidTorus(0.02, 0.37, 100, 100);

glutSolidTorus(0.02, 0.36, 100, 100);

glutSolidTorus(0.02, 0.35, 100,100);

glPopMatrix();

//Luna

glPushMatrix();

glColor3f(1, 1, 1);

glTranslatef(0, 0, 0);

rotacion(anguloCubox);

glTranslatef(x, 0, 0);

glPushMatrix();

glTranslatef(0.7, 0, 0);

glRotatef(-anguloCubox, -1.0f, 1.0f, -1.0f);

glTranslatef(0, 0, 0);

setMaterial(0, 0, 0, 0.7, 0.6, 0.0, 0.7, 0.7, 0.7, 0.6);

glutSolidSphere(0.08, 100, 100);

glPopMatrix();

glPopMatrix();

void display()

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();

hazPerspectiva = 1;
glTranslatef(0.0f, 0.0f, -0.5f);

glRotatef(1, 1.0f, 0.0f, 0.0f);

//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

glutSolidSphere(0.5, 100, 100);

draw();

glLoadIdentity();

glFlush();

glutSwapBuffers();

anguloCubox += VELOCIDAD; // Velocidad de rotación de la tierra

void init()

glClearColor(0, 0, 0, 0);

glEnable(GL_DEPTH_TEST);

ancho = 400;

alto = 400;

void idle()

display();

int main(int argc, char** argv)


{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);

glutInitWindowPosition(100,100);

glutInitWindowSize(ancho, alto);

glutCreateWindow("Cosmos");

init();

glutDisplayFunc(display);

glutReshapeFunc(reshape);

glutIdleFunc(idle);

//código de iluminación general//

glEnable(GL_LIGHTING);

glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambcolor);

glEnable(GL_LIGHT0);

glLightfv(GL_LIGHT0, GL_POSITION, lightpos);

glLightfv(GL_LIGHT0, GL_AMBIENT, lightcolor);

glLightfv(GL_LIGHT0, GL_DIFFUSE, lightcolor);

glLightfv(GL_LIGHT0, GL_SPECULAR, lightcolor);

glutMainLoop();

return 0;

You might also like