Task 7 Report of curiosity / / previous 7
/ / a) When launching the program first opens a window that displays viewport
/ / a fractal (Sierpenski Gasket)
/ / b) By click the left mouse button on the view port, output prints
/ / standard coordinates of the mouse cursor and creates a new window which will
/ / "draw" these coordinates and shifts the focus of the application to the window. Clicking
/ / with the right button on that window closes and focus returns to the initial window.
/ /
/ / c) in the initial screen, clicking the right button opens a window that draws
/ / parameterized humanoid (developed in previous practices) in an animation tour
/ / for the event idle. It changes the focus to this window. / / / / Christian Durán Jorge Lara
# include # include
void init (void);
fractal void (void);
display_fractal void (void);
display_coordenadas void (void);
display_humanoide void (void);
reshape_fractal void (int w, int h) void
reshape_coordenadas (int w, int h);
void idle ();
humanoid void ();
void cube ();
/ / used for the animation of the humanoid / /
torso parameters int rot_torso_x = 0; rot_torso_y
int = 0; rot_torso_z int = 0;
/ / parameters int head
rot_cabeza_x = 0;
rot_cabeza_y
int = 0;
rot_cabeza_z int = 0;
/ / parameters right arm
rot_brazoder_x
int = 0;
Int
rot_brazoder_y =- 60;
rot_brazoder_z int = 0;
/ / left arm parameters rot_brazoizq_x
int = 0; rot_brazoizq_y
int = 60;
rot_brazoizq_z int = 0;
/ / parameters right leg rot_piernader_x
int = 0; rot_piernader_y
int = 0; rot_piernader_z
int = 0;
/ / parameters left leg rot_piernaizq_x
int = 0; rot_piernaizq_y int = 0; rot_piernaizq_z
int = 0;
/ / Used for the purpose of factal and window control int aux = 1; int flag = 0; bandera1
int = 0;
Window1 int / / logical name for the first int window
ventana2 / / logical name for the second window
int ventana3
/ / logical name for the third window
int xzoom = 0;
yzoom
int = 0;
px1
float =- 2.5;
float =- 2165 PY1, PX2
float = 2.5;
=- 2165 PY2 float, float PX3 = 0; float PY3 = 2165; float px = 0; float py = 0;
void init (void) { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_FLAT);} void cube (void) {
glBegin (GL_QUADS)
glVertex3f (0.5,0.5,0.5), / / \u200b\u200bv1
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 humanoid ( ) {
/ * Build the torso of the humanoid * / glPushMatrix ();//
parent keeps a stack
glTranslatef (0.0,2.0,0.0) / / serves for translation
glScalef (1.7, 4.0, 1.0), / / \u200b\u200bused to climb
glRotatef (rot_torso_x, 1.0,0.0,0.0) glRotatef
(rot_torso_y, 0.0,1.0,0.0);
glRotatef (rot_torso_z, 0.0,0.0,1.0);
/ / glutWireCube (1.0);
cube ();
/ * built the head * /
glPushMatrix ();
glScalef (0.5,0.333,1.5)
glTranslatef (0.0,2.0,0.0) glRotatef
(rot_cabeza_x, 1.0,0.0,0.0);
glRotatef (rot_cabeza_y, 0.0,1.0,0.0) glRotatef
(rot_cabeza_z, 0.0,0.0,1.0);
glutWireCube (1.0);
glPopMatrix ();
/ * Build the right arm * /
glPushMatrix ();
glScalef (1.0,0.1666,1.0)
glTranslatef (1.0,2.5,0.0) glRotatef
(rot_brazoder_x, 1.0,0.0,0.0);
glRotatef (rot_brazoder_y, 0.0,1.0,0.0) glRotatef
(rot_brazoder_z, 0.0,0.0,1.0);
glutWireCube (1.0);
/ * Build the right forearm * /
glPushMatrix ();
glScalef (1.0,1.3,1.3);
glTranslatef (1.0,0.0,0.0);
/ / glutWireCube (1.0);
cube ();
/ * built the right * /
glPushMatrix ();
glScalef (0.25,0.5,1.0)
glTranslatef (2.5,0.0,0.0);
glutWireCube (1.0);
glPopMatrix ();
glPopMatrix ();
glPopMatrix ();/* up here is the full right arm * /
/ * Build the left arm * /
glPushMatrix ();
glScalef (1.0,0.1666,1.0)
glTranslatef (-1.0,2.5,0.0)
glRotatef (rot_brazoizq_x, 1.0,0.0,0.0) glRotatef
(rot_brazoizq_y, 0.0,1.0,0.0) glRotatef
(rot_brazoizq_z, 0.0,0.0,1.0);
glutWireCube (1.0);
/ * Build the left forearm * /
glPushMatrix ();
glScalef (1.0,1.3,1.3);
glTranslatef (-1.0,0.0,0.0) ;
/ / glutWireCube (1.0);
cube ();
/ * left hand constructed * /
glPushMatrix ();
glScalef (0.25,0.5,1.0)
glTranslatef (-2.5,0.0,0.0)
glutWireCube (1.0);
glPopMatrix ();
glPopMatrix ();
here glPopMatrix ();// to full left arm
/ * Build the right thigh * /
glPushMatrix ();
glScalef (0.3333,0.6,1.0)
glTranslatef (1.0, -1.125,0.0)
glRotatef (rot_piernader_x, 1.0,0.0,0.0) glRotatef
(rot_piernader_y , 0.0,1.0,0.0) glRotatef
(rot_piernader_z, 0.0,0.0,1.0);
glutWireCube (1.0);
/ * right calf constructed * /
glPushMatrix ();
glScalef (1.5,1.0,1.0);
glTranslatef (0.0, -1.0,0.0) ;
/ / glutWireCube (1.0);
cube ();
/ * RF * /
glPushMatrix ();
glScalef (1.5,0.25,1.0) glTranslatef
(0.1555, -2.5,0.0);
glutWireCube (1.0);
glPopMatrix ();
glPopMatrix ();
glPopMatrix ();// up here the whole right leg
/ * Build the left thigh * /
glPushMatrix ();
glScalef (0.3333,0.6,1.0)
glTranslatef (-1.0, -1.125,0.0)
glRotatef (rot_piernaizq_x, 1.0,0.0,0.0) glRotatef
( rot_piernaizq_y, 0.0,1.0,0.0) glRotatef
(rot_piernaizq_z, 0.0,0.0,1.0);
glutWireCube (1.0);
/ * left calf constructed * /
glPushMatrix ();
glScalef (1.5,1.0,1.0);
glTranslatef (0.0, -1.0,0.0) ;
/ / glutWireCube (1.0);
cube ();
/ * Build the left foot * /
glPushMatrix ();
glScalef (1.5,0.25,1.0)
glTranslatef (-0.1555, -2.5,0.0);
glutWireCube (1.0);
glPopMatrix ();
glPopMatrix ();
glPopMatrix ();/* left leg completes * / glPopMatrix
();/* full torso * /
glFlush ();}
fractal void (void) { int i = 0; px = rand ()% 20; py = rand () % 20; px = px/10; py = py/10; / * Points of the triangle * / 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 ();
/ * points to calculate * /
do
{
to
= rand ()% 3;
if (to == 0) {
px = (PX1 + px) / 2;
py = (py + PY1) / 2;}
if (to == 1) {
px = (px + PX2) / 2;
py = (py + PY2) / 2;
} if (to == 2) {
px = (px + PX3) / 2;
py = (PY3 + py) / 2;
}
glBegin (GL_POINTS)
glVertex2f (px, py);
glEnd ();
i + +;
} while ( i}
display_fractal void (void) {
glColor3f (1.0, 1.0, 0.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);
fractal ();
glFlush();
}
void display_coordenadas(void)
{
glColor3f (0.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);
fractal();
glPopMatrix();
glFlush();
}
void display_humanoide(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 0.0);
glLoadIdentity (); /* clear the matrix */
gluLookAt (0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
humanoide();
glFlush ();
}
void reshape_fractal (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 reshape_coordenadas (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);
}
/* ARGSUSED1 */
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
default:
break;
}
}
void mouse(int button, int state, int x, int y)
{
if (state == GLUT_DOWN)
{
if ((glutGetWindow() == ventana1) && button == GLUT_LEFT_BUTTON)
{
xzoom = 255 - x;
yzoom = y - 255;
printf ("% d,% d \\ n", x, y);
glutInitWindowSize (500, 500);
glutInitWindowPosition (700, 50);
ventana2 glutCreateWindow = ("specific coordinates");
init ();
glutDisplayFunc (display_coordenadas);
glutReshapeFunc (reshape_coordenadas);
glutSetWindow (ventana2) ;
glutIdleFunc (NULL);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
}
else if ((glutGetWindow() == ventana2) && (button == GLUT_RIGHT_BUTTON)){
glutIdleFunc(NULL);
glutDestroyWindow(ventana2);
}
}
if (state == GLUT_UP)
{
if ((glutGetWindow() == ventana1) && button == GLUT_RIGHT_BUTTON)
{
printf("%d, %d \n",x, y);
glutInitWindowSize (800, 800);
glutInitWindowPosition (450, 0);
ventana3 = glutCreateWindow ("Humanoide");
init();
glutDisplayFunc(display_humanoide);
glutReshapeFunc(reshape_fractal);
glutSetWindow(ventana3);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutIdleFunc(idle);
}
else if ((glutGetWindow() == ventana3) && (button == GLUT_RIGHT_BUTTON)){
glutIdleFunc(NULL);
glutDestroyWindow(ventana3);
//glutSetWindow(win1);
}
}
}
void idle()
{
int i,j;
for(j=0;j
{
display_humanoide();
rot_brazoder_y = ((rot_brazoizq_y + 1)*-1)%65;
rot_brazoizq_y = (rot_brazoizq_y + 1)%65;
for (i=0;i
{
}
}
for(j=0;j
{
display_humanoide();
rot_brazoder_y = ((rot_brazoizq_y - 1)*-1)%65;
rot_brazoizq_y = (rot_brazoizq_y - 1)%65;
for (i=0;i
{}} <60;j++)
} int main (int argc, char ** argv) {
<10000000;i++)
/ / code to the first window that displays the fractal
glutInit (& argc, argv);
glutInitDisplayMode (GLUT_SINGLE
init (); <60;j++)
glutDisplayFunc (display_fractal)
glutReshapeFunc (reshape_fractal)
glutIdleFunc (NULL);
glutKeyboardFunc (keyboard);
glutMouseFunc (mouse); <10000000;i++)
glutMainLoop ();
return 0;}