Robot en opengl

Solo disponible en BuenasTareas
  • Páginas : 5 (1034 palabras )
  • Descarga(s) : 11
  • Publicado : 28 de julio de 2010
Leer documento completo
Vista previa del texto
#include

GLfloat angulo1 = 0.0f;
GLfloat tras1 = 0.0f;
GLfloat tras2 = 0.0f;
GLfloat tras3 = 0.0f;
GLfloat tras4 = 0.0f;

GLfloat lim1 = 0.0f;
GLfloat lim2 = 0.0f;
GLfloat lim3 = 0.0f;
GLfloat lim4 = 0.0f;

void reshape(int width, int height){

glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();glOrtho(-4,4, -4, 4, 1, 10);
glMatrixMode(GL_MODELVIEW);
}

void drawCube(void){


glBegin(GL_QUADS); //cara frontal
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-0.5f, -0.5f, 0.5f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f( 0.5f, -0.5f, 0.5f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glColor3f(1.0f, 1.0f, 0.0f);glVertex3f(-0.5f, 0.5f, 0.5f);

glEnd();


glBegin(GL_QUADS); //cara trasera
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f( 0.5f, -0.5f, -0.5f);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glColor3f(1.0f, 1.0f, 0.0f);
glVertex3f( 0.5f, 0.5f, -0.5f);

glEnd();glBegin(GL_QUADS); //cara lateral izq
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(-0.5f,-0.5f, -0.5f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-0.5f,-0.5f, 0.5f);
glColor3f(0.0f,1.0f,1.0f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glColor3f(1.0f, 1.0f, 0.0f);
glVertex3f(-0.5f, 0.5f, -0.5f);

glEnd();


glBegin(GL_QUADS); //caralateral dcha
glColor3f(1.0f, 1.0f, 0.0f);
glVertex3f(0.5f, -0.5f, 0.5f);
glColor3f(0.0f,1.0f,1.0f);
glVertex3f(0.5f, -0.5f, -0.5f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(0.5f, 0.5f, -0.5f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(0.5f, 0.5f, 0.5f);

glEnd();


glBegin(GL_QUADS); //cara arriba
glColor3f(0.0f,1.0f,1.0f);glVertex3f(-0.5f, 0.5f, 0.5f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glColor3f(1.0f, 0.0f, 1.0f);
glVertex3f( 0.5f, 0.5f, -0.5f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glEnd();


glBegin(GL_QUADS); //cara abajo
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f( 0.5f,-0.5f, -0.5f);
glColor3f(1.0f,0.0f, 1.0f);
glVertex3f( 0.5f,-0.5f, 0.5f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-0.5f,-0.5f, 0.5f);
glColor3f(0.0f, 1.0f, 1.0f);
glVertex3f(-0.5f,-0.5f, -0.5f);
glEnd();

}

void display(){

//GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
//GLfloat mat_diffuse[] = { 0.1f, 0.5f, 0.8f, 1.0f };
//GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f,1.0f };
//GLfloat mat_shininess[] = { 10.0f };

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//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, mat_shininess);

//crear base
glLoadIdentity();glTranslatef(0.0f, -1.3f, -5.0f);
glScalef(2.0f, 0.5f, 2.0f);
//glutSolidCube (1.0);
drawCube();

//crear caja2
glLoadIdentity();
glTranslatef(0.0f, 0.5f, -5.0f);
glRotatef(angulo1, 0.0f, 1.0f, 0.0f);
glScalef(0.5f, 4.0f, 0.5f);
//glutSolidCube (1.0);
drawCube();

//crear caja3
glLoadIdentity();
glTranslatef(0.0f,1.5f+tras1, -5.0f);
glRotatef(angulo1, 0.0f, 1.0f, 0.0f);
glScalef(1.0f, 1.0f, 1.0f);
//glutSolidCube (1.0);
drawCube();

//crear caja4
glLoadIdentity();
glTranslatef(0.0f, 1.5f+tras1, -5.0f);
glRotatef(angulo1, 0.0f, 1.0f, 0.0f);
glTranslatef(1.0f, 0.0f, 0.0f);
glScalef(4.0f, 0.5f, 0.5f);
//glutSolidCube (1.0);
drawCube();

//crear caja5...
tracking img