martes, 13 de noviembre de 2007

Letras Star Wars

Este es el programa que simula la presentacion de las letras tipo star wars

#include "GL/glut.h"
#include "string.h"
#include

char etiqueta[80];

static int angulo=0,angulo2=180,trasladarx=0,trasladary=0,trasladarz=0;
static float escalax=0.5,escalay=0.5,escalaz=0.5;

void Escribe (char *cadena)
{
unsigned int Nletras;
//glTranslatef(0,0,0);
glScalef(0.1,0.1,0.1);
for (Nletras=0; Nletras{
glLineWidth(1.0);
glutStrokeCharacter(GLUT_STROKE_ROMAN, cadena[Nletras]);
}
}

void texto(void)
{
char *nombre="Eduardo Ademir Hernandez Garcia";
char *numeroCuenta="301594679";

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode( GL_MODELVIEW_MATRIX );
glLoadIdentity();
glColor3f(1.0, 1.0, 1.0);
glPushMatrix();
glTranslatef(trasladarx,trasladary,trasladarz);
glScalef(escalax,escalay,escalaz);
glRotatef(angulo,0,0,1);
glRotatef(65.3,1,0,0);
glRasterPos3f(0,0,0);
Escribe(nombre);
glPopMatrix();

glPushMatrix();
glTranslatef(0,-7,0);
glTranslatef(trasladarx,trasladary,0);
glScalef(escalax,escalay,escalaz);
glRotatef(angulo,0,0,1);
glRasterPos3f(0,0,0);
Escribe(numeroCuenta);
glPopMatrix();

glPushMatrix();

glTranslatef (0.0, -2.0, -10.0);
glRotatef(-45.0, 0.0, 1.0, 0.0);
glRotatef(-45.0, 1.0, 0.0, 0.0);
glutSolidTorus (0.3, 0.8, 12, 24);
//glutSolidSphere (0.5,24,16);
//glutWireSphere(1.2,200,198);
glPopMatrix();

/* Aquí tratamos la línea leída */
//}

//glPopMatrix();
glFlush();
}

void reshape(int w, int h)
{
if (!h)
return;
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-30, 75, -30, 35, -200, 100);
//Tengo la matriz de proyección limpia, pero ahora tengo que decirle a OpenGL de que manera quiero
//que proyecte mis gráficos en la ventana que he creado. Usaremos la función glOrtho(...). Así creo el
//volumen de visualización. Todo lo que esté dentro de este volumen será proyectado de la forma más simple,
//eliminando su coordenada Z, o de profundidad. Es la llamada proyección ortográfica y no permite que se
//distinga la distancia de los objetos a la cámara
gluLookAt(5.0, 0.0, 5.0,0.0, 0.0, 0.0,0.0, 1.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void keyboard (unsigned char key, int x, int y)
{
switch (key)
{
case ' ':
angulo=angulo+45;
glutPostRedisplay();
break;
default:
break;
case 'a':
angulo=angulo-45;
glutPostRedisplay();
break;
case 27:
exit (0);
break;
case 'r':
angulo=0;
angulo2=180;
trasladarx=0;
trasladary=0;
escalax=0.5;
escalay=0.5;
escalaz=0.5;
glutPostRedisplay();
break;
case 'R':
angulo=0;
angulo2=180;
trasladarx=0;
trasladary=0;
escalax=0.5;
escalay=0.5;
escalaz=0.5;
glutPostRedisplay();
break;
case 's':
trasladarz=trasladarz+5;
trasladary=trasladary+1;
escalax=escalax/1.1;
escalay=escalay/1.1;
escalaz=escalaz/1.1;
glutPostRedisplay();
break;
}
glutSwapBuffers();
}

void buttonPress(int button,int state,int x,int y)
{
if(state == GLUT_DOWN)
{
switch(button)
{
case GLUT_LEFT_BUTTON:
escalax=escalax/2;
escalay=escalay/2;
escalaz=escalaz/2;
break;

case GLUT_RIGHT_BUTTON:
trasladarx++;
trasladary++;
break;

default:
break;
}
}
glutPostRedisplay();
glutSwapBuffers();
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(700,620);
glutInitWindowPosition(0, 0);
glutCreateWindow("Cadenas Dibujadas");

glutDisplayFunc(texto);
glutIdleFunc(keyboard);
glutKeyboardFunc ( keyboard);
glutMouseFunc ( buttonPress );
glutReshapeFunc(reshape);

glutMainLoop();
return 0;
}

martes, 6 de noviembre de 2007

Practica 8

Modificar el código de los programas

Regladas

#include "stdafx.h"
#include
#include
#include
#include "stdio.h"
#define PI 3.1415926535897932384626433
#define PUNTOS 500
#define RADIO 50.0

float verticesX[PUNTOS][2];
float verticesY[PUNTOS][2];
//***************
static int puntos = 1;
//****************

using namespace System;

void inicializa(void)
{
glClearColor(0.0,0.0,0.0,1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-50.0,50.0,-50.0,50.0);
glMatrixMode(GL_MODELVIEW);
}

void ejes()
{
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINES);
//*****************
glVertex2f(100.0, 100.0*sqrt(3.0));
glVertex2f(-100.0, -100.0*sqrt(3.0));
glVertex2f(100.0, -100.0*sqrt(3.0));
glVertex2f(-100.0, 100.0*sqrt(3.0));
glVertex2f(-100.0,0.0);
glVertex2f(100.0,0.0);
//**********************
glEnd();
}

void regladas(void)
{
int i;

for (i=0; i <= puntos; i++)
{
verticesX[i][0] = RADIO-(i*(RADIO/puntos));//reduce en X 0.1
verticesX[i][1] = -(sqrt(3.0))*(RADIO-(i*(RADIO/puntos)));
verticesY[i][0] = (RADIO-(i*(RADIO/puntos)));
verticesY[i][1] = 0;
}

glColor3f(1.0, 1.0, 0.0);


for (i=0; i < puntos; i++)
{
glBegin(GL_LINES);
//*****************
glVertex2fv(verticesX[(puntos - 1) - i]);
glVertex2fv(verticesY[i]);

glVertex2f(-(verticesX[(puntos - 1) - i][0]), verticesX[(puntos - 1) - i][1]);
glVertex2f(-verticesY[i][0],verticesY[i][1]);

glVertex2f((verticesX[(puntos - 1) - i][0]),- verticesX[(puntos - 1) - i][1]);
glVertex2f(verticesY[i][0],-(verticesY[i][1]));


glVertex2f(-(verticesX[(puntos - 1) - i][0]),- verticesX[(puntos - 1) - i][1]);
glVertex2f(-verticesY[i][0],-(verticesY[i][1]));


glVertex2f((verticesX[(puntos - 1) - i][0]),-verticesX[(puntos - 1) - i][1]);
glVertex2f(-verticesY[i][0],-(verticesY[i][1])+(sqrt(3.0))*(RADIO-(i*(RADIO/puntos))));

glVertex2f(-(verticesX[(puntos - 1) - i][0]),verticesX[(puntos - 1) - i][1]);
glVertex2f(verticesY[i][0],(verticesY[i][1])-(sqrt(3.0))*(RADIO-(i*(RADIO/puntos))));
//***********************

glEnd();

}
}

void despliega(void)
{
glClear(GL_COLOR_BUFFER_BIT);

ejes();

regladas();

glFlush();
}

void teclado(unsigned char key, int x, int y)
{
switch (key)
{
case 27:
exit (0);
break;
case 'p':
if (puntos < PUNTOS) puntos++;
glutPostRedisplay();
break;
case 'P':
if (puntos > 1) puntos--;
glutPostRedisplay();
break;
default:
break;
}
}

int main(array ^args)
{
//glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("Regladas");
glutDisplayFunc(despliega);
glutKeyboardFunc(teclado);
inicializa();
glutMainLoop();
Console::WriteLine(L"Hola a todos");
return 0;
}

////////////////////////////////MANO

/*

Programa de modelado de una mano, control de articulaciones de los dedos,
y animacion con algunos gestos.

Junio de 1999.
Santiago Igor Valiente Gomez

*/

#include
#include
#include

#define ANTEBRAZO_ALTO 8.0
#define ANTEBRAZO_ANCHO 1.0

#define PALMA_ALTO 5.0
#define PALMA_ANCHO 4.0

#define PULGAR_ALTO1F 2.0
#define PULGAR_ANCHO1F 0.5

#define MENIQUE_ALTO1F 1.5
#define MENIQUE_ALTO2F 0.5
#define MENIQUE_ALTO3F 0.5
#define MENIQUE_ANCHO1F 0.5
#define MENIQUE_ANCHO2F 0.45
#define MENIQUE_ANCHO3F 0.4

#define INDICE_ALTO1F 2.0
#define INDICE_ALTO2F 1.0
#define INDICE_ALTO3F 1.0
#define INDICE_ANCHO1F 0.5
#define INDICE_ANCHO2F 0.49
#define INDICE_ANCHO3F 0.48

#define MEDIO_ALTO1F 2.5
#define MEDIO_ALTO2F 1.0
#define MEDIO_ALTO3F 1.0
#define MEDIO_ANCHO1F 0.5
#define MEDIO_ANCHO2F 0.49
#define MEDIO_ANCHO3F 0.48

#define ANULAR_ALTO1F 2.0
#define ANULAR_ALTO2F 1.0
#define ANULAR_ALTO3F 1.0
#define ANULAR_ANCHO1F 0.5
#define ANULAR_ANCHO2F 0.49
#define ANULAR_ANCHO3F 0.48

#define PALMA_VOLUMEN 1.0

typedef float point[3];

static GLfloat theta[14] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};

static GLfloat theta_prueba[14] = {10.0, 25.0, 15.0, //rota muñeca,rota codo,rota no se (= r muñeca)
-10.0, //inclina palma (adelante,atras)
90.0, 90.0, //mueve pulgar, mueve 2a falange
0.0, 20.0, //mueve indice,mueve 2a falange
0.0, 20.0, //mueve dedo grosero 1a falange (adelante y atrás), mueve 2a falange
90.0, 90.0, //mueve anular 1a falange (adelante y atrás), mueve 2a falange
90.0, 90.0}; //mueve chiquito medallas, mueve 2a falange

static GLfloat theta_metal[14] = {10.0, 25.0, 15.0, //rota muñeca,rota codo,rota no se (= r muñeca)
-10.0, //inclina palma (adelante,atras)
0.0, 0.0, //mueve pulgar, mueve 2a falange
0.0, 0.0, //mueve indice,mueve 2a falange
90.0, 90.0, //mueve dedo grosero 1a falange (adelante y atrás), mueve 2a falange
90.0, 90.0, //mueve anular 1a falange (adelante y atrás), mueve 2a falange
0.0, 0.0}; //mueve chiquito medallas, mueve 2a falange



static GLfloat theta_aventon[14] = {-90.0, -35.0, 70.0, 0.0, 0.0, 0.0, 135.0, 20.0, 145.0, 20.0, 145.0, 20.0, 145.0, 20.0};
static GLfloat theta_uno[14] = { 30.0, 15.0, 0.0, -15.0, 80.0, 80.0, 0.0, 0.0, 145.0, 20.0, 145.0, 20.0, 145.0, 20.0};
static GLfloat theta_cuernos[14] = {135.0, 15.0,-10.0, 45.0, 80.0, 80.0, 0.0, 20.0, 145.0, 20.0, 145.0, 20.0, 0.0, 20.0};

static GLint angle = 0;
static GLint direccion = 1;

GLUquadricObj *ab, *p1f, *p2f,*m1f, *m2f, *m3f, *i1f,*i2f, *i3f, *a1f, *a2f, *a3f, *md1f,*md2f, *md3f;

double size=1.0;

void antebrazo()
{
glPushMatrix();
glRotatef(-90.0,1.0,0.0,0.0);
gluCylinder(ab,ANTEBRAZO_ANCHO,ANTEBRAZO_ANCHO,ANTEBRAZO_ALTO,10,10);
glPopMatrix();
}

void palma()
{
glPushMatrix();
glTranslatef(0.0,PALMA_ALTO/2,0.0);
glScalef(PALMA_ANCHO,PALMA_ALTO,PALMA_VOLUMEN);
glutSolidCube(1.0);
glPopMatrix();
}

void pulgar1f()
{
glPushMatrix();
glRotatef(-80.0,1.0,1.0,0.0);
gluCylinder(p1f,PULGAR_ANCHO1F,PULGAR_ANCHO1F,PULGAR_ALTO1F,10,10);
glPopMatrix();
}

void pulgar2f()
{
glPushMatrix();
glRotatef(-90.1,0.0,1.0,0.0);
gluCylinder(p2f,PULGAR_ANCHO1F,PULGAR_ANCHO1F,PULGAR_ALTO1F,10,10);
glPopMatrix();
}

void menique1f()
{
glPushMatrix();
glRotatef(-90.0,1.0,0.0,0.0);
gluCylinder(m1f,MENIQUE_ANCHO1F,MENIQUE_ANCHO1F,MENIQUE_ALTO1F,10,10);
glPopMatrix();
}

void menique2f()
{
glPushMatrix();
glRotatef(-90.0,1.0,0.0,0.0);
gluCylinder(m2f,MENIQUE_ANCHO2F,MENIQUE_ANCHO2F,MENIQUE_ALTO2F,10,10);
glPopMatrix();
}

void menique3f()
{
glPushMatrix();
glRotatef(-90.0,1.0,0.0,0.0);
gluCylinder(m3f,MENIQUE_ANCHO3F,MENIQUE_ANCHO3F,MENIQUE_ALTO3F,10,10);
glPopMatrix();
}

void indice1f()
{
glPushMatrix();
glRotatef(-90.0,1.0,0.0,0.0);
gluCylinder(i1f,INDICE_ANCHO1F,INDICE_ANCHO1F,INDICE_ALTO1F,10,10);
glPopMatrix();
}

void indice2f()
{
glPushMatrix();
glRotatef(-90.0,1.0,0.0,0.0);
gluCylinder(i2f,INDICE_ANCHO2F,INDICE_ANCHO2F,INDICE_ALTO2F,10,10);
glPopMatrix();
}

void indice3f()
{
glPushMatrix();
glRotatef(-90.0,1.0,0.0,0.0);
gluCylinder(i3f,INDICE_ANCHO3F,INDICE_ANCHO3F,INDICE_ALTO3F,10,10);
glPopMatrix();
}


void medio1f()
{
glPushMatrix();
glRotatef(-90.0,1.0,0.0,0.0);
gluCylinder(md1f,MEDIO_ANCHO1F,MEDIO_ANCHO1F,MEDIO_ALTO1F,10,10);
glPopMatrix();
}

void medio2f()
{
glPushMatrix();
glRotatef(-90.0,1.0,0.0,0.0);
gluCylinder(md2f,MEDIO_ANCHO2F,MEDIO_ANCHO2F,MEDIO_ALTO2F,10,10);
glPopMatrix();
}

void medio3f()
{
glPushMatrix();
glRotatef(-90.0,1.0,0.0,0.0);
gluCylinder(md3f,MEDIO_ANCHO3F,MEDIO_ANCHO3F,MEDIO_ALTO3F,10,10);
glPopMatrix();
}

void anular1f()
{
glPushMatrix();
glRotatef(-90.0,1.0,0.0,0.0);
gluCylinder(a1f,ANULAR_ANCHO1F,ANULAR_ANCHO1F,ANULAR_ALTO1F,10,10);
glPopMatrix();
}

void anular2f()
{
glPushMatrix();
glRotatef(-90.0,1.0,0.0,0.0);
gluCylinder(a2f,ANULAR_ANCHO2F,ANULAR_ANCHO2F,ANULAR_ALTO2F,10,10);
glPopMatrix();
}

void anular3f()
{
glPushMatrix();
glRotatef(-90.0,1.0,0.0,0.0);
gluCylinder(a3f,ANULAR_ANCHO3F,ANULAR_ANCHO3F,ANULAR_ALTO3F,10,10);
glPopMatrix();
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glColor3f(1.0,0.0,0.0);
glTranslatef(-4.5, -ANTEBRAZO_ALTO,0.0);
glRotatef(theta[0],0.0,1.0,0.0);
glRotatef(theta[1],1.0,0.0,0.0);
antebrazo();
glTranslatef(0.0, ANTEBRAZO_ALTO,0.0);
glPushMatrix();
glRotatef(theta[2],0.0,1.0,0.0);
glRotatef(theta[3],1.0,0.0,0.0);
palma();
glPushMatrix();
glTranslatef(-PULGAR_ALTO1F/2-0.5,PULGAR_ALTO1F/2+1,0.0);
glRotatef(theta[4],0.0,1.0,0.0);
glTranslatef(0.0,-PULGAR_ALTO1F/2,0.0);
pulgar1f();
glTranslatef(-PULGAR_ALTO1F/2-0.5,PULGAR_ALTO1F+0.5,0.0);
glRotatef(theta[5],0.0,1.0,0.0);
glTranslatef(0.0,-PULGAR_ALTO1F/2,0.0);
pulgar2f();
glPopMatrix();
glPushMatrix();
glTranslatef(-PALMA_ANCHO/2+0.5, PALMA_ALTO,0.0);
glRotatef(theta[6],1.0,0.0,0.0);
indice1f();
glTranslatef(0.0,INDICE_ALTO1F,0.0);
glRotatef(theta[7],1.0,0.0,0.0);
indice2f();
glTranslatef(0.0,INDICE_ALTO2F,0.0);
glRotatef(theta[7],1.0,0.0,0.0);
indice3f();
glPopMatrix();
glPushMatrix();
glTranslatef(-PALMA_ANCHO/2+1.5,PALMA_ALTO,0.0);
glRotatef(theta[8],1.0,0.0,0.0);
medio1f();
glTranslatef(0.0,MEDIO_ALTO1F,0.0);
glRotatef(theta[9],1.0,0.0,0.0);
medio2f();
glTranslatef(0.0,MEDIO_ALTO2F,0.0);
glRotatef(theta[9],1.0,0.0,0.0);
medio3f();
glPopMatrix();
glPushMatrix();
glTranslatef(PALMA_ANCHO/2-1.5,PALMA_ALTO,0.0);
glRotatef(theta[10],1.0,0.0,0.0);
anular1f();
glTranslatef(0.0,ANULAR_ALTO1F,0.0);
glRotatef(theta[11],1.0,0.0,0.0);
anular2f();
glTranslatef(0.0,ANULAR_ALTO2F,0.0);
glRotatef(theta[11],1.0,0.0,0.0);
anular3f();
glPopMatrix();
glPushMatrix();
glTranslatef(PALMA_ANCHO/2-0.5,PALMA_ALTO,0.0);
glRotatef(theta[12],1.0,0.0,0.0);
menique1f();
glTranslatef(0.0,MENIQUE_ALTO1F,0.0);
glRotatef(theta[13],1.0,0.0,0.0);
menique2f();
glTranslatef(0.0,MENIQUE_ALTO2F,0.0);
glRotatef(theta[13],1.0,0.0,0.0);
menique3f();
glPopMatrix();
glPopMatrix();
glFlush();
glutSwapBuffers();
}

void mouse(int btn, int state, int x, int y)
{
GLfloat mintope;
if(btn==GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
if (angle <=3 ) mintope = -180.0;
else mintope = 0.0;
// switch (direccion) {
// case 1:
theta[angle]+=5.0;
if( theta[angle] > 150.0) theta[angle] = 150.0;
// break;
// case 0:
// theta[angle] -= 5.0;
// if( theta[angle]// break;
// }
display();
}
// if(btn==GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
// {
// if (angle <=3 ) mintope = -180.0;
// else mintope = 0.0;
// switch (direccion) {
// case 1:
// theta[angle]+=5.0;
// if( theta[angle] > 150.0) theta[angle] = 150.0;
// break;
// case 0:
// theta[angle] -= 5.0;
// if( theta[angle]// break;
// }
display();
// }

}

void animacion_uno(void)
{
int i,j;
int mueve=1;
do
{
for(i = 0; i <=13 ; i++)
{
if (theta[i]!=theta_uno[i])
{
if (theta[i] {
if((((int)(theta_uno[i]-theta[i]))%5)==0)
theta[i]+=5.0;
else
theta[i]+=(GLfloat)(((int)(theta_uno[i]-theta[i]))%5);
}
else
{
if((((int)(theta[i]-theta_uno[i]))%5)==0)
theta[i]-=5.0;
else
theta[i]-=(GLfloat)(((int)(theta[i]-theta_uno[i]))%5);
}
}
}
j=13;
for(i = 0; i <=13 ; i++)
{
if(theta[i]==theta_uno[i]) j--;
}
if (j<=0) mueve=0;
display();
}
while(mueve);
}

void animacion_cuernos(void)
{
int i,j;
int mueve=1;
do
{
for(i = 0; i <=13 ; i++)
{
if (theta[i]!=theta_cuernos[i])
{
if (theta[i] {
if((((int)(theta_cuernos[i]-theta[i]))%5)==0)
theta[i]+=5.0;
else
theta[i]+=(GLfloat)(((int)(theta_cuernos[i]-theta[i]))%5);
}
else
{
if((((int)(theta[i]-theta_cuernos[i]))%5)==0)
theta[i]-=5.0;
else
theta[i]-=(GLfloat)(((int)(theta[i]-theta_cuernos[i]))%5);
}
}
}
j=13;
for(i = 0; i <=13 ; i++)
{
if(theta[i]==theta_cuernos[i]) j--;
}
if (j<=0) mueve=0;
display();
}
while(mueve);
}

void animacion_metal(void)
{
int i,j;
int mueve=1;

do
{
for(i = 0; i <=13 ; i++)
{
if (theta[i]!=theta_metal[i])
{
if (theta[i] {
if((((int)(theta_metal[i]-theta[i]))%5)==0)
theta[i]+=5.0;
else
theta[i]+=(GLfloat)(((int)(theta_metal[i]-theta[i]))%5);
}
else
{
if((((int)(theta[i]-theta_metal[i]))%5)==0)
theta[i]-=5.0;
else
theta[i]-=(GLfloat)(((int)(theta[i]-theta_metal[i]))%5);
}
}
}
j=13;
for(i = 0; i <=13 ; i++)
{
if(theta[i]==theta_metal[i]) j--;
}
if (j<=0) mueve=0;
display();
}
while(mueve);
}

void animacion_metalAbajo(void)
{
int i,j,palma;
static GLfloat theta_metalAbajo[14] = {10.0, 25.0, 15.0, //rota muñeca,rota codo,rota no se (= r muñeca)
200, //inclina palma (adelante,atras)
0.0, 0.0, //mueve pulgar, mueve 2a falange
0.0, 0.0, //mueve indice,mueve 2a falange
90.0, 90.0, //mueve dedo grosero 1a falange (adelante y atrás), mueve 2a falange
90.0, 90.0, //mueve anular 1a falange (adelante y atrás), mueve 2a falange
0.0, 0.0}; //mueve chiquito medallas, mueve 2a falange

int mueve=1;

do
{
for(i = 0; i <=13 ; i++)
{
if (theta[i]!=theta_metalAbajo[i])
{
if (theta[i] {
if((((int)(theta_metalAbajo[i]-theta[i]))%5)==0)
theta[i]+=5.0;
else
theta[i]+=(GLfloat)(((int)(theta_metalAbajo[i]-theta[i]))%5);
}
else
{
if((((int)(theta[i]-theta_metalAbajo[i]))%5)==0)
theta[i]-=5.0;
else
theta[i]-=(GLfloat)(((int)(theta[i]-theta_metalAbajo[i]))%5);
}
}
}
j=13;
for(i = 0; i <=13 ; i++)
{
if(theta[i]==theta_metalAbajo[i]) j--;
}
if (j<=0) mueve=0;
display();
}
while(mueve);
}

void animacion_aventon(void)
{
int i,j;
int mueve=1;
do
{
for(i = 0; i <=13 ; i++)
{
if (theta[i]!=theta_aventon[i])
{
if (theta[i] {
if((((int)(theta_aventon[i]-theta[i]))%5)==0)
theta[i]+=5.0;
else
theta[i]+=(GLfloat)(((int)(theta_aventon[i]-theta[i]))%5);
}
else
{
if((((int)(theta[i]-theta_aventon[i]))%5)==0)
theta[i]-=5.0;
else
theta[i]-=(GLfloat)(((int)(theta[i]-theta_aventon[i]))%5);
}
}
}
j=13;
for(i = 0; i <=13 ; i++)
{
if(theta[i]==theta_aventon[i]) j--;
}
if (j<=0) mueve=0;
display();
}
while(mueve);
}

void animacion_prueba(void)
{
int i,j;
int mueve=1;
do
{
for(i = 0; i <=13 ; i++)
{
if (theta[i]!=theta_prueba[i])
{
if (theta[i] {
if((((int)(theta_prueba[i]-theta[i]))%5)==0)
theta[i]+=5.0;
else
theta[i]+=(GLfloat)(((int)(theta_prueba[i]-theta[i]))%5);
}
else
{
if((((int)(theta[i]-theta_prueba[i]))%5)==0)
theta[i]-=5.0;
else
theta[i]-=(GLfloat)(((int)(theta[i]-theta_prueba[i]))%5);
}
}
}
j=13;
for(i = 0; i <=13 ; i++)
{
if(theta[i]==theta_prueba[i]) j--;
}
if (j<=0) mueve=0;
display();
}
while(mueve);
}

void animacion_restituye(void)
{
int i,j;
int mueve=1;
do
{
for(i = 0; i <=13 ; i++)
{
if (theta[i]!=0.0)
{
if (theta[i]<0.0)
{
if(((int)theta[i]%5)==0)
theta[i]+=5.0;
else
theta[i]+=(GLfloat)(((int)theta[i])%5);
}
else
{
if(((int)theta[i]%5)==0)
theta[i]-=5.0;
else
theta[i]-=(GLfloat)(((int)theta[i])%5);
}
}
}
j=13;
for(i = 0; i <=13 ; i++)
{
if(theta[i]==0.0) j--;
}
if (j<=0) mueve=0;
display();
}
while(mueve);
}

void menu(int id)
{
int i;
if(id <= 1) direccion = id;
else if(id <= 13 ) angle=id-2;
else if(id <= 18 )
{
switch (id)
{
case 16:
animacion_aventon();
break;
case 17:
animacion_uno();
break;
case 18:
printf("id = %d",id);
animacion_cuernos();
break;
case 15:
animacion_prueba();
break;
case 14:
for(i=0;i<6;i++)
{
animacion_metal();
Sleep(500);
animacion_metalAbajo();
}
break;
}
display();
}
else if(id == 19) exit(0);
else if(id == 20) animacion_restituye();
}

void myReshape(int w, int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w<=h)
glOrtho(-10.0,10.0,-10.0 * (GLfloat) h / (GLfloat) w,10.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0);
else
glOrtho(-10.0 * (GLfloat) w / (GLfloat) h,10.0 * (GLfloat) w / (GLfloat) h, 0.0, 10.0, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void myinit()
{
GLfloat mat_specular[] ={1.0,1.0,1.0,1.0};
GLfloat mat_diffuse[] ={1.0,1.0,1.0,1.0};
GLfloat mat_ambient[] ={1.0,1.0,1.0,1.0};
GLfloat mat_shininess[] ={100.0};
GLfloat light_ambient[] ={0.0,0.0,0.0,1.0};
GLfloat light_diffuse[] ={1.0,0.0,0.0,1.0};
GLfloat light_specular[]={1.0,1.0,1.0,1.0};
GLfloat light_position[]={10.0,10.0,10.0,0.0};
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glEnable(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(1.0,0.0,0.0);
ab=gluNewQuadric();
gluQuadricDrawStyle(ab,GLU_FILL);
p1f=gluNewQuadric();
gluQuadricDrawStyle(p1f,GLU_FILL);
p2f=gluNewQuadric();
gluQuadricDrawStyle(p2f,GLU_FILL);
m1f=gluNewQuadric();
gluQuadricDrawStyle(m1f,GLU_FILL);
m2f=gluNewQuadric();
gluQuadricDrawStyle(m2f,GLU_FILL);
m3f=gluNewQuadric();
gluQuadricDrawStyle(m3f,GLU_FILL);
i1f=gluNewQuadric();
gluQuadricDrawStyle(i1f,GLU_FILL);
i2f=gluNewQuadric();
gluQuadricDrawStyle(i2f,GLU_FILL);
i3f=gluNewQuadric();
gluQuadricDrawStyle(i3f,GLU_FILL);
md1f=gluNewQuadric();
gluQuadricDrawStyle(md1f,GLU_FILL);
md2f=gluNewQuadric();
gluQuadricDrawStyle(md2f,GLU_FILL);
md3f=gluNewQuadric();
gluQuadricDrawStyle(md3f,GLU_FILL);
a1f=gluNewQuadric();
gluQuadricDrawStyle(a1f,GLU_FILL);
a2f=gluNewQuadric();
gluQuadricDrawStyle(a2f,GLU_FILL);
a3f=gluNewQuadric();
gluQuadricDrawStyle(a3f,GLU_FILL);
}

void main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("Mano");
myinit();
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutCreateMenu(menu);
glutAddMenuEntry("",1);
glutAddMenuEntry("",0);
glutAddMenuEntry("Girar Brazo",2);
glutAddMenuEntry("Doblar Brazo",3);
glutAddMenuEntry("Girar Palma",4);
glutAddMenuEntry("Doblar Palma",5);
glutAddMenuEntry("Pulgar 1ª falange",6);
glutAddMenuEntry("Pulgar 2ª falange",7);
glutAddMenuEntry("Indice 1ª falange",8);
glutAddMenuEntry("Indice 2ª y 3ª falanges",9);
glutAddMenuEntry("Medio 1ª falange",10);
glutAddMenuEntry("Medio 2ª y 3ª falanges",11);
glutAddMenuEntry("Anular 1ª falange",12);
glutAddMenuEntry("Anular 2ª y 3ª falanges",13);
//glutAddMenuEntry("Meñique 1ª falange",14);
//glutAddMenuEntry("Meñique 2ª y 3ª falanges",15);
glutAddMenuEntry("Gestos - AVENTON",16);
glutAddMenuEntry("Gestos - UNO",17);
glutAddMenuEntry("Gestos - CUERNOS",18);
glutAddMenuEntry("V de Victoria",15);
glutAddMenuEntry("Metal",14);
glutAddMenuEntry("RESTITUIR",20);
glutAddMenuEntry("",19);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop();
}

//////ESCENA 11 DE SEPTIEMBRE

/*
Programa en donde se representa la escena previamente programada en C.
La escena se puede explorar usando las teclas x,X,y,Y,z,Z, las cuales
cambian las coordenadas de la camara que siempre va a estar apuntando al origen
del sistema de coordenadas.
El uso de las teclas i,I,j,J,k,K y los botones del mouse permiten rotar la escena
sobre sus tres ejes.

Junio de 1999.

Santiago Igor Valiente Gomez
*/

#include
#include

typedef GLint linea[2];

static GLfloat theta[]={0.0,0.0,0.0};
static GLint eje=2;
static GLdouble camara[]={0.0,25.0,120.0};

GLfloat vertices_edificio[8][3]={
{ 0, 0, 0},{ 0, 0, 10},{10, 0, 10},{10, 0, 0},{ 0, 50, 0},
{ 0, 50, 10},{10, 50, 10},{10, 50, 0}};

GLfloat vertices_calle[12][3]={
{ 500, 0, 10},{ 10, 0, 10},{ 10, 0, 500},{ -10, 0, 500},{ -10, 0, 10},
{-500, 0, 10},{ 500, 0, -10},{ 10, 0, -10},{ 10, 0,-500},{ -10, 0,-500},
{ -10, 0, -10},{-500, 0, -10}};

GLfloat vertices_avion[37][3]={
{ 0, 0, 0},{ 0, 0, 0},{ -2, 1, 7},{ -2, 1, 15},{ 2, 1, 15},
{ 2, 1, 7},{ -2, -1, 7},{ -2, -1, 15},{ 2, -1, 15},{ 2, -1, 7},
{ -2, 0, 9},{ -5, 0, 9},{ -5, 0, 13},{ -2, 0, 13},{ 2, 0, 9},
{ 5, 0, 9},{ 5, 0, 13},{ 2, 0, 13},{ -5, 0.5, 8},{ -6, 0.5, 8},
{ -6, 0.5, 14},{ -5, 0.5, 14},{ -5, -0.5, 8},{ -6, -0.5, 8},{ -6, -0.5, 14},
{ -5, -0.5, 14},{ 5, 0.5, 8},{ 6, 0.5, 8},{ 6, 0.5, 14},{ 5, 0.5, 14},
{ 5, -0.5, 8},{ 6, -0.5, 8},{ 6, -0.5, 14},{ 5, -0.5, 14},{ 0, 1, 9},
{ 0, 3, 13},{ 0, 1, 13}};

GLuint lineas_edificio[24]={
0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7};

GLuint lineas_avion[90]={
1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 6, 6, 7, 7, 8, 8, 9, 9, 1,
2, 6, 3, 7, 4, 8, 5, 9,10,11,12,13,14,15,16,17,18,19,19,20,
20,21,21,18,22,23,23,24,24,25,25,22,18,22,19,23,20,24,21,25,
26,27,27,28,28,29,29,26,30,31,31,32,32,33,33,30,26,30,27,31,
28,32,29,33,34,35,35,36,36,34};

GLuint lineas_calle[16]={
0, 1, 1, 2, 3, 4, 4, 5,11,10,10, 9, 8, 7, 7, 6};


void dibuja (float colorRojo,float colorVerde,float colorAzul,int tamArre,GLuint lineas[],GLfloat vertices[][3])
{
int i,m,n;
glColor3f(colorRojo,colorVerde,colorAzul);
glBegin(GL_LINES);
for (i=1;i {
m=lineas[i-1];
n=lineas[i];
glVertex3fv(vertices[m]);
glVertex3fv(vertices[n]);
}
glEnd();
}

void dibuja_edificio(void)
{
dibuja(1.0,0.0,0.0,24,lineas_edificio,vertices_edificio);
}

void dibuja_calle(void)
{
dibuja(1.0,0.0,1.0,16,lineas_calle,vertices_calle);
}

void dibuja_avion(void)
{
dibuja(1.0,1.0,0.0,90,lineas_avion,vertices_avion);
}

void inicializa(void)
{
glClearColor(0.0,0.0,0.0,0.0);
}

void despliega(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glLoadIdentity();
gluLookAt(camara[0],camara[1],camara[2],0.0,0.0,0.0,0.0,1.0,0.0);
glRotatef(theta[0],1.0,0.0,0.0);
glRotatef(theta[1],0.0,1.0,0.0);
glRotatef(theta[2],0.0,0.0,1.0);
dibuja_calle();
glPushMatrix();
glTranslatef(10.0,0.0,10.0);
dibuja_edificio();
glPopMatrix();
glPushMatrix();
glTranslatef(10.0,0.0,-20.0);
dibuja_edificio();
glPopMatrix();
glPushMatrix();
glTranslatef(-20.0,0.0,-20.0);
dibuja_edificio();
glPopMatrix();
glPushMatrix();
glTranslatef(-20.0,0.0,10.0);
dibuja_edificio();
glPopMatrix();
dibuja_calle();
glPushMatrix();
glTranslatef(0.0,15.0,50.0);
dibuja_avion();
glPopMatrix();
glFlush();
glutSwapBuffers();
}


void mouse(int btn, int state, int x, int y)
{
if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN) eje=0;
if(btn==GLUT_MIDDLE_BUTTON && state==GLUT_DOWN) eje=1;
if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN) eje=2;
theta[eje]+=2.0;
if(theta[eje] > 360.0) theta[eje]-=360.0;
glutPostRedisplay();
}

void teclas(unsigned char tecla, int x, int y)
{
if(tecla=='x') camara[0]-= 1.0;
if(tecla=='X') camara[0]+= 1.0;
if(tecla=='y') camara[1]-= 1.0;
if(tecla=='Y') camara[1]+= 1.0;
if(tecla=='z') camara[2]-= 1.0;
if(tecla=='Z') camara[2]+= 1.0;
if(tecla=='i')
{
eje=0;
theta[eje]+=2.0;
if(theta[eje] > 360.0) theta[eje]-=360.0;
}
if(tecla=='I')
{
eje=0;
theta[eje]-=2.0;
if(theta[eje] < 360.0) theta[eje]+=360.0;
}
if(tecla=='j')
{
eje=1;
theta[eje]+=2.0;
if(theta[eje] > 360.0) theta[eje]-=360.0;
}
if(tecla=='J')
{
eje=1;
theta[eje]-=2.0;
if(theta[eje] < 360.0) theta[eje]+=360.0;
}
if(tecla=='k')
{
eje=2;
theta[eje]+=2.0;
if(theta[eje] > 360.0) theta[eje]-=360.0;
}
if(tecla=='K')
{
eje=2;
theta[eje]-=2.0;
if(theta[eje] < 360.0) theta[eje]+=360.0;
}
if(tecla=='r'||tecla=='R')
{
camara[0]=0.0;
camara[1]=25.0;
camara[2]=120.0;
theta[0]=0.0;
theta[1]=0.0;
theta[2]=0.0;
}
glutPostRedisplay();
}

void reshape(int w, int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w<=h) glFrustum(-2.0,2.0,-2.0*(GLfloat)h/(GLfloat)w,2.0*(GLfloat)h/(GLfloat)w,1.0,200.0);
else
glFrustum(-2.0,2.0,-2.0*(GLfloat)w/(GLfloat)h,2.0*(GLfloat)w/(GLfloat)h,1.0,200.0);
glMatrixMode(GL_MODELVIEW);
}

void main(int argc, char** argv)
{
inicializa();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("Escena");
glutReshapeFunc(reshape);
glutDisplayFunc(despliega);
glutMouseFunc(mouse);
glutKeyboardFunc(teclas);
glEnable(GL_DEPTH_TEST);
glutMainLoop();
}

/////////////SOLIDO DE REVOLUCION

# include
# include
# include
# include

# define PI 3.1415926535

GLfloat ctlpoints[8][3];
GLfloat cpoints1[8][8][3];
GLfloat cpoints2[8][8][3];
GLfloat cpoints3[8][8][3];
GLfloat cpoints4[8][8][3];
GLfloat cpoints5[8][8][3];
GLfloat cpoints6[8][8][3];
GLfloat cpoints7[8][8][3];
GLfloat cpoints8[8][8][3];
GLfloat eje_rotacion[2][3]={{0.0,-10.0,0.0},{0.0,10.0,0.0}};
GLfloat *line=&ctlpoints[0][0];
GLuint selectedPoint = ~0;
GLuint selectBuffer[64];
GLdouble modelMatrix[16], projMatrix[16];
GLint viewport[4];
GLfloat modo=GLU_OUTLINE_POLYGON;

GLfloat luz_ambiental[4]={1.0,1.0,1.0,1.0};

//*******************
GLfloat points[80];
//***************

int showPoints=0;
int superficie=0;
int winWidth, winHeight;
int uSize = 8;
int vSize = 3;

static int angx=0;
static int angy=0;
static int angz=0;
static GLfloat x=0.0;
static GLfloat y=0.0;
static GLfloat z=0.0;
static float ang=0.0;

GLUnurbsObj *theNurb;

GLUnurbsObj *octante1;
GLUnurbsObj *octante2;
GLUnurbsObj *octante3;
GLUnurbsObj *octante4;
GLUnurbsObj *octante5;
GLUnurbsObj *octante6;
GLUnurbsObj *octante7;
GLUnurbsObj *octante8;

void init_curve(void)
{
int u;
for (u=0;u {
ctlpoints[u][0] = 2.0*((GLfloat)u - 3.0);
ctlpoints[u][1] = 2.0*((GLfloat)u - 3.0);
ctlpoints[u][2] = 0.0;
}
}

void init_solid(void)
{
int i,j,k;
for(k=0;k<8;k++)
{
for(i=0;i<8;i++)
{
for(j=7;j>=0;j--)
{
if(k==0)
{
cpoints1[i][7-j][0]=ctlpoints[j][0]*cos((i*6.43)*PI/180.0) - ctlpoints[j][2]*sin((i*6.43)*PI/180.0);
cpoints1[i][7-j][1]=ctlpoints[j][1];
cpoints1[i][7-j][2]=ctlpoints[j][0]*sin((i*6.43)*PI/180.0) + ctlpoints[j][2]*cos((i*6.43)*PI/180.0);
}
if(k==1)
{
cpoints2[i][7-j][0]=ctlpoints[j][0]*cos((i*6.43+45.0)*PI/180.0) - ctlpoints[j][2]*sin((i*6.43+45.0)*PI/180.0);
cpoints2[i][7-j][1]=ctlpoints[j][1];
cpoints2[i][7-j][2]=ctlpoints[j][0]*sin((i*6.43+45.0)*PI/180.0) + ctlpoints[j][2]*cos((i*6.43+45.0)*PI/180.0);
}
if(k==2)
{
cpoints3[i][7-j][0]=ctlpoints[j][0]*cos((i*6.43+90.0)*PI/180.0) - ctlpoints[j][2]*sin((i*6.43+90.0)*PI/180.0);
cpoints3[i][7-j][1]=ctlpoints[j][1];
cpoints3[i][7-j][2]=ctlpoints[j][0]*sin((i*6.43+90.0)*PI/180.0) + ctlpoints[j][2]*cos((i*6.43+90.0)*PI/180.0);
}
if(k==3)
{
cpoints4[i][7-j][0]=ctlpoints[j][0]*cos((i*6.43+135.0)*PI/180.0) - ctlpoints[j][2]*sin((i*6.43+135.0)*PI/180.0);
cpoints4[i][7-j][1]=ctlpoints[j][1];
cpoints4[i][7-j][2]=ctlpoints[j][0]*sin((i*6.43+135.0)*PI/180.0) + ctlpoints[j][2]*cos((i*6.43+135.0)*PI/180.0);
}
if(k==4)
{
cpoints5[i][7-j][0]=ctlpoints[j][0]*cos((i*6.43+180.0)*PI/180.0) - ctlpoints[j][2]*sin((i*6.43+180.0)*PI/180.0);
cpoints5[i][7-j][1]=ctlpoints[j][1];
cpoints5[i][7-j][2]=ctlpoints[j][0]*sin((i*6.43+180.0)*PI/180.0) + ctlpoints[j][2]*cos((i*6.43+180.0)*PI/180.0);
}
if(k==5)
{
cpoints6[i][7-j][0]=ctlpoints[j][0]*cos((i*6.43+225.0)*PI/180.0) - ctlpoints[j][2]*sin((i*6.43+225.0)*PI/180.0);
cpoints6[i][7-j][1]=ctlpoints[j][1];
cpoints6[i][7-j][2]=ctlpoints[j][0]*sin((i*6.43+225.0)*PI/180.0) + ctlpoints[j][2]*cos((i*6.43+225.0)*PI/180.0);
}
if(k==6)
{
cpoints7[i][7-j][0]=ctlpoints[j][0]*cos((i*6.43+270.0)*PI/180.0) - ctlpoints[j][2]*sin((i*6.43+270.0)*PI/180.0);
cpoints7[i][7-j][1]=ctlpoints[j][1];
cpoints7[i][7-j][2]=ctlpoints[j][0]*sin((i*6.43+270.0)*PI/180.0) + ctlpoints[j][2]*cos((i*6.43+270.0)*PI/180.0);
}
if(k==7)
{
cpoints8[i][7-j][0]=ctlpoints[j][0]*cos((i*6.43+315.0)*PI/180.0) - ctlpoints[j][2]*sin((i*6.43+315.0)*PI/180.0);
cpoints8[i][7-j][1]=ctlpoints[j][1];
cpoints8[i][7-j][2]=ctlpoints[j][0]*sin((i*6.43+315.0)*PI/180.0) + ctlpoints[j][2]*cos((i*6.43+315.0)*PI/180.0);
}
}
}
}
}

void init(void)
{
GLfloat mat_diffuse[] = {0.7,1.0,0.7,1.0};
GLfloat mat_specular[] = {1.0,1.0,1.0,1.0};
GLfloat mat_shininess[] = {100.0};
glClearColor(0.0,0.0,0.0,0.0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0,GL_AMBIENT,luz_ambiental);
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
glEnable (GL_DEPTH_TEST);
glEnable (GL_AUTO_NORMAL);
glEnable (GL_NORMALIZE);
init_curve();
theNurb=gluNewNurbsRenderer();
gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0);
gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_OUTLINE_POLYGON);
octante1=gluNewNurbsRenderer();
gluNurbsProperty(octante1, GLU_SAMPLING_TOLERANCE, 25.0);
gluNurbsProperty(octante1, GLU_DISPLAY_MODE, modo);
octante2=gluNewNurbsRenderer();
gluNurbsProperty(octante2, GLU_SAMPLING_TOLERANCE, 25.0);
gluNurbsProperty(octante2, GLU_DISPLAY_MODE, modo);
octante3=gluNewNurbsRenderer();
gluNurbsProperty(octante3, GLU_SAMPLING_TOLERANCE, 25.0);
gluNurbsProperty(octante3, GLU_DISPLAY_MODE, modo);
octante4=gluNewNurbsRenderer();
gluNurbsProperty(octante4, GLU_SAMPLING_TOLERANCE, 25.0);
gluNurbsProperty(octante4, GLU_DISPLAY_MODE, modo);
octante5=gluNewNurbsRenderer();
gluNurbsProperty(octante5, GLU_SAMPLING_TOLERANCE, 25.0);
gluNurbsProperty(octante5, GLU_DISPLAY_MODE, modo);
octante6=gluNewNurbsRenderer();
gluNurbsProperty(octante6, GLU_SAMPLING_TOLERANCE, 25.0);
gluNurbsProperty(octante6, GLU_DISPLAY_MODE, modo);
octante7=gluNewNurbsRenderer();
gluNurbsProperty(octante7, GLU_SAMPLING_TOLERANCE, 25.0);
gluNurbsProperty(octante7, GLU_DISPLAY_MODE, modo);
octante8=gluNewNurbsRenderer();
gluNurbsProperty(octante8, GLU_SAMPLING_TOLERANCE, 25.0);
gluNurbsProperty(octante8, GLU_DISPLAY_MODE, modo);
}

void showcontrolpoints(void)
{
int i;
glPointSize(5.0);
glDisable(GL_LIGHTING);
glColor3f(1.0,1.0,0.0);
for(i=0;i {
glBegin(GL_POINTS);
glVertex3fv(&line[i*3]);
glEnd();
}
glEnable(GL_LIGHTING);
}

void selectControlPoints(void)
{
int k;
for (k=0;k {
glLoadName(k);
glBegin(GL_POINTS);
glVertex3fv(&line[k*3]);
glEnd();
}
}

void display(void)
{
GLfloat knots[16] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_OUTLINE_POLYGON);
gluNurbsProperty(octante1, GLU_DISPLAY_MODE, modo);
gluNurbsProperty(octante2, GLU_DISPLAY_MODE, modo);
gluNurbsProperty(octante3, GLU_DISPLAY_MODE, modo);
gluNurbsProperty(octante4, GLU_DISPLAY_MODE, modo);
gluNurbsProperty(octante5, GLU_DISPLAY_MODE, modo);
gluNurbsProperty(octante6, GLU_DISPLAY_MODE, modo);
gluNurbsProperty(octante7, GLU_DISPLAY_MODE, modo);
gluNurbsProperty(octante8, GLU_DISPLAY_MODE, modo);
glPushMatrix();
glRotatef((GLfloat)angx,1.0,0.0,0.0);
glRotatef((GLfloat)angy,0.0,1.0,0.0);
glRotatef((GLfloat)angz,0.0,0.0,1.0);
glTranslatef(x,0.0,0.0);
glTranslatef(0.0,y,0.0);
glTranslatef(0.0,0.0,z);
if(superficie)
{
gluBeginSurface(octante1);
gluNurbsSurface(octante1,16,knots,16,knots,8*3,3,&cpoints1[0][0][0],8,8,GL_MAP2_VERTEX_3);
gluEndSurface(octante1);
gluBeginSurface(octante2);
gluNurbsSurface(octante2,16,knots,16,knots,8*3,3,&cpoints2[0][0][0],8,8,GL_MAP2_VERTEX_3);
gluEndSurface(octante2);
gluBeginSurface(octante3);
gluNurbsSurface(octante3,16,knots,16,knots,8*3,3,&cpoints3[0][0][0],8,8,GL_MAP2_VERTEX_3);
gluEndSurface(octante3);
gluBeginSurface(octante4);
gluNurbsSurface(octante4,16,knots,16,knots,8*3,3,&cpoints4[0][0][0],8,8,GL_MAP2_VERTEX_3);
gluEndSurface(octante4);
gluBeginSurface(octante5);
gluNurbsSurface(octante5,16,knots,16,knots,8*3,3,&cpoints5[0][0][0],8,8,GL_MAP2_VERTEX_3);
gluEndSurface(octante5);
gluBeginSurface(octante6);
gluNurbsSurface(octante6,16,knots,16,knots,8*3,3,&cpoints6[0][0][0],8,8,GL_MAP2_VERTEX_3);
gluEndSurface(octante6);
gluBeginSurface(octante7);
gluNurbsSurface(octante7,16,knots,16,knots,8*3,3,&cpoints7[0][0][0],8,8,GL_MAP2_VERTEX_3);
gluEndSurface(octante7);
gluBeginSurface(octante8);
gluNurbsSurface(octante8,16,knots,16,knots,8*3,3,&cpoints8[0][0][0],8,8,GL_MAP2_VERTEX_3);
gluEndSurface(octante8);
}
glDisable(GL_LIGHTING);
glColor3f(1.0,0.0,1.0);
gluBeginCurve(theNurb);
gluNurbsCurve(theNurb,16,knots,3,line,8,GL_MAP1_VERTEX_3);
gluEndCurve(theNurb);
glEnable(GL_LIGHTING);
showcontrolpoints();
glPopMatrix();
glDisable(GL_LIGHTING);
glColor3f(0.0,1.0,1.0);
glBegin(GL_LINES);
glVertex3fv(&eje_rotacion[0][0]);
glVertex3fv(&eje_rotacion[1][0]);
glEnd();
glEnable(GL_LIGHTING);
glFlush();
glutSwapBuffers();
}

//****************************
void guardaArchivo(void)
{
char path[]="C:\\Users\\Carlos\\Desktop\\puntoscontrol.txt";
char str[80];
int d;
double ld;
int arreglo[10];
FILE *fp;
//Escritura de archivo
if((fp=fopen(path,"w"))==NULL)
{
printf("No se puede abrir el archivo");
exit(1);
}

for(int contador=0;contador {
fprintf(fp,"%f,%f,%f\n",ctlpoints[contador][0],ctlpoints[contador][1],ctlpoints[contador][2]);
}
fclose(fp);
}
void cargaArchivo(void)
{
char path[80];
FILE *fp;

printf("Ingrese la direción.\n");
gets(path);

if((fp=fopen(path,"r"))==NULL)
{
printf("No se puede abrir el archivo");
exit(1);
}

for(int contador=0;contador {
fscanf(fp,"%f,%f,%f\n",&ctlpoints[contador][0],&ctlpoints[contador][1],&ctlpoints[contador][2]);
printf("%f,%f,%f\n",ctlpoints[contador][0],ctlpoints[contador][1],ctlpoints[contador][2]);
}
fclose(fp);
}
//*********************************
void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case 't':
case 'T':
if(modo==GLU_OUTLINE_POLYGON)
modo=GLU_FILL;
else
modo=GLU_OUTLINE_POLYGON;
glutPostRedisplay();
break;
case 'c':
case 'C':
z=z+0.5;
glutPostRedisplay();
break;
case 'l':
case 'L':
z=z-0.5;
glutPostRedisplay();
break;
case 's':
case 'S':
y=y+0.5;
glutPostRedisplay();
break;
case 'b':
case 'B':
y=y-0.5;
glutPostRedisplay();
break;
case 'i':
case 'I':
x=x-0.5;
glutPostRedisplay();
break;
case 'd':
case 'D':
x=x+0.5;
glutPostRedisplay();
break;
case 'g':
case 'G':
init_solid();
superficie=~superficie;
glutPostRedisplay();
break;
case 'x':
angx=(angx+10)%360;
glutPostRedisplay();
break;
case 'X':
angx=(angx-10)%360;
glutPostRedisplay();
break;
case 'y':
angy=(angy+10)%360;
glutPostRedisplay();
break;
case 'Y':
angy=(angy-10)%360;
glutPostRedisplay();
break;
case 'z':
angz=(angz+10)%360;
glutPostRedisplay();
break;
case 'Z':
angz=(angz-10)%360;
glutPostRedisplay();
break;
case 'r':
case 'R':
angx=0;
angy=0;
angz=0;
x=y=z=0.0;
glutPostRedisplay();
break;
//******************
case 'p':
case 'P':
printf("\n");
for(int contador=0;contador<8;contador++)
{
printf("%f,%f,%f\n",ctlpoints[contador][0],ctlpoints[contador][1],ctlpoints[contador][2]);
}
guardaArchivo();
break;
case 'a':
case 'A':
cargaArchivo();
glutPostRedisplay();
break;
//*********************
case 27:
exit(0);
break;
default:
break;
}
}

void ortho(void)
{
if (winWidth <= winHeight)
glOrtho(-10.0,10.0,-10.0*(GLfloat)winHeight/(GLfloat)winWidth,10.0*(GLfloat)winHeight/(GLfloat)winWidth,-10.0,10.0);
else
glOrtho(-10.0*(GLfloat)winWidth/(GLfloat)winHeight,10.0*(GLfloat)winWidth/(GLfloat)winHeight,-10.0,10.0,-10.0,10.0);
}

GLuint pick(int x, int y)
{
int hits;
(void)glRenderMode(GL_SELECT);
glInitNames();
glPushName(~0);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix(x,winHeight-y, 8.0, 8.0, viewport);
ortho();
glMatrixMode(GL_MODELVIEW);
selectControlPoints();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
hits = glRenderMode(GL_RENDER);
if (hits)
{
return selectBuffer[3];
}
else
{
return ~0;
}
}

void reshape (int w, int h)
{
glViewport(0, 0, w, h);
winWidth = w;
winHeight = h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
ortho();
glGetDoublev(GL_PROJECTION_MATRIX,projMatrix);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glGetDoublev(GL_MODELVIEW_MATRIX,modelMatrix);
viewport[0] = 0;
viewport[1] = 0;
viewport[2] = winWidth;
viewport[3] = winHeight;
}

void mouse(int button, int state, int x, int y)
{
if(button == GLUT_LEFT_BUTTON)
{
if(state == GLUT_DOWN)
{
selectedPoint = pick(x,y);
}
else
{
selectedPoint = -1;
}
}
}


void motion(int x, int y)
{
GLdouble objx, objy, objz;
if (selectedPoint!=~0)
{
gluUnProject(x,winHeight-y,0.95,modelMatrix,projMatrix,viewport,&objx,&objy,&objz);
line[selectedPoint*3+0]=objx;
line[selectedPoint*3+1]=objy;
glutPostRedisplay();
}
}

int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow(argv[0]);
init();
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
glSelectBuffer(sizeof(selectBuffer),selectBuffer);
glutMainLoop();
return 0;
}

//////////////KOCH_HYBRID

/*
Programa en OpenGL que dibuja curva de Koch para insertar un exágono sobre un
cuadrilátero.
El programa utiliza una función recursiva que referencia en forma global
al último vértice que se utilizó para dibujar líneas en forma relativa a éste.
Se incrementan el número de iteraciones con la tecla 'i' y se decrementan con 'I',
nunca siendo menores a una iteración.

Mayo de 2003.

Santiago Igor Valiente Gomez
*/

#include
#include
#include
#define PI 3.1415926535897932384626433

typedef GLfloat point2[2];

point2 lastPoint = { 0.0, 0.0 };
static int iteraciones = 1;

void inicializa(void)
{
glClearColor(0.0,0.0,1.0,1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-100.0, 100.0, -100.0, 100.0);
glMatrixMode(GL_MODELVIEW);
}

void ejes()
{
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINES);
glVertex2f(-100.0, 0.0);
glVertex2f(100.0, 0.0);
glVertex2f(0.0, -100.0);
glVertex2f(0.0, 100.0);
glEnd();
}

void koch(int iteracion, float longitud, float pendiente)
{
float x1, y1, x2, y2;

iteracion-=1;

if (iteracion == 0)
{

x1 = lastPoint[0];
y1 = lastPoint[1];

x2 = longitud*cos(pendiente*PI/180.0) + x1;
y2 = longitud*sin(pendiente*PI/180.0) + y1;
glColor3f(1.0, 1.0, 0.0);

glBegin(GL_LINES);
glVertex2f(x1, y1);
glVertex2f(x2, y2);
glEnd();

lastPoint[0] = x2;
lastPoint[1] = y2;
} else
{
//triangulo
koch(iteracion, longitud/3, pendiente);
koch(iteracion, longitud/3, pendiente += 60.0);
koch(iteracion, longitud/3, pendiente -= 120.0);
koch(iteracion, longitud/3, pendiente += 60.0);
}
}

void despliega(void)
{
int iteracion = iteraciones;
float pendiente = 0.0;
float longitud = 50.0;

lastPoint[0] = 0.0;
lastPoint[1] = 0.0;
glClear(GL_COLOR_BUFFER_BIT);
ejes();
glPushMatrix();
glTranslatef(-25.0, 25.0, 0.0);

// base.. pentagono
koch(iteracion, longitud/3, pendiente);
koch(iteracion, longitud/3, pendiente += 108.0);
koch(iteracion, longitud/3, pendiente -= 72.0);
koch(iteracion, longitud/3, pendiente -= 72.0);
koch(iteracion, longitud/3, pendiente -= 72.0);
koch(iteracion, longitud/3, pendiente += 108.0);

koch(iteracion, longitud/3, pendiente -= 72.0);
koch(iteracion, longitud/3, pendiente += 108.0);
koch(iteracion, longitud/3, pendiente -= 72.0);
koch(iteracion, longitud/3, pendiente -= 72.0);
koch(iteracion, longitud/3, pendiente -= 72.0);
koch(iteracion, longitud/3, pendiente += 108.0);

koch(iteracion, longitud/3, pendiente -= 72.0);
koch(iteracion, longitud/3, pendiente += 108.0);
koch(iteracion, longitud/3, pendiente -= 72.0);
koch(iteracion, longitud/3, pendiente -= 72.0);
koch(iteracion, longitud/3, pendiente -= 72.0);
koch(iteracion, longitud/3, pendiente += 108.0);

koch(iteracion, longitud/3, pendiente -= 72.0);
koch(iteracion, longitud/3, pendiente += 108.0);
koch(iteracion, longitud/3, pendiente -= 72.0);
koch(iteracion, longitud/3, pendiente -= 72.0);
koch(iteracion, longitud/3, pendiente -= 72.0);
koch(iteracion, longitud/3, pendiente += 108.0);

koch(iteracion, longitud/3, pendiente -= 72.0);
koch(iteracion, longitud/3, pendiente += 108.0);
koch(iteracion, longitud/3, pendiente -= 72.0);
koch(iteracion, longitud/3, pendiente -= 72.0);
koch(iteracion, longitud/3, pendiente -= 72.0);
koch(iteracion, longitud/3, pendiente += 108.0);

glPopMatrix();
glFlush();
}

void teclado(unsigned char key, int x, int y)
{
switch (key)
{
case 27:
exit (0);
break;
case 'i':
iteraciones++;
glutPostRedisplay();
break;
case 'I':
if(iteraciones > 1) iteraciones--;
glutPostRedisplay();
default:
break;
}
}

int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("Curva de Koch");
glutDisplayFunc(despliega);
glutKeyboardFunc(teclado);
inicializa();
glutMainLoop();
return (0);
}