martes, 17 de abril de 2007

Previo 7

#include
#include
#include
#include
#include
/*parametros para el triangulo*/
static int prueba = 1;
static int prueba2 = 1;
static int prueba4 = 1;
static int win1;
static int win2;
static int win3;
static int xzoom = 0;
static int yzoom = 0;
static float px1=-2.5;
static float py1=-2.165;
static float px2=2.5;
static float py2=-2.165;
static float px3=0;
static float py3=2.165;
static float px = 0;
static float py = 0;
static float pcx = 0;
static float pcy = 0;
static float color1 = 0;
static float color2 = 0;
/*-----------------------------------*/
/*parametros para humanoide*/
static int posicionx = 0;
static int posiciony = 0;
static int posicionz = 0;
/*cabeza*/
static int cuelloy = 0;
/*brazo derecho*/
static int hombroderx = 0;
static int hombrodery = 0;
static int hombroderz = 90;
static int cododerz = 0;
/*brazo izquierdo*/
static int hombroizqx = 0;
static int hombroizqy = 0;
static int hombroizqz = -90;
static int codoizqz = 0;
/*pierna derecha*/
static int musloderx = 0;
static int muslodery = 0;
static int musloderz = 45;
static int rodilladerx = 0;
static int piedery = 0;
/*pierna izquierda*/
static int musloizqx = 0;
static int musloizqy = 0;
static int musloizqz = -45;
static int rodillaizqx = 0;
static int pieizqy = 0;
GLUquadricObj *sphereObj;
/*-------------------------------------*/
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
}
void sierpinski (void)
{
int i= 0;
px = rand()%20;
py = rand()%20;
px = px/10;
py = py/10;
/*puntos del triangulo*/
glBegin(GL_POINTS);
glVertex2f(px1,py1);
glEnd();
glBegin(GL_POINTS);
glVertex2f(px2,py2);
glEnd();
glBegin(GL_POINTS);
glVertex2f(px3,py3);
glEnd();
glBegin(GL_POINTS);
glVertex2f(px,py);
glEnd();
/*puntos a calcular*/
do
{
prueba = rand()%3;
if(prueba == 0)
{
px = (px1 + px)/2;
py = (py1 + py)/2;
}
if(prueba == 1)
{
px = (px2 + px)/2;
py = (py2 + py)/2;
}
if(prueba == 2)
{
px = (px3 + px)/2;
py = (py3 + py)/2;
}
/*distancia entre el punto y el centro para los colores*/
pcx = px;
pcy = py + 0.72125;
pcx = pcx*pcx;
pcy = pcy*pcy;
color1 = sqrt(pcx+pcy);
color1 = color1/2.886;
color2 = 1.1 - color1;
glColor3f (color2,color1,0.0);
/*----------------------------------------------------*/
glBegin(GL_POINTS);
glVertex2f(px,py);
glEnd();
i++;
}while (i < 500000);
}
/*Humanoide y sus funciones*/
void cuborelleno(void)
{
glBegin(GL_QUADS);
glVertex3f(0.5,0.5,0.5);//v1
glVertex3f(-0.5,0.5,0.5);//v2
glVertex3f(-0.5,-0.5,0.5);//v3
glVertex3f(0.5,-0.5,0.5);//v4
glEnd();
glBegin(GL_QUADS);
glVertex3f(-0.5,0.5,-0.5);//v5
glVertex3f( 0.5,0.5,-0.5);//v6
glVertex3f(0.5,-0.5,-0.5);//v7
glVertex3f(-0.5,-0.5,-0.5);//v8
glEnd();
glBegin(GL_QUADS);
glVertex3f(-0.5,0.5,0.5);//v2
glVertex3f(-0.5,0.5,-0.5);//v5
glVertex3f(-0.5,-0.5,-0.5);//v8
glVertex3f(-0.5,-0.5,0.5);//v3
glEnd();
glBegin(GL_QUADS);
glVertex3f(0.5,0.5,0.5);//v1
glVertex3f(0.5,-0.5,0.5);//v4
glVertex3f( 0.5,-0.5,-0.5);//v7
glVertex3f(0.5,0.5,-0.5);//v6
glEnd();
glBegin(GL_QUADS);
glVertex3f(-0.5,0.5,-0.5);//v5
glVertex3f(-0.5,0.5,0.5);//v2
glVertex3f(0.5,0.5,0.5);//v1
glVertex3f( 0.5,0.5,-0.5);//v6
glEnd();
glBegin(GL_QUADS);
glVertex3f(0.5,-0.5,-0.5);//v7
glVertex3f(-0.5,-0.5,-0.5);//v8
glVertex3f(-0.5,-0.5,0.5);//v3
glVertex3f(0.5,-0.5,0.5);//v4
glEnd();
}
void cubohueco(void)
{
glBegin(GL_LINE_LOOP);
glVertex3f(0.5,0.5,0.5);//v1
glVertex3f(-0.5,0.5,0.5);//v2
glVertex3f(-0.5,-0.5,0.5);//v3
glVertex3f(0.5,-0.5,0.5);//v4
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(-0.5,0.5,-0.5);//v5
glVertex3f( 0.5,0.5,-0.5);//v6
glVertex3f(0.5,-0.5,-0.5);//v7
glVertex3f(-0.5,-0.5,-0.5);//v8
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(-0.5,0.5,0.5);//v2
glVertex3f(-0.5,0.5,-0.5);//v5
glVertex3f(-0.5,-0.5,-0.5);//v8
glVertex3f(-0.5,-0.5,0.5);//v3
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(0.5,0.5,0.5);//v1
glVertex3f(0.5,-0.5,0.5);//v4
glVertex3f( 0.5,-0.5,-0.5);//v7
glVertex3f(0.5,0.5,-0.5);//v6
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(-0.5,0.5,-0.5);//v5
glVertex3f(-0.5,0.5,0.5);//v2
glVertex3f(0.5,0.5,0.5);//v1
glVertex3f( 0.5,0.5,-0.5);//v6
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(0.5,-0.5,-0.5);//v7
glVertex3f(-0.5,-0.5,-0.5);//v8
glVertex3f(-0.5,-0.5,0.5);//v3
glVertex3f(0.5,-0.5,0.5);//v4
glEnd();
}
void torso (int posx,int posy,int posz)
{
glTranslatef(0.0,1.5,0.0);
glScalef (0.75, 0.75, 0.75);
glRotatef(posx,1.0,0.0,0.0);
glRotatef(posy,0.0,1.0,0.0);
glRotatef(posz,0.0,0.0,1.0);
glTranslatef(0.0,0.0,0.0);
glPushMatrix();
glScalef (2.0, 3.0, 1.0);
cubohueco();
glPopMatrix();
}
void cara (int cuey)
{
glPushMatrix();
glRotatef(cuey,0.0,1.0,0.0);
glTranslatef(0.0,2.0,0.0);
//cubohueco();
gluSphere(sphereObj, 0.65, 12, 5);
glPopMatrix();
}
void muneca (void)
{
/*muñeca y palma*/
glTranslatef(0.0,0.0,0.0);
glRotatef(0,1.0,0.0,0.0);
glRotatef(0,0.0,1.0,0.0);
glRotatef(0,0.0,0.0,1.0);
glTranslatef(0.0,0.5,0.0);
glPushMatrix();
glScalef(1.0,1.0,0.33333);
cubohueco();
glPopMatrix();
}
void dedos(void)
{
/*dedo chito*/
glScalef(1.0,1.0,1.0);
glPushMatrix();
/*primera falange*/
glScalef(0.25,0.25,0.25);
glTranslatef(-1.5,2.2,0.0);
glRotatef(0,1.0,0.0,0.0);
gluSphere(sphereObj, 0.65, 12, 5);
glTranslatef(0.0,1.0,0.0);
glPushMatrix();
glScalef(1.0,1.5,1.0);
cubohueco();
glPopMatrix();
/*segunda falange*/
glTranslatef(0.0,0.90,0.0);
glRotatef(0,1.0,0.0,0.0);
gluSphere(sphereObj, 0.65, 12, 5);
glTranslatef(0.0,0.85,0.0);
glPushMatrix();
glScalef(1.0,1.0,1.0);
cubohueco();
glPopMatrix();
/*tercera falange*/
glTranslatef(0.0,0.90,0.0);
glRotatef(0,1.0,0.0,0.0);
gluSphere(sphereObj, 0.60, 12, 5);
glTranslatef(0.0,0.75,0.0);
glPushMatrix();
glScalef(1.0,1.0,1.0);
cubohueco();
glPopMatrix();
glPopMatrix();/*fin dedo chiquito*/
/*dedo anular*/
glPushMatrix();
/*primera falange*/
glScalef(0.25,0.25,0.25);
glTranslatef(-0.5,2.2,0.0);
glRotatef(0,1.0,0.0,0.0);
gluSphere(sphereObj, 0.65, 12, 5);
glTranslatef(0.0,1.0,0.0);
glPushMatrix();
glScalef(1.0,1.5,1.0);
cubohueco();
glPopMatrix();
/*segunda falange*/
glTranslatef(0.0,0.90,0.0);
glRotatef(0,1.0,0.0,0.0);
gluSphere(sphereObj, 0.65, 12, 5);
glTranslatef(0.0,1.25,0.0);
glPushMatrix();
glScalef(1.0,1.75,1.0);
cubohueco();
glPopMatrix();
/*tercera falange*/
glTranslatef(0.0,0.90,0.0);
glRotatef(0,1.0,0.0,0.0);
gluSphere(sphereObj, 0.60, 12, 5);
glTranslatef(0.0,0.75,0.0);
glPushMatrix();
glScalef(1.0,1.0,1.0);
cubohueco();
glPopMatrix();
glPopMatrix();/*fin dedo anular*/
/*dedo medio*/
glPushMatrix();
/*primera falange*/
glScalef(0.25,0.25,0.25);
glTranslatef(0.5,2.2,0.0);
glRotatef(0,1.0,0.0,0.0);
gluSphere(sphereObj, 0.65, 12, 5);
glTranslatef(0.0,1.0,0.0);
glPushMatrix();
glScalef(1.0,1.5,1.0);
cubohueco();
glPopMatrix();
/*segunda falange*/
glTranslatef(0.0,0.90,0.0);
glRotatef(0,1.0,0.0,0.0);
gluSphere(sphereObj, 0.65, 12, 5);
glTranslatef(0.0,1.5,0.0);
glPushMatrix();
glScalef(1.0,2.25,1.0);
cubohueco();
glPopMatrix();
/*tercera falange*/
glTranslatef(0.0,0.90,0.0);
glRotatef(0,1.0,0.0,0.0);
gluSphere(sphereObj, 0.60, 12, 5);
glTranslatef(0.0,0.75,0.0);
glPushMatrix();
glScalef(1.0,1.0,1.0);
cubohueco();
glPopMatrix();
glPopMatrix();/*fin dedo medio*/
/*dedo indice*/
glPushMatrix();
/*primera falange*/
glScalef(0.25,0.25,0.25);
glTranslatef(1.5,2.2,0.0);
glRotatef(0,1.0,0.0,0.0);
gluSphere(sphereObj, 0.65, 12, 5);
glTranslatef(0.0,1.0,0.0);
glPushMatrix();
glScalef(1.0,1.5,1.0);
cubohueco();
glPopMatrix();
/*segunda falange*/
glTranslatef(0.0,0.90,0.0);
glRotatef(0,1.0,0.0,0.0);
gluSphere(sphereObj, 0.65, 12, 5);
glTranslatef(0.0,1.25,0.0);
glPushMatrix();
glScalef(1.0,1.75,1.0);
cubohueco();
glPopMatrix();
/*tercera falange*/
glTranslatef(0.0,0.90,0.0);
glRotatef(0,1.0,0.0,0.0);
gluSphere(sphereObj, 0.60, 12, 5);
glTranslatef(0.0,0.75,0.0);
glPushMatrix();
glScalef(1.0,1.0,1.0);
cubohueco();
glPopMatrix();
glPopMatrix();/*fin dedo indice*/
/*dedo gordo*/
glPushMatrix();
/*primera falange*/
glScalef(0.25,0.25,0.25);
glTranslatef(2.0,-1.25,0.0);
glRotatef(0,0.0,-1.0,0.0);
glRotatef(0,0.0,0.0,1.0);
glScalef(1.3,1.3,1.0);
gluSphere(sphereObj, 0.65, 12, 5);
glTranslatef(0.75,0.0,0.0);
glPushMatrix();
glScalef(1.0,1.0,1.0);
cubohueco();
glPopMatrix();
/*segunda falange*/
glTranslatef(0.9,0.0,0.0);
glRotatef(0,0.0,0.0,1.0);
gluSphere(sphereObj, 0.65, 12, 5);
glTranslatef(0.6,0.0,0.0);
glPushMatrix();
glScalef(0.75,1.0,1.0);
cubohueco();
glPopMatrix();
/*tercera falange*/
glTranslatef(0.75,0.0,0.0);
glRotatef(0,0.0,0.0,1.0);
gluSphere(sphereObj, 0.60, 12, 5);
glTranslatef(0.5,0.0,0.0);
glPushMatrix();
glScalef(0.75,1.0,1.0);
cubohueco();
glPopMatrix();
glPopMatrix();/*fin dedo gordo*/
}
void mano(void)
{
glPushMatrix();
//glScalef(-1.0,1.0,1.0);
muneca();
dedos();
glPopMatrix();
}
void brazoderecho (int hombrodx,int hombrody,int hombrodz,int cododz)
{
/*brazo derecho*/
glPushMatrix();
glTranslatef(1.0,1.0,0.0);
glRotatef(hombrodx,1.0,0.0,0.0);
glRotatef(hombrody,0.0,1.0,0.0);
glRotatef(hombrodz,0.0,0.0,1.0);
glTranslatef(1.0,0.25,0.0);
glPushMatrix();
glScalef(2.0,0.5,1.0);
cubohueco();
glPopMatrix();
/*antebrazo derecho*/
glTranslatef(1.0,0.0,0.0);
glRotatef(cododz,0.0,0.0,1.0);
glTranslatef(1.0,0.0,0.0);
glPushMatrix();
glScalef(2.0,1.0,1.0);
cubohueco();
glPopMatrix();
/*mano derecha*/
glTranslatef(1.0,0.0,0.0);
glRotatef(-90,0.0,0.0,1.0);
gluSphere(sphereObj,0.25,12,5);
glTranslatef(0.0,0.25,0.0);
glPushMatrix();
glScalef(-0.5,0.5,1.0);
mano();
glPopMatrix();
glPopMatrix();/*brazo derecho completo*/
}
void brazoizquierdo (int hombroix,int hombroiy,int hombroiz,int codoiz)
{
/*brazo izquierdo*/
glPushMatrix();
glTranslatef(-1.0,1.0,0.0);
glRotatef(hombroix,1.0,0.0,0.0);
glRotatef(hombroiy,0.0,1.0,0.0);
glRotatef(hombroiz,0.0,0.0,1.0);
glTranslatef(-1.0,0.25,0.0);
glPushMatrix();
glScalef(2.0,0.5,1.0);
cubohueco();
glPopMatrix();
/*antebrazo izquierdo*/
glTranslatef(-1.0,0.0,0.0);
glRotatef(codoiz,0.0,0.0,1.0);
glTranslatef(-1.0,0.0,0.0);
glPushMatrix();
glScalef(2.0,1.0,1.0);
cubohueco();
glPopMatrix();
/*mano derecha*/
glTranslatef(-1.0,0.0,0.0);
glRotatef(90,0.0,0.0,1.0);
gluSphere(sphereObj,0.25,12,5);
glTranslatef(0.0,0.25,0.0);
glPushMatrix();
glScalef(0.5,0.5,1.0);
mano();
glPopMatrix();
glPopMatrix();/*brazo izquierdo completo*/
}
void piernaderecha(int muslodx,int muslody,int muslodz,int rodilladx,int piedy)
{
/*muslo derecho*/
glPushMatrix();
glTranslatef(0.665,-1.5,0.0);
glRotatef(muslodx,1.0,0.0,0.0);
glRotatef(muslody,0.0,1.0,0.0);
glRotatef(muslodz,0.0,0.0,1.0);
glTranslatef(0.0,-1.2,0.0);
glPushMatrix();
glScalef(0.68,2.4,1.0);
cubohueco();
glPopMatrix();
/*pantorrilla derecha*/
glTranslatef(0.0,-1.2,0.0);
glRotatef(rodilladx,1.0,0.0,0.0);
glTranslatef(0.0,-1.2,0.0);
glPushMatrix();
glScalef(1.0,2.4,1.0);
cubohueco();
glPopMatrix();
/*pie derecho*/
glTranslatef(0.0,0.-1.25,0.0);
glRotatef(piedy,0.0,1.0,0.0);
glTranslatef(0.25,-0.35,0.0);
glPushMatrix();
glScalef(1.5,0.75,1.0);
cubohueco();
glPopMatrix();
glPopMatrix();/*pie derecho completo*/
}
void piernaizquierda(int musloix,int musloiy,int musloiz,int rodillaix,int pieiy)
{
/*muslo izquierdo*/
glPushMatrix();
glTranslatef(-0.665,-1.5,0.0);
glRotatef(musloix,1.0,0.0,0.0);
glRotatef(musloiy,0.0,1.0,0.0);
glRotatef(musloiz,0.0,0.0,1.0);
glTranslatef(0.0,-1.2,0.0);
glPushMatrix();
glScalef(0.68,2.4,1.0);
cubohueco();
glPopMatrix();
/*pantorrilla izquierda*/
glTranslatef(0.0,-1.2,0.0);
glRotatef(rodillaix,1.0,0.0,0.0);
glTranslatef(0.0,-1.2,0.0);
glPushMatrix();
glScalef(1.0,2.4,1.0);
cubohueco();
glPopMatrix();
/*pie izquierdo*/
glTranslatef(0.0,0.-1.25,0.0);
glRotatef(pieiy,0.0,1.0,0.0);
glTranslatef(-0.25,-0.35,0.0);
glPushMatrix();
glScalef(1.5,0.75,1.0);
cubohueco();
glPopMatrix();
glPopMatrix();/*pierna izquierda completo*/
}
void humanoide (int px,int py,int pz,int cy,int hdx,int hdy,int hdz,int cdz,int hix,int hiy,int hiz,int ciz,
int mdx,int mdy,int mdz,int rdx,int pdy,int mix,int miy,int miz,int rix,int piy)
{
torso(px,py,pz);
cara(cy);
brazoderecho(hdx,hdy,hdz,cdz);
brazoizquierdo(hix,hiy,hiz,ciz);
piernaderecha(mdx,mdy,mdz,rdx,pdy);
piernaizquierda(mix,miy,miz,rix,piy);
}
/*----------------------------------------*/
void display1(void)
{
srand(time(NULL));
glColor3f (1.0, 1.0, 1.0);
glLoadIdentity ();
gluLookAt (0.0,0.0,5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glClear (GL_COLOR_BUFFER_BIT);
sierpinski();
glFlush();
}
void display2(void)
{
srand(time(NULL));
glColor3f (1.0, 1.0, 1.0);
glLoadIdentity ();
gluLookAt (0.0,0.0,15.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glClear (GL_COLOR_BUFFER_BIT);
glPushMatrix();
glScalef(4,4,1);
sierpinski();
glPopMatrix();
glFlush();
}
void display3(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glLoadIdentity ();
gluLookAt (0.0,0.0,10.0,0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glPushMatrix();
sphereObj = gluNewQuadric();
gluQuadricDrawStyle(sphereObj, GLU_LINE);
humanoide(posicionx,posiciony,posicionz,cuelloy,
hombroderx,hombrodery,hombroderz,cododerz,
hombroizqx,hombroizqy,hombroizqz,codoizqz,
musloderx,muslodery,musloderz,rodilladerx,piedery,
musloizqx,musloizqy,musloizqz,rodillaizqx,pieizqy);
glPopMatrix();
glFlush ();
}
void reshape1 (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);
}
void reshape2 (int w, int h)
{
glViewport (xzoom, yzoom, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);
}
void reshape3 (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);
}
void animacion(void)
{
int i,j;
for(j=0;j<45;j++)
{
display3();
hombroderz = (hombroderz +2)%95;
hombroizqz = (hombroizqz -2)%95;
musloderz = (musloderz -1)%50;
musloizqz = (musloizqz +1)%50;
for (i=0;i<3500000;i++)
{
}
}
for(j=0;j<45;j++)
{
display3();
hombroderz = (hombroderz -2)%90;
hombroizqz = (hombroizqz +2)%90;
musloderz = (musloderz +1)%50;
musloizqz = (musloizqz -1)%50;
for (i=0;i<3500000;i++)
{
}
}
}
void idle3(void)
{
animacion();
display3();
}
/* ARGSUSED1 */
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
case 'q':
glutPostRedisplay();
break;
}
}
void mouse(int button, int state, int x, int y)
{
if (state == GLUT_DOWN)
{
if ((glutGetWindow() == win1) && button == GLUT_LEFT_BUTTON)
{
xzoom = 255 - x;
yzoom = y - 255;
printf("%d, %d \n",x, y);
glutInitWindowSize (500, 500);
glutInitWindowPosition (700, 100);
win2 = glutCreateWindow ("Ventana 2");
init();
glutDisplayFunc(display2);
glutReshapeFunc(reshape2);
glutSetWindow(win2);
glutIdleFunc(NULL);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
}
else if ((glutGetWindow() == win2) && (button == GLUT_RIGHT_BUTTON)){
glutIdleFunc(NULL);
glutDestroyWindow(win2);
}
}
if (state == GLUT_UP)
{
if ((glutGetWindow() == win1) && button == GLUT_RIGHT_BUTTON)
{
printf("%d, %d \n",x, y);
glutInitWindowSize (800, 800);
glutInitWindowPosition (500, 50);
win3 = glutCreateWindow ("Ventana 3");
init();
glutDisplayFunc(display3);
glutReshapeFunc(reshape3);
glutSetWindow(win3);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutIdleFunc(idle3);
}
else if ((glutGetWindow() == win3) && (button == GLUT_RIGHT_BUTTON)){
glutIdleFunc(NULL);
glutDestroyWindow(win3);
//glutSetWindow(win1);
}
}
}
int main(int argc, char** argv)
{
//Configuracion de la primera ventana
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
win1 =glutCreateWindow ("Fractal");
glutSetWindow(win1);
init ();
glutDisplayFunc(display1);
glutReshapeFunc(reshape1);
glutIdleFunc(NULL);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}

No hay comentarios.: