You are on page 1of 19

#ifdef __APPLE__

#include <GL/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define M_PI 3.141592653


#define DEF_dollyStepSize 1.0
#define DEF_angleSensitivity 1.0

static int slices = 16;


static int stacks = 16;

static void resize(int width, int height){


const float ar = (float) width / (float) height;

glViewport(0, 0, width, height);


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
}

struct Point3f{
float x, y, z;
float u, v;
};

float LightPos0[] = { 0.75f, 1.0f, 1.0f, 0.0f};


float LightAmb0[] = { 0.75f, 0.75f, 0.75f, 1.0f};
float LightDif0[] = { 1.0f, 1.0f, 1.0f, 1.0f};
float LightSpc0[] = { 1.0f, 1.0f, 1.0f, 1.0f};

GLfloat camX = 0.0;


GLfloat camY = 8.0;
GLfloat camZ = -40.0;
GLfloat camYaw = 180.0;
GLfloat camPitch = 0.0;

int isInMouseDrag = false;


int mouseIsInverted = true;
int viewPortCenterX = -1;
int viewPortCenterY = -1;
int oldCursorID = 0;
int oldCursorX = 0;
int oldCursorY = 0;

FILE *f;
char line[80];
char mode[15];
char trash[9];
int i,numMaterial;
void planetas(){
const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
const double a = t*90.0;
//SOL
glPushMatrix();
glColor3ub(255,255,0);
glTranslated(0,0,180);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(80,slices,stacks);
glPopMatrix();
//MERCURIO
glPushMatrix();
glColor3ub(144,100,15);
glTranslated(-130,0,150);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(10,slices,stacks);
glPopMatrix();
//VENUS
glPushMatrix();
glColor3ub(89,63,9);
glTranslated(150,0,150);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(30,slices,stacks);
glPopMatrix();
//TIERRA
glPushMatrix();
glColor3ub(23,52,255);
glTranslated(0,0,0);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(30,slices,stacks);
glPopMatrix();
//TIERRA
glPushMatrix();
glColor3ub(227,47,43);
glTranslated(100,0,300);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(30,slices,stacks);
glPopMatrix();

//ESTRELLAS
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(150,150,150);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(150,150,150);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(150,150,150);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();
// Estructura 1
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(50,50,50);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 2
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(75,25,100);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 3
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(30,90,70);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 4
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(120,70,30);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 5
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(80,20,80);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();
// Estructura 6
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(110,90,10);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();
// Estructura 7
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(10,30,120);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 8
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(60,40,90);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 9
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(100,100,100);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 10
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(70,10,50);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 11
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(20,50,80);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 12
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(90,30,20);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 13
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(40,70,60);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 14
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(60,80,40);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 15
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(90,90,60);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 16
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(10,20,70);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 17
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(80,80,80);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 18
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(50,30,70);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 19
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(20,80,20);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();
// Estructura 20
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(70,70,10);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();
// Estructura 21
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(10,10,10);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 22
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(90,90,90);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 23
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(20,40,60);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 24
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(30,70,100);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 25
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(80,20,40);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();
// Estructura 1
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(50,50,50);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 2
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(75,25,100);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 3
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(30,90,70);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 4
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(120,70,30);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 5
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(80,20,80);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 6
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(110,90,10);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 7
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(10,30,120);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 8
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(60,40,90);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 9
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(100,100,100);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 10
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(70,10,50);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 11
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(20,50,80);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 12
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(90,30,20);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 13
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(40,70,60);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 14
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(60,80,40);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();
// Estructura 15
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(90,90,60);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 16
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(10,20,70);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 17
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(80,80,80);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 18
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(50,30,70);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 19
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(20,80,20);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 20
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(70,70,10);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 21
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(10,10,10);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 22
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(90,90,90);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 23
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(20,40,60);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 24
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(30,70,100);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 25
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(80,20,40);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 26
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(60,10,70);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 27
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(-70,60,30);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();
// Estructura 28
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(40,10,90);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 29
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(-20,60,-50);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 30
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(70,-30,60);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();
// ... Continuar con las estructuras 31 a 100 con coordenadas diferentes ...
// Estructura 31
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(50,90,20);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 32
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(30,-50,70);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 33
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(80,80,-20);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 34
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(10,-40,90);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 35
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(60,-60,60);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// ... Continuar con las estructuras 36 a 100 con coordenadas diferentes ...
// Estructura 36
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(30,-10,60);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 37
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(-70,20,100);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 38
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(20,-70,40);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 39
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(40,30,80);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 40
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(80,60,-20);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();
// ... Continuar con las estructuras 41 a 100 con coordenadas diferentes ...
// Estructura 41
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(-50,-50,-50);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 42
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(-75,-25,-100);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 43
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(-30,-90,-70);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 44
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(-120,-70,-30);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 45
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(-80,-20,-80);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 46
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(-110,-90,-10);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 47
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(-10,-30,-120);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 48
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(-60,-40,-90);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 49
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(-100,-100,-100);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// Estructura 50
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(-70,-10,-50);
glRotated(60,1,0,0);
glRotated(a,0,0,1);
glutSolidSphere(1,slices,stacks);
glPopMatrix();

// ... Continuar con las estructuras 51 a 100 con coordenadas diferentes ...

}
void graficarEjes(){
glBegin(GL_LINES);
glColor3f(1,0,0);
glVertex3f(-40,0,0);
glVertex3f(40,0,0);
glColor3f(0,1,0);
glVertex3f(0,-40,0);
glVertex3f(0,40,0);
glColor3f(0,0,1);
glVertex3f(0,0,0);
glVertex3f(0,0,30);
glEnd();
}
void inicializar(){
glClearColor(0,0,0,0);
glEnable(GL_DEPTH_TEST);
}

