viernes, 5 de octubre de 2012

Proyecto Unidad 2


Proyecto Unidad 2

Código Fuente

#include <glut.h>

float angX=0.0f,angY=0.0f;
int ResX=800,ResY=600;
enum{EJE=2};
float angB=0.0f,angC=0.0f,angDE=0.0f;
float aceX=0.0f,aceY=-0.0001f;
float velX=0.001f,velY=0.0f;
float posX=0.0f,posY=10.0f;

//Colores
GLfloat material [4] = {1.0f, 0.2f, 0.2f, 1.0f };
GLfloat RedMaterial [4] = {1.0, 0.0, 0.0, 1.0 };
GLfloat WhiteMaterial [4] = {1.0, 1.0, 1.0, 1.0 };

void EjesReferencia()
{
glNewList(1,GL_COMPILE);
glBegin (GL_LINES);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, WhiteMaterial );
glVertex3f ( 0.0, 0.0, 0.0);
glVertex3f ( 0.0, 0.0,20.0);
glEnd();
glEndList();
}

void pEJE(){
glNewList(2,GL_COMPILE);
glPushMatrix();
glutSolidSphere(0.5f,100,100);
glPopMatrix();
glEndList();
}


void RenderScene(void){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

//camara
glLoadIdentity( );
glTranslatef(1.0f,0.0f,-10.0f);
glRotatef(angY,1.0f,0.0f,0.0f);
glRotatef(angX,0.0f,1.0f,0.0f);
//EJES DE REFERENCIA
glLineWidth(5);
glCallList(1);
glPushMatrix();
glScalef(1,1,1);
glTranslatef(1.0f,1.0f,1.0f);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, RedMaterial );
glPushMatrix();
glTranslatef(posX,posY,0.0f);
glCallList(EJE);
glPopMatrix();
glutSwapBuffers();
}


void idle(void){
velY+=aceY; posY+=velY;
velX+=aceX; posX+=velX;
if(posY<0.0f){posY=0.0f; velY*=-0.8f;
if(velY<0.01f){velX=0.0f; velY=0.0f;}
}
glutPostRedisplay();
}


int main(int a, char *b[]){
glutInit(&a,b);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(ResX,ResY);
glutInitWindowPosition(100,100);

glutCreateWindow("Proyecto");
glutDisplayFunc(RenderScene);

glutIdleFunc(idle);
glViewport( 0, 0, ResX, ResY );
glMatrixMode( GL_PROJECTION );
glLoadIdentity( );
glFrustum(-(float)ResX/ResY, (float)ResX/ResY, -1.0, 1.0, 1, 1000.0);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity( );
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);

EjesReferencia();
pEJE();
glutMainLoop();
return 0;
}



No hay comentarios:

Publicar un comentario