martes, 29 de octubre de 2013

jueves, 17 de octubre de 2013

Cubo Rubick

// cubo rubick.cpp: define el punto de entrada de la aplicación de consola.
//
#include "stdafx.h"
#include <stdlib.h>
#include <GL/glut.h>

GLfloat escala = 1.25f;
GLfloat angulo = 0.0f;
GLfloat angulo1 = 0.0f;
void reshape(int width, int height)
{
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
 glOrtho(-10,20,-4,10,-8,5);
glMatrixMode(GL_MODELVIEW);
}

void display(){
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
angulo-=0.0f;
 glRotatef(angulo, 1.0f, 0.0f, 0.0f);
glRotatef(angulo1, 0.0f, 1.0f, 0.0f);
glTranslatef(-5.5f,-1.5f,1.5f);
//cara frontal
//hilera 1
 glColor3f(1,0,0);
 glBegin(GL_POLYGON);
 glVertex3f(4,0,0);
 glVertex3f(5,0,0);
 glVertex3f(5,1,0);
 glVertex3f(4,1,0);
 glEnd();
 glColor3f(1,0,0);
 glBegin(GL_POLYGON);
 glVertex3f(5,0,0);
 glVertex3f(6,0,0);
 glVertex3f(6,1,0);
 glVertex3f(5,1,0);
 glEnd();
 glColor3f(1,0,0);
 glBegin(GL_POLYGON);
 glVertex3f(6,0,0);
 glVertex3f(7,0,0);
 glVertex3f(7,1,0);
 glVertex3f(6,1,0);
 glEnd();
//hilera2
 glColor3f(1,0,0);
 glBegin(GL_POLYGON);
 glVertex3f(4,1,0);
 glVertex3f(5,1,0);
 glVertex3f(5,2,0);
 glVertex3f(4,2,0);
 glEnd();
 glColor3f(1,0,0);
 glBegin(GL_POLYGON);
 glVertex3f(5,1,0);
 glVertex3f(6,1,0);
 glVertex3f(6,2,0);
 glVertex3f(5,2,0);
 glEnd();
 glColor3f(1,0,0);
 glBegin(GL_POLYGON);
 glVertex3f(6,1,0);
 glVertex3f(7,1,0);
 glVertex3f(7,2,0);
 glVertex3f(6,2,0);
 glEnd();
//hilera3
 glColor3f(1,0,0);
 glBegin(GL_POLYGON);
 glVertex3f(4,2,0);
 glVertex3f(5,2,0);
 glVertex3f(5,3,0);
 glVertex3f(4,3,0);
 glEnd();
 glColor3f(1,0,0);
 glBegin(GL_POLYGON);
 glVertex3f(5,2,0);
 glVertex3f(6,2,0);
 glVertex3f(6,3,0);
 glVertex3f(5,3,0);
 glEnd();
 glColor3f(1,0,0);
 glBegin(GL_POLYGON);
 glVertex3f(6,2,0);
 glVertex3f(7,2,0);
 glVertex3f(7,3,0);
 glVertex3f(6,3,0);
 glEnd();
 //cara superior
 //hilera1
 glColor3f(1,1,1);
 glBegin(GL_POLYGON);
 glVertex3f(4,3,0);
 glVertex3f(5,3,0);
 glVertex3f(5,3,-1);
 glVertex3f(4,3,-1);
 glEnd();
 glColor3f(1,1,1);
 glBegin(GL_POLYGON);
 glVertex3f(5,3,0);
 glVertex3f(6,3,0);
 glVertex3f(6,3,-1);
 glVertex3f(5,3,-1);
 glEnd();
 glColor3f(1,1,1);
 glBegin(GL_POLYGON);
 glVertex3f(6,3,0);
 glVertex3f(7,3,0);
 glVertex3f(7,3,-1);
 glVertex3f(6,3,-1);
 glEnd();
//hilera2
 glColor3f(1,1,1);
 glBegin(GL_POLYGON);
 glVertex3f(4,3,-1);
 glVertex3f(5,3,-1);
 glVertex3f(5,3,-2);
 glVertex3f(4,3,-2);
 glEnd();
 glColor3f(1,1,1);
 glBegin(GL_POLYGON);
 glVertex3f(5,3,-1);
 glVertex3f(6,3,-1);
 glVertex3f(6,3,-2);
 glVertex3f(5,3,-2);
 glEnd();
 glColor3f(1,1,1);
 glBegin(GL_POLYGON);
 glVertex3f(6,3,-1);
 glVertex3f(7,3,-1);
 glVertex3f(7,3,-2);
 glVertex3f(6,3,-2);
 glEnd();
 //hilera3
 glColor3f(1,1,1);
 glBegin(GL_POLYGON);
 glVertex3f(4,3,-2);
 glVertex3f(5,3,-2);
 glVertex3f(5,3,-3);
 glVertex3f(4,3,-3);
 glEnd();
 glColor3f(1,1,1);
 glBegin(GL_POLYGON);
 glVertex3f(5,3,-2);
 glVertex3f(6,3,-2);
 glVertex3f(6,3,-3);
 glVertex3f(5,3,-3);
 glEnd();
 glColor3f(1,1,1);
 glBegin(GL_POLYGON);
 glVertex3f(6,3,-2);
 glVertex3f(7,3,-2);
 glVertex3f(7,3,-3);
 glVertex3f(6,3,-3);
 glEnd();
//cara posterior
 //hilera1
 glColor3f(1,.5,0);
 glBegin(GL_POLYGON);
 glVertex3f(4,0,-3);
 glVertex3f(5,0,-3);
 glVertex3f(5,1,-3);
 glVertex3f(4,1,-3);
 glEnd();
 glColor3f(1,.5,0);
 glBegin(GL_POLYGON);
 glVertex3f(5,0,-3);
 glVertex3f(6,0,-3);
 glVertex3f(6,1,-3);
 glVertex3f(5,1,-3);
 glEnd();
 glColor3f(1,.5,0);
 glBegin(GL_POLYGON);
 glVertex3f(6,0,-3);
 glVertex3f(7,0,-3);
 glVertex3f(7,1,-3);
 glVertex3f(6,1,-3);
 glEnd();
//hilera2
 glColor3f(1,.5,0);
 glBegin(GL_POLYGON);
 glVertex3f(4,1,-3);
 glVertex3f(5,1,-3);
 glVertex3f(5,2,-3);
 glVertex3f(4,2,-3);
 glEnd();
 glColor3f(1,.5,0);
 glBegin(GL_POLYGON);
 glVertex3f(5,1,-3);
 glVertex3f(6,1,-3);
 glVertex3f(6,2,-3);
 glVertex3f(5,2,-3);
 glEnd();
 glColor3f(1,.5,0);
 glBegin(GL_POLYGON);
 glVertex3f(6,1,-3);
 glVertex3f(7,1,-3);
 glVertex3f(7,2,-3);
 glVertex3f(6,2,-3);
 glEnd();
//hilera3
 glColor3f(1,.5,0);
 glBegin(GL_POLYGON);
 glVertex3f(4,2,-3);
 glVertex3f(5,2,-3);
 glVertex3f(5,3,-3);
 glVertex3f(4,3,-3);
 glEnd();
 glColor3f(1,.5,0);
 glBegin(GL_POLYGON);
 glVertex3f(5,2,-3);
 glVertex3f(6,2,-3);
 glVertex3f(6,3,-3);
 glVertex3f(5,3,-3);
 glEnd();
 glColor3f(1,.5,0);
 glBegin(GL_POLYGON);
 glVertex3f(6,2,-3);
 glVertex3f(7,2,-3);
 glVertex3f(7,3,-3);
 glVertex3f(6,3,-3);
 glEnd();
 //cara inferior
 //hilera1
 glColor3f(1,1,0);
 glBegin(GL_POLYGON);
 glVertex3f(4,0,0);
 glVertex3f(5,0,0);
 glVertex3f(5,0,-1);
 glVertex3f(4,0,-1);
 glEnd();
 glColor3f(1,1,0);
 glBegin(GL_POLYGON);
 glVertex3f(5,0,0);
 glVertex3f(6,0,0);
 glVertex3f(6,0,-1);
 glVertex3f(5,0,-1);
 glEnd();
 glColor3f(1,1,0);
 glBegin(GL_POLYGON);
 glVertex3f(6,0,0);
 glVertex3f(7,0,0);
 glVertex3f(7,0,-1);
 glVertex3f(6,0,-1);
 glEnd();
//hilera2
 glColor3f(1,1,0);
 glBegin(GL_POLYGON);
 glVertex3f(4,0,-1);
 glVertex3f(5,0,-1);
 glVertex3f(5,0,-2);
 glVertex3f(4,0,-2);
 glEnd();
 glColor3f(1,1,0);
 glBegin(GL_POLYGON);
 glVertex3f(5,0,-1);
 glVertex3f(6,0,-1);
 glVertex3f(6,0,-2);
 glVertex3f(5,0,-2);
 glEnd();
 glColor3f(1,1,0);
 glBegin(GL_POLYGON);
 glVertex3f(6,0,-1);
 glVertex3f(7,0,-1);
 glVertex3f(7,0,-2);
 glVertex3f(6,0,-2);
 glEnd();
 //hilera3
 glColor3f(1,1,0);
 glBegin(GL_POLYGON);
 glVertex3f(4,0,-2);
 glVertex3f(5,0,-2);
 glVertex3f(5,0,-3);
 glVertex3f(4,0,-3);
 glEnd();
 glColor3f(1,1,0);
 glBegin(GL_POLYGON);
 glVertex3f(5,0,-2);
 glVertex3f(6,0,-2);
 glVertex3f(6,0,-3);
 glVertex3f(5,0,-3);
 glEnd();
 glColor3f(1,1,0);
 glBegin(GL_POLYGON);
 glVertex3f(6,0,-2);
 glVertex3f(7,0,-2);
 glVertex3f(7,0,-3);
 glVertex3f(6,0,-3);
 glEnd();
 //cara derecha
//hilera 1
 glColor3f(0,0,1);
 glBegin(GL_POLYGON);
 glVertex3f(7,0,0);
 glVertex3f(7,0,-1);
 glVertex3f(7,1,-1);
 glVertex3f(7,1,0);
 glEnd();
 glColor3f(0,0,1);
 glBegin(GL_POLYGON);
 glVertex3f(7,0,-1);
 glVertex3f(7,0,-2);
 glVertex3f(7,1,-2);
 glVertex3f(7,1,-1);
 glEnd();
 glColor3f(0,0,1);
 glBegin(GL_POLYGON);
 glVertex3f(7,0,-2);
 glVertex3f(7,0,-3);
 glVertex3f(7,1,-3);
 glVertex3f(7,1,-2);
 glEnd();
//hilera2
 glColor3f(0,0,1);
 glBegin(GL_POLYGON);
 glVertex3f(7,1,0);
 glVertex3f(7,1,-1);
 glVertex3f(7,2,-1);
 glVertex3f(7,2,-0);
 glEnd();
 glColor3f(0,0,1);
 glBegin(GL_POLYGON);
 glVertex3f(7,1,-1);
 glVertex3f(7,1,-2);
 glVertex3f(7,2,-2);
 glVertex3f(7,2,-1);
 glEnd();
 glColor3f(0,0,1);
 glBegin(GL_POLYGON);
 glVertex3f(7,1,-2);
 glVertex3f(7,1,-3);
 glVertex3f(7,2,-3);
 glVertex3f(7,2,-2);
 glEnd();
//hilera3
 glColor3f(0,0,1);
 glBegin(GL_POLYGON);
 glVertex3f(7,2,0);
 glVertex3f(7,2,-1);
 glVertex3f(7,3,-1);
 glVertex3f(7,3,0);
 glEnd();
 glColor3f(0,0,1);
 glBegin(GL_POLYGON);
 glVertex3f(7,2,-1);
 glVertex3f(7,2,-2);
 glVertex3f(7,3,-2);
 glVertex3f(7,3,-1);
 glEnd();
 glColor3f(0,0,1);
 glBegin(GL_POLYGON);
 glVertex3f(7,2,-2);
 glVertex3f(7,2,-3);
 glVertex3f(7,3,-3);
 glVertex3f(7,3,-2);
 glEnd();
//cara izquierda
//hilera 1
 glColor3f(0,1,0);
 glBegin(GL_POLYGON);
 glVertex3f(4,0,0);
 glVertex3f(4,0,-1);
 glVertex3f(4,1,-1);
 glVertex3f(4,1,0);
 glEnd();
 glColor3f(0,1,0);
 glBegin(GL_POLYGON);
 glVertex3f(4,0,-1);
 glVertex3f(4,0,-2);
 glVertex3f(4,1,-2);
 glVertex3f(4,1,-1);
 glEnd();
 glColor3f(0,1,0);
 glBegin(GL_POLYGON);
 glVertex3f(4,0,-2);
 glVertex3f(4,0,-3);
 glVertex3f(4,1,-3);
 glVertex3f(4,1,-2);
 glEnd();
//hilera2
 glColor3f(0,1,0);
 glBegin(GL_POLYGON);
 glVertex3f(4,1,0);
 glVertex3f(4,1,-1);
 glVertex3f(4,2,-1);
 glVertex3f(4,2,-0);
 glEnd();
 glColor3f(0,1,0);
 glBegin(GL_POLYGON);
 glVertex3f(4,1,-1);
 glVertex3f(4,1,-2);
 glVertex3f(4,2,-2);
 glVertex3f(4,2,-1);
 glEnd();
 glColor3f(0,1,0);
 glBegin(GL_POLYGON);
 glVertex3f(4,1,-2);
 glVertex3f(4,1,-3);
 glVertex3f(4,2,-3);
 glVertex3f(4,2,-2);
 glEnd();
//hilera3
 glColor3f(0,1,0);
 glBegin(GL_POLYGON);
 glVertex3f(4,2,0);
 glVertex3f(4,2,-1);
 glVertex3f(4,3,-1);
 glVertex3f(4,3,0);
 glEnd();
 glColor3f(0,1,0);
 glBegin(GL_POLYGON);
 glVertex3f(4,2,-1);
 glVertex3f(4,2,-2);
 glVertex3f(4,3,-2);
 glVertex3f(4,3,-1);
 glEnd();
 glColor3f(0,1,0);
 glBegin(GL_POLYGON);
 glVertex3f(4,2,-2);
 glVertex3f(4,2,-3);
 glVertex3f(4,3,-3);
 glVertex3f(4,3,-2);
 glEnd();
 //lineas-----------------------------------------------------------------
 //cara frontal
//hilera 1
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,0,0);
 glVertex3f(5,0,0);
 glVertex3f(5,1,0);
 glVertex3f(4,1,0);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(5,0,0);
 glVertex3f(6,0,0);
 glVertex3f(6,1,0);
 glVertex3f(5,1,0);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(6,0,0);
 glVertex3f(7,0,0);
 glVertex3f(7,1,0);
 glVertex3f(6,1,0);
 glEnd();
//hilera2
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,1,0);
 glVertex3f(5,1,0);
 glVertex3f(5,2,0);
 glVertex3f(4,2,0);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(5,1,0);
 glVertex3f(6,1,0);
 glVertex3f(6,2,0);
 glVertex3f(5,2,0);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(6,1,0);
 glVertex3f(7,1,0);
 glVertex3f(7,2,0);
 glVertex3f(6,2,0);
 glEnd();
//hilera3
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,2,0);
 glVertex3f(5,2,0);
 glVertex3f(5,3,0);
 glVertex3f(4,3,0);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(5,2,0);
 glVertex3f(6,2,0);
 glVertex3f(6,3,0);
 glVertex3f(5,3,0);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(6,2,0);
 glVertex3f(7,2,0);
 glVertex3f(7,3,0);
 glVertex3f(6,3,0);
 glEnd();
 //cara superior
 //hilera1
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,3,0);
 glVertex3f(5,3,0);
 glVertex3f(5,3,-1);
 glVertex3f(4,3,-1);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(5,3,0);
 glVertex3f(6,3,0);
 glVertex3f(6,3,-1);
 glVertex3f(5,3,-1);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(6,3,0);
 glVertex3f(7,3,0);
 glVertex3f(7,3,-1);
 glVertex3f(6,3,-1);
 glEnd();
//hilera2
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,3,-1);
 glVertex3f(5,3,-1);
 glVertex3f(5,3,-2);
 glVertex3f(4,3,-2);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(5,3,-1);
 glVertex3f(6,3,-1);
 glVertex3f(6,3,-2);
 glVertex3f(5,3,-2);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(6,3,-1);
 glVertex3f(7,3,-1);
 glVertex3f(7,3,-2);
 glVertex3f(6,3,-2);
 glEnd();
 //hilera3
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,3,-2);
 glVertex3f(5,3,-2);
 glVertex3f(5,3,-3);
 glVertex3f(4,3,-3);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(5,3,-2);
 glVertex3f(6,3,-2);
 glVertex3f(6,3,-3);
 glVertex3f(5,3,-3);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(6,3,-2);
 glVertex3f(7,3,-2);
 glVertex3f(7,3,-3);
 glVertex3f(6,3,-3);
 glEnd();
//cara posterior
 //hilera1
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,0,-3);
 glVertex3f(5,0,-3);
 glVertex3f(5,1,-3);
 glVertex3f(4,1,-3);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(5,0,-3);
 glVertex3f(6,0,-3);
 glVertex3f(6,1,-3);
 glVertex3f(5,1,-3);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(6,0,-3);
 glVertex3f(7,0,-3);
 glVertex3f(7,1,-3);
 glVertex3f(6,1,-3);
 glEnd();
//hilera2
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,1,-3);
 glVertex3f(5,1,-3);
 glVertex3f(5,2,-3);
 glVertex3f(4,2,-3);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(5,1,-3);
 glVertex3f(6,1,-3);
 glVertex3f(6,2,-3);
 glVertex3f(5,2,-3);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(6,1,-3);
 glVertex3f(7,1,-3);
 glVertex3f(7,2,-3);
 glVertex3f(6,2,-3);
 glEnd();
//hilera3
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,2,-3);
 glVertex3f(5,2,-3);
 glVertex3f(5,3,-3);
 glVertex3f(4,3,-3);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(5,2,-3);
 glVertex3f(6,2,-3);
 glVertex3f(6,3,-3);
 glVertex3f(5,3,-3);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(6,2,-3);
 glVertex3f(7,2,-3);
 glVertex3f(7,3,-3);
 glVertex3f(6,3,-3);
 glEnd();
 //cara inferior
 //hilera1
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,0,0);
 glVertex3f(5,0,0);
 glVertex3f(5,0,-1);
 glVertex3f(4,0,-1);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(5,0,0);
 glVertex3f(6,0,0);
 glVertex3f(6,0,-1);
 glVertex3f(5,0,-1);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(6,0,0);
 glVertex3f(7,0,0);
 glVertex3f(7,0,-1);
 glVertex3f(6,0,-1);
 glEnd();
//hilera2
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,0,-1);
 glVertex3f(5,0,-1);
 glVertex3f(5,0,-2);
 glVertex3f(4,0,-2);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(5,0,-1);
 glVertex3f(6,0,-1);
 glVertex3f(6,0,-2);
 glVertex3f(5,0,-2);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(6,0,-1);
 glVertex3f(7,0,-1);
 glVertex3f(7,0,-2);
 glVertex3f(6,0,-2);
 glEnd();
 //hilera3
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,0,-2);
 glVertex3f(5,0,-2);
 glVertex3f(5,0,-3);
 glVertex3f(4,0,-3);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(5,0,-2);
 glVertex3f(6,0,-2);
 glVertex3f(6,0,-3);
 glVertex3f(5,0,-3);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(6,0,-2);
 glVertex3f(7,0,-2);
 glVertex3f(7,0,-3);
 glVertex3f(6,0,-3);
 glEnd();
 //cara derecha
//hilera 1
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(7,0,0);
 glVertex3f(7,0,-1);
 glVertex3f(7,1,-1);
 glVertex3f(7,1,0);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(7,0,-1);
 glVertex3f(7,0,-2);
 glVertex3f(7,1,-2);
 glVertex3f(7,1,-1);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(7,0,-2);
 glVertex3f(7,0,-3);
 glVertex3f(7,1,-3);
 glVertex3f(7,1,-2);
 glEnd();
//hilera2
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(7,1,0);
 glVertex3f(7,1,-1);
 glVertex3f(7,2,-1);
 glVertex3f(7,2,-0);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(7,1,-1);
 glVertex3f(7,1,-2);
 glVertex3f(7,2,-2);
 glVertex3f(7,2,-1);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(7,1,-2);
 glVertex3f(7,1,-3);
 glVertex3f(7,2,-3);
 glVertex3f(7,2,-2);
 glEnd();
//hilera3
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(7,2,0);
 glVertex3f(7,2,-1);
 glVertex3f(7,3,-1);
 glVertex3f(7,3,0);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(7,2,-1);
 glVertex3f(7,2,-2);
 glVertex3f(7,3,-2);
 glVertex3f(7,3,-1);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(7,2,-2);
 glVertex3f(7,2,-3);
 glVertex3f(7,3,-3);
 glVertex3f(7,3,-2);
 glEnd();
//cara izquierda
//hilera 1
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,0,0);
 glVertex3f(4,0,-1);
 glVertex3f(4,1,-1);
 glVertex3f(4,1,0);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,0,-1);
 glVertex3f(4,0,-2);
 glVertex3f(4,1,-2);
 glVertex3f(4,1,-1);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,0,-2);
 glVertex3f(4,0,-3);
 glVertex3f(4,1,-3);
 glVertex3f(4,1,-2);
 glEnd();
//hilera2
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,1,0);
 glVertex3f(4,1,-1);
 glVertex3f(4,2,-1);
 glVertex3f(4,2,-0);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,1,-1);
 glVertex3f(4,1,-2);
 glVertex3f(4,2,-2);
 glVertex3f(4,2,-1);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,1,-2);
 glVertex3f(4,1,-3);
 glVertex3f(4,2,-3);
 glVertex3f(4,2,-2);
 glEnd();
//hilera3
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,2,0);
 glVertex3f(4,2,-1);
 glVertex3f(4,3,-1);
 glVertex3f(4,3,0);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,2,-1);
 glVertex3f(4,2,-2);
 glVertex3f(4,3,-2);
 glVertex3f(4,3,-1);
 glEnd();
 glColor3f(0,0,0);
 glBegin(GL_LINE_LOOP);
 glVertex3f(4,2,-2);
 glVertex3f(4,2,-3);
 glVertex3f(4,3,-3);
 glVertex3f(4,3,-2);
 glEnd();


glFlush();
glutSwapBuffers();
}
void idle()
{
display();
}
void init()
{
glClearColor(0,0,0,0);
}

void handleSpecialKeypress(int key, int x, int y) {
 switch (key) {
 case GLUT_KEY_UP:
        angulo-=10.0f;
  glRotatef(angulo, 1.0f, 0.0f, 0.0f);
 
 
  break;
 case GLUT_KEY_DOWN:

        angulo+=10.0f;
  glRotatef(angulo, 1.0f, 0.0f, 0.0f);
 
  break;
  case GLUT_KEY_LEFT:
        angulo1-=10.0f;
  glRotatef(angulo1, 0.0f, 1.0f, 0.0f);
 
 
  break;
 case GLUT_KEY_RIGHT:

        angulo1+=10.0f;
  glRotatef(angulo1, 0.0f, 1.0f, 0.0f);
 
  break;
 }
}

int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowPosition(500,60);
glutInitWindowSize(600,500);
glutCreateWindow("Cubo Rubick");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
   glEnable(GL_DEPTH_TEST);
glutIdleFunc(idle);
glutSpecialFunc(handleSpecialKeypress);
glutMainLoop();

}



lunes, 14 de octubre de 2013

Disney con la pantalla tactil 3d

Las investigadores de Disney han desarrollado un algoritmo para un rendering de texturas de tres dimenciones. Alterando la friccion encontrada en las huellas de las puntas de los dedos del usuario
atraves de la superficie, el algoritmo de Disney crea una percepcion de un bulto en 3D en la superfice tactil sin tener que mover la superficie fisicamente.

"Si podemos artificialmente estirar la piel de un dedo al momento que se desliza por la pantalla tactil, el cerebro sera engañado en el pensamiento que hay un bulto fisico en la pantalla tactil a pesar de quela superficie sea completamente lisa," dice el investigador de Disney Ivan Poupyrev.


Un nuevo algoritmo permite a los
Investigadores de Disney crear un
rendering tactil de funciones y texturas 3D

Durante las pruebas, los investigadores usaron electrovibraciones para modular la friccion entre los dededos deslizandose y la superficie tactil con las fuerzas electrostaticas. Como agregado, los investigadores crearon y validaron un modelo psicofisico que casi simula las fuerzas de friccion percividas por los dedos humanos cuando se deslizan sobre un bulto real.


"Con nuestro algoritmo no tenemos uno o dos efectos, si no el grupo de controles que hacen posible activar los efectos tactiles a un artefacto visual especifico en el momento".

Los investigadores estan presentando su trabajo en el ACM Symposium en las Interfaces de Usuario de Software y Tecnologia esta semana en San Andrews, Escocia

De TG Diario

jueves, 10 de octubre de 2013

MODELADO DE COMPUTADORA (USB)

// USB.cpp: define el punto de entrada de la aplicación de consola.
//

#include "stdafx.h"
#include <stdlib.h>
#include <GL/glut.h>


GLfloat xm= 1.5f;
GLfloat escala = 1.5f;
GLfloat angulo = 0.0f;

void reshape(int width, int height)
{
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
 glOrtho(-5,20,-4,5,-5,5);
glMatrixMode(GL_MODELVIEW);

}


void display(){

glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
angulo+=0.2f;

glTranslatef(xm,0.0f,0.0f);
glScalef(escala, escala, escala);
glRotatef(angulo, 1.0f, 0.0f, 0.0f);


//CUERPO
 glColor3f(1,0,0);
 glBegin(GL_POLYGON);
 
 glVertex3f(8,0,0);
 glVertex3f(8,2.5,0);
 glVertex3f(5,2.5,0);
 glVertex3f(5,0,0);

 glEnd();

//ENTRADA
 glColor3f(0.75,0.75,0.75);
 glBegin(GL_POLYGON);
 glVertex3f(5.5,2.5,0.0);
  glVertex3f(5.5,3.5,0.0);
   glVertex3f(7.5,3.5,0.0);
    glVertex3f(7.5,2.5,0.0);
glEnd();

//CUADRO DE DATOS
 glColor3f(0,0,0);
 glBegin(GL_POLYGON);
 glVertex3f(5.65,2.75,0.1);
  glVertex3f(5.65,3.25,0.1);
   glVertex3f(6.35,3.25,0.1);
    glVertex3f(6.35,2.75,0.1);
    glEnd();
    //CUADRO DE VOLTAJE
glColor3f(0,0,0);
 glBegin(GL_POLYGON);
 glVertex3f(6.55,2.75,0.1);
  glVertex3f(6.55,3.25,0.1);
   glVertex3f(7.25,3.25,0.1);
    glVertex3f(7.25,2.75,0.1);
    glEnd();

    //FRANJA
    glColor3f(0,0,1);
 glBegin(GL_POLYGON);
 glVertex3f(7,.2,.1);
 glVertex3f(7,2.3,.1);
 glVertex3f(6,2.3,.1);
 glVertex3f(6,.2,.1);
    glEnd();

glFlush();
glutSwapBuffers();



}void idle()
{
display();
}

void init()
{
glClearColor(0,0,0,0);

}



void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
}
}
void ArrowKey(int key, int x, int y){

switch (key){
case GLUT_KEY_RIGHT:
if( xm<2.5){xm = xm + 0.2;}
if(xm>0.1 && xm<2){escala = xm;}
break;


case GLUT_KEY_LEFT:
if( xm>-2.5){xm = xm - 0.2;}
if(xm>0.1 && xm<1){escala = xm;}
break;



}
}


int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowPosition(500,60);
glutInitWindowSize(600,500);
glutCreateWindow("USB");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
   glEnable(GL_DEPTH_TEST);
glutIdleFunc(idle);
glutKeyboardFunc(keyboard);
glutSpecialFunc(ArrowKey);
glutMainLoop();


}

Aplicando las tranformaciones


Transformaciones en la piramide

Transformaciones geometricas traslacion, rotacion y escalacion en OpenGL



    *Traslación:      glTranslatef(0.0f, 0.0f, 0.0f); //glTranslatef(unidadesdetrasladoen X, traslado en Y, traslado en Z);

    *Rotación: Rota en sentido contrario a las manecillas del reloj.      glRotatef(0.0f, 0.0f, 0.0f, 0.0f); //ángulos en grados

    *Escalación: Nos permite expandir o contraer los objetos de un vértice.      glScalef(0.0f, 0.0f, 0.0f);



#include "stdafx.h"
#include <stdlib.h>
#include <GL/glut.h>

GLfloat xm=1.5f;
GLfloat escala = 1.5f;
GLfloat angulo = 0.0f;

void reshape( int width, int height)

{

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

void display()

{

glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
angulo+=0.2f;

glTranslatef(xm,0.0f,0.0f);
glScalef(escala, escala, escala);
glRotatef(angulo, 1.0f, 0.0f, 0.0f);

//cara1

glColor3f(1,0,1);
glBegin(GL_TRIANGLES);
glVertex3f(0,0,0);
glVertex3f(1.5,3,0);
glVertex3f(3,0,0);
glEnd();
//cara2
glColor3f(1,0,0);
glBegin(GL_TRIANGLES);
glVertex3f(3,0,0);
glVertex3f(1.5,3,0);
glVertex3f(1.5,0,3);
glEnd();
//cara3
glColor3f(1,1,1);
glBegin(GL_TRIANGLES);
glVertex3f(1.5,3,0);
glVertex3f(1.5,0,3);
glVertex3f(0,0,0);
glEnd();
//BASE
glColor3f(0,1,0);
glBegin(GL_TRIANGLES);
glVertex3f(0,0,0);
glVertex3f(3,0,0);
glVertex3f(1.5,0,3);
glEnd();
glFlush();
glutSwapBuffers();

}

void idle()
{
display();
}

void

init()

{

glClearColor(0,0,0,0);

}


void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
}
}
void ArrowKey(int key, int x, int y){

switch (key){
case GLUT_KEY_LEFT:
if( xm<3.0 )
{xm = xm - 0.3;}
if(xm>0.1 && xm<2)
{escala = xm;}
break;


case GLUT_KEY_RIGHT:
if( xm>-3.0 ){xm = xm + 0.3;}
if(xm>0.1 && xm<2){escala = xm;}
break;

}
}

int main (int argc, char **argv)

{

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(50,50);
glutInitWindowSize(500,500);
glutCreateWindow(
"Piramide");

init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glutKeyboardFunc(keyboard);
glutSpecialFunc(ArrowKey);
glutMainLoop();
}

Piramide 3D

#include "stdafx.h"

#include <GL/glut.h>


void reshape( int width, int height)

{

glViewport(0,0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-4,7,-6,5,-5,5);
glMatrixMode(GL_MODELVIEW);}

void

display()

{

glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();

//cara1
glColor3f(1,0,1);
glBegin(GL_POLYGON);
glVertex3f(0,0,0);
glVertex3f(1.5,3,0);
glVertex3f(3,0,0);
glEnd();

//cara2
glColor3f(1,0,0);
glBegin(GL_POLYGON);
glVertex3f(3,0,0);
glVertex3f(1.5,3,0);
glVertex3f(1.5,0,3);
glEnd();
//cara3
glColor3f(1,1,1);
glBegin(GL_POLYGON);
glVertex3f(1.5,3,0);
glVertex3f(1.5,0,3);
glVertex3f(0,0,0);
glEnd();



//base
glColor3f(0,1,0);
glBegin(GL_POLYGON);
glVertex3f(0,0,0);
glVertex3f(3,0,0);
glVertex3f(1.5,0,3);
glEnd();
glFlush();
}



void

init()

{

glClearColor(0,0,0,0);

}


int main (int argc, char **argv)

{

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(50,50);
glutInitWindowSize(500,500);
glutCreateWindow(
"Piramide");

init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;

}


Secuencia de las tranformaciones y Pilas

Secuencia de Tranformaciones:

El orden en que se aplican las transformaciones en OpenGL es al contrario de lo que parece intuitivo a primera vista. Por ejemplo:


glLoadIdentity();glTranslatef(0.5, 0.5, 1.0);
glRotatef(45.0, 1.0, 1.0, 1.0)

glBegin(GL_TRIANGLE);
glVertex3f(0.0, 0.0, 0.0);glVertex3f(1.0, 0.0, 0.0);
glVertex3f(0.0, 1.0, 0.0)
;
glEnd();

Primero carga la matriz identidad, luego multiplica por una matriz de translacion y por ultimo una de rotación. El resultado es que primero rota el triangulo y posteriormente lo traslada, esto es debido a que las multiplicaciones las realiza por el lado derecho:

La lectura se realiza de abajo arriba, hasta encontrar una funcion glLoadIdentity o glLoadMatrix. Las transformaciones que haya despues de la primitiva de dibujado glBegin - glEnd no se tienen en cuenta porque la primtiva ya ha sido renderizada.


Pila de Matrices
Una pila es un almacén con funcionamiento LIFO, el último en entrar es el primero en
salir, por lo que suele comparar a una pila de platos en la que sólo se puede dejar uno encima
de la pila o coger el superior que es el último depositado. La pila de matrices tiene el mismo
funcionamiento sustituyendo los platos por matrices. La matriz superior de la pila es sobre la
que se aplican las distintas transformaciones, multiplicándola por la matriz que generan las
disntintas funciones.
 
Para poder guardar una determinada matriz y posteriormente recuperarla OpenGL
dispone de las dos funciones comentadas: glPushMatrix() y glPopMatrix().
 
La función glPushMatrix() realiza una copia de la matriz superior y la pone encima de
la pila, de tal forma que las dos matrices superiores son iguales. Las siguientes transformaciones que se realizan se aplican sólo a la matriz superior de la pila, quedando la anterior con los valores que tenía en el momento de llamar a la función glPushMatrix().
 
La función glPopMatrix() elimina la matriz superior, quedando en la parte superior de
la pila la matriz que estaba en el momento de llamar a la función glPushMatrix().
Figura 1 PushMatrix y PopMatrix
 
En la función display() al llamar a la función glPushMatrix() se realiza una copia de la
matriz actual. La traslación en el eje Z se realiza en la matriz superior de la pila, es decir, en la
copia de la matriz, de tal forma que al llamar a la función glPopMatrix().

 Ejemplo:
glPushMatrix(); // Guardamos la transformacion del mundo
glTranslatef(cocheX, cocheY, cocheZ);
glRotatef(angulo, ejeX, ejeY, ejeZ);
RenderCarroceria();

glPushMatrix(); // Guardamos la transformacion del coche
glTranslatef(rueda1X, rueda1Y, rueda1Z);
glRotatef(anguloRueda1, eje1X, eje1Y, eje1Z);
RenderRueda();
glPopMatrix(); // Recuperamos la transformacion del coche

glPushMatrix();
glTranslatef(rueda2X, rueda2Y, rueda2Z);
glRotatef(anguloRueda2, eje2X, eje2Y, eje2Z);
RenderRueda();
glPopMatrix();

glPushMatrix();
glTranslatef(rueda3X, rueda3Y, rueda3Z);
glRotatef(anguloRueda3, eje3X, eje4Y, eje3Z);
RenderRueda();
glPopMatrix();

glPushMatrix();
glTranslatef(rueda4X, rueda4Y, rueda4Z);
glRotatef(anguloRueda4, eje4X, eje4Y, eje4Z);
RenderRueda();
glPopMatrix();

glPopMatrix(); // Recuperamos la transformacion del mundo

Resumen Capitulo 2

Tranformaciones geometricas.
Las transformaciones geométricas básicas son la traslación, la rotación y la escalación.
La traslación mueve un objeto con una trayectoria en línea recta de una posición a otra. La
rotación mueve un objeto de una posición a otra a lo largo de una trayectoria circular sobre
un eje de rotación específico.

Traslación
Se aplica una traslación en un objeto para cambiar su posición a lo largo de la
trayectoria de una línea recta de una dirección de coordenadas a otra. Convertimos un
punto bidimensional al agregar las distancias de traslación, tx y ty a la posición de
coordenadas original (x, y) para mover el punto a una nueva posición (x’, y’).

Rotación
Se aplica una rotación bidimensional en un objeto al cambiar su posición a lo largo de la
trayectoria de una circunferencia en el plano de xy. para generar una rotación,
especificamos un ángulo de rotación θ y la posición (xr, yr) del punto de rotación (o punto
pivote) en torno al cual se gira el objeto.

Escalación
Una transformación de escalación altera el tamaño de un objeto. Se puede realizar esta
operación para polígonos al multiplicar los valores de coordenadas (x, y) de cada vértice por
los factores de escalación sx y sy para producir las coordenadas transformadas (x’, y’)

Coordenadas homogéneas y representación matricial

En las aplicaciones de diseño y de creación de imágenes, realizamos traslaciones,
rotaciones y escalaciones para ajustar los componentes de la imagen en sus posiciones
apropiadas. En este tema consideramos cómo se pueden volver a formular las
representaciones de la matriz de modo que se pueden procesar de manera eficiente esas
secuencias de transformación.

Es posible expresar cada una de las transformaciones básicas en la forma de matriz
general con las posiciones de coordenadas P y P’ representadas como columnas de vector.

Representación matricial de transformaciones tridimensionales
Así como las transformaciones bidimensionales se pueden representar con matrices de
3 X 3 usando coordenadas homogéneas, las transformaciones tridimensionales se pueden
representar con matrices de 4 X 4, siempre y cuando usemos representaciones de
coordenadas homogéneas de los puntos en el espacio tridimensional.

Para encontrar la matriz de la posición transformada expresamos posiciones de
coordenadas como matrices de columna. Elegimos la representación de matriz columna para
puntos de coordenadas porque ese es el convenio matemático estándar y, muchos
paquetes gráficos siguen dicha convención.

Nos referimos a una matriz de tres o cuatro elementos (vector) como una
representación de coordenadas homogéneas. Para transformaciones geométricas, al
coeficiente homogéneo se le asigna el valor 1.

Las transformaciones compuestas se forman como multiplicación de matrices de
traslación, rotación, cambio de escala y otras transformaciones. Podemos usar
combinaciones de traslación y rotación para aplicaciones de animación y podemos usar
combinaciones de rotación y escalación para cambiar el tamaño de los objetos en cualquier
dirección especificada.