void enterMouseDrag( int x, int y ){


if( isInMouseDrag )
return;
isInMouseDrag = true;
if( viewPortCenterX < 0 )
{
viewPortCenterX = glutGet( GLUT_WINDOW_WIDTH ) / 2;
viewPortCenterY = glutGet( GLUT_WINDOW_HEIGHT ) / 2;
}
oldCursorID = glutGet( GLUT_WINDOW_CURSOR );
oldCursorX = x;
oldCursorY = y;
glutSetCursor( GLUT_CURSOR_NONE );
glutWarpPointer( viewPortCenterX, viewPortCenterY );
}
void exitMouseDrag( int x, int y ){
if( !isInMouseDrag )
return;
isInMouseDrag = false;
glutSetCursor( oldCursorID );
glutWarpPointer( oldCursorX, oldCursorY );
}
void clampCamera(){
if( camPitch > 90.0 )
camPitch = 90.0;
else if( camPitch < -90.0 )
camPitch = -90.0;
while( camYaw < 0.0 )
camYaw += 360.0;
while( camYaw >= 360.0 )
camYaw -= 360.0;
}
void dollyCamera( GLfloat dollyBy, GLfloat dollyAngle ){
GLfloat actualAngleInRadians;
actualAngleInRadians = ( ( camYaw + dollyAngle ) * M_PI / 180.0 );
camX -= sin( actualAngleInRadians ) * dollyBy * DEF_dollyStepSize;
camZ -= cos( actualAngleInRadians ) * dollyBy * DEF_dollyStepSize;
}
void keyboard(unsigned char key, int x, int y){
switch (key) {
case 'w':
case 'W':
dollyCamera( DEF_dollyStepSize, 0.0 );
break;

case 's':
case 'S':
dollyCamera( DEF_dollyStepSize, 180.0 );
break;

case 'a':
case 'A':
dollyCamera( DEF_dollyStepSize, 90.0 );
break;

case 'd':
case 'D':
dollyCamera( DEF_dollyStepSize, 270.0 );
break;

case 'i':
case 'I':
mouseIsInverted = !mouseIsInverted;
break;
case 'Q':
case 'q':
exit(0);
break;

case 'R':
case 'r':
slices++;
stacks++;
break;

case 'L':
case 'l':
if (slices>3 && stacks>3){
slices--;
stacks--;
}
break;

case 'E':
case 'e':
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };

const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };


const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };

glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);


glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);


glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
break;

}
}
void specialFunc( int key, int x, int y ){
switch( key )
{
//giro a la izquierda
case GLUT_KEY_LEFT:
camYaw += 1.0;
clampCamera();
break;

// giro a la derecha.
case GLUT_KEY_RIGHT:
camYaw -= 1.0;
clampCamera();
break;
// mirar hacia arriba.
case GLUT_KEY_UP:
camPitch += 1.0;
clampCamera();
break;

// mirar hacia abajo


case GLUT_KEY_DOWN:
camPitch -= 1.0;
clampCamera();
break;
}
}
void mouseFunc( int button, int state, int x, int y ){
if( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN )
{
if( !isInMouseDrag )
enterMouseDrag( x, y );
else
exitMouseDrag( x, y );
}
}
void allMotionFunc( int x, int y ){
int deltaX, deltaY;

if( !isInMouseDrag )
return;
deltaX = x - viewPortCenterX;
deltaY = y - viewPortCenterY;
if( deltaX == 0 && deltaY == 0 )
return;
glutWarpPointer( viewPortCenterX, viewPortCenterY );
camYaw -= DEF_angleSensitivity * deltaX;
camPitch -= DEF_angleSensitivity * deltaY * ( mouseIsInverted ? -1.0 : 1.0 );
clampCamera();
glutPostRedisplay();
}
void myReshape(int w, int h){
if (!h)
return;
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 1000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
viewPortCenterX = w / 2;
viewPortCenterY = h / 2;
}
void redimensionar(int w, int h){
glViewport(0,0, w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90, (float)w/(float)h,2,500);
}
void idle(void){
glutPostRedisplay();
}
static void key(unsigned char key, int x, int y){
switch (key)
{
case '0':
exit(0);
break;

case 'r':
slices++;
stacks++;
break;

case 'l':
if (slices>3 && stacks>3)
{
slices--;
stacks--;
}
break;

case 'f':
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };

const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };


const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };

glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);


glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);


glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
break;
}

glutPostRedisplay();
}

void graficar(void){
glMatrixMode(GL_PROJECTION);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glRotatef( -camPitch, 1.0, 0.0, 0.0 );


glRotatef( -camYaw, 0.0, 1.0, 0.0 );
glTranslatef( -camX, -camY, -camZ );
graficarEjes();
//INICIO
planetas();
//FIN
glEnd();
glPopMatrix();
glFlush();
glutSwapBuffers();
}

int main(int argc, char** argv){


glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(1400,1200);
glutInitWindowPosition(100,200);
glutCreateWindow("Galaxia");
inicializar();
glutReshapeFunc(redimensionar);

glutDisplayFunc(graficar);
glutReshapeFunc(myReshape);
glutKeyboardFunc(keyboard);
glutSpecialFunc( specialFunc );
glutMouseFunc( mouseFunc );
glutMotionFunc( allMotionFunc );
glutPassiveMotionFunc( allMotionFunc );
glutIdleFunc(idle);

glClearColor(0,0,0,0);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);

glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);

glutMainLoop();
return 0;
}

You might also like