// //Alumno: Sánchez Nicolás Enrique //Matricula: 2173038289 // // flecha arriba rotar hacia arriba // flecha abajo rotar hacia abajo // flecha izquierda rotar hacia la izquierda // flecha derecha rotar hacia la derecha // f5 girar brazo completo en sentido horario // f6 girar brazo completo en sentido antihorario // f7 girar antebrazo completo en sentido horario // f8 girar antebrazo completo en sentido antihorario // f9 mover luz a lateral a la figura brazo +z // f10 mover luz a lateral a la figura brazo -z // page up mover luz lateral // page down mover luz lateral // insert subir luz // home bajar luz // a mover camara lateral sobre plano // s mover camara lateral sobre el plano // d subir camara sobre el plano // f subir camara sobre el plano // q alejar camara // w acercar camara #include "stdafx.h" #define BRAZO 1 #define ANTEBRAZO 2 #define ALPHA 0.75 #define ImageWidth 256 #define ImageHeight 256 #define BUFSIZE 512 GLfloat velocidadGiro1; GLfloat velocidadGiro2; GLfloat ex = 0.0f; GLfloat ey = 20.0f; GLfloat ez = -50.0f; GLfloat delta = 0.01f; GLfloat deltaR = 0.01f; GLenum shademode = GL_FLAT; GLuint selectBuf[BUFSIZE]; GLfloat shadowMat[16]; GLfloat xRot = 0.45f; GLfloat yRot = 0.35f; GLfloat Vpizo[] = { 0, 1,0, 20 }; GLfloat VLuz[] = { 0., 8., 0. , 1.0 }; //textura static GLubyte checkImage[ImageHeight][ImageWidth][4]; static GLuint texName[1]; int giro1, giro2; GLfloat texpts[2][2][2] = { {{0.0, 0.0}, {0.0, 2.0}}, {{3.0, 0.0}, {3.0, 2.0}} }; GLfloat colors[][3] = { { .5,0.0,0.5 },{ 1.0,0.0,0.0 }, { 1.0,1.0,0.0 },{ 0.0,1.0,0.0 },{ 0.0,0.0,1.0 }, { 1.0,0.0,1.0 },{ 1.0,1.0,1.0 },{ 0.0,1.0,1.0 } }; //puntos de control para objetos curveados (deformaciones) GLfloat ctrlpoints[4][4][3] = { { {-1.5, -1.5, 4.0}, {-0.5, -3.5, 2.0}, {0.5, -1.5, -1.0}, {1.5, -1.5, 2.0}}, { {-1.5, -0.5, 1.0}, {-0.5, -0.5, 3.0}, {0.5, -0.5, 0.0}, {1.5, -0.5, 4.0}}, //{ {-1.5, 0.5, -3.0}, {-0.5, -1.5, 0.0}, {0.5, 0.5, -3.0}, {1.5, 0.5, 4.0}}, { {-1.5, 2.5, 2.0}, {-0.5, -1.5, 2.0}, {0.5, 1.5, 0.0}, {1.5, 1.5, -1.0}} }; GLboolean bCull = glIsEnabled(GL_CULL_FACE); GLboolean bDepth = glIsEnabled(GL_DEPTH_TEST); GLboolean bOutline = (GLboolean)true; GLfloat ambientLight[] = { 0.3f, 0.3f, 0.3f, 1.0f }, diffuseLight[] = { 0.7f, 0.7f, 0.7f, 1.0f }, specular[] = { 1.0f, 1.0f, 1.0f, 1.0f }, specref[] = { 1.0f, 1.0f, 1.0f, 1.0f }, mat_shininess[] = { 50.0 }; // void makeCheckImages(void) { int i, j, c; for (i = 0; i < ImageHeight; i++) { for (j = 0; j < ImageWidth; j++) { c = ((((i & 0x12) == 0) ^ ((j & 0x12)) == 0)) * 255; checkImage[i][j][0] = (GLubyte)c; checkImage[i][j][3] = (GLubyte)255; } } } //configuracion inicial void init(){ velocidadGiro1 = 1; velocidadGiro2 = 1; glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_SMOOTH); glMap2f(GL_MAP2_TEXTURE_COORD_2, 0, 1, 2, 2, 0, 1, 4, 2, &texpts[0][0][0]); glEnable(GL_MAP2_TEXTURE_COORD_2); glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &ctrlpoints[0][0][0]); glEnable(GL_MAP2_VERTEX_3); glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0); glFrontFace(GL_CW); glEnable(GL_LIGHTING); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glPolygonMode(GL_BACK, GL_FILL); // the light source GL_LIGHT0 is enabled: // Set up and enable light 0 glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight); glLightfv(GL_LIGHT0, GL_SPECULAR, specular); glEnable(GL_LIGHT0); // Enable color tracking glEnable(GL_COLOR_MATERIAL); // Front material ambient and diffuse colors track glColor glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); // All materials hereafter have full specular reflectivity glMaterialfv(GL_FRONT, GL_SPECULAR, specref); glMateriali(GL_FRONT, GL_SHININESS, 128); makeCheckImages(); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, texName); glBindTexture(GL_TEXTURE_2D, texName[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ImageWidth, ImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage); glFrontFace(GL_CW); } void normalize(GLfloat v[3]) { GLfloat d = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); if (d == 0.0){ exit(100); return; } v[0] /= d; v[1] /= d; v[2] /= d; } void normcrossprod(GLfloat v1[3], GLfloat v2[3], GLfloat out[3]){ out[0] = v1[1] * v2[2] - v1[2] * v2[1]; out[1] = v1[2] * v2[0] - v1[0] * v2[2]; out[2] = v1[0] * v2[1] - v1[1] * v2[0]; normalize(out); } void gltGetNormalVector(GLfloat v0[3], GLfloat v1[3], GLfloat v2[3], GLfloat norm[3]){ GLfloat d1[3], d2[3]; for (int j = 0; j < 3; j++) { d1[j] = v0[j] - v1[j]; d2[j] = v1[j] - v2[j]; } normcrossprod(d1, d2, norm); } // Creacion de cuadrado y objetos para renderizar (color/no color) void cuadrado(){ glBegin(GL_POLYGON); GLfloat v1[] = { 1,1,0 }, v2[] = { 1, -1, 0 }, v3[] = { -1, -1, 0 }, norm[3]; gltGetNormalVector(&v1[0], &v3[0], &v2[0], norm); glNormal3fv(norm); glVertex2f(1., 1.); glVertex2f(1., -1.); glVertex2f(-1., -1.); glVertex2f(-1., 1.); glEnd(); } void uncolored_cube(void){ /* map vertices to faces */ /*cara 1*/ glPushMatrix(); glTranslatef(0, 0, 1.); cuadrado(); glPopMatrix(); /*cara 2*/ glPushMatrix(); glRotatef(90., 0., 1., 0); glTranslatef(0, 0, 1.); cuadrado(); glPopMatrix(); /*cara 3*/ glPushMatrix(); glRotatef(180., 0., 1., 0); glTranslatef(0, 0, 1.); cuadrado(); glPopMatrix(); /*cara 4*/ glPushMatrix(); glRotatef(270., 0., 1., 0); glTranslatef(0, 0, 1.); cuadrado(); glPopMatrix(); /*cara 5*/ glPushMatrix(); glRotatef(90., 1., 0., 0); glTranslatef(0, 0, 1.); cuadrado(); glPopMatrix(); /*cara 6*/ glPushMatrix(); glRotatef(-90., 1., 0., 0); glTranslatef(0, 0, 1.); cuadrado(); glPopMatrix(); } void colorcube(void){ /* map vertices to faces */ /*cara 1*/ glColor3fv(colors[2]); glPushMatrix(); glTranslatef(0, 0, 1.); cuadrado(); glPopMatrix(); /*cara 2*/ glColor3fv(colors[2]); glPushMatrix(); glRotatef(90., 0., 1., 0); glTranslatef(0, 0, 1.); cuadrado(); glPopMatrix(); /*cara 3*/ glColor3fv(colors[2]); glPushMatrix(); glRotatef(180., 0., 1., 0); glTranslatef(0, 0, 1.); cuadrado(); glPopMatrix(); /*cara 4*/ glColor3fv(colors[2]); glPushMatrix(); glRotatef(270., 0., 1., 0); glTranslatef(0, 0, 1.); cuadrado(); glPopMatrix(); /*cara 5*/ glColor3fv(colors[2]); glPushMatrix(); glRotatef(90., 1., 0., 0); glTranslatef(0, 0, 1.); cuadrado(); glPopMatrix(); /*cara 6*/ glColor3fv(colors[2]); glPushMatrix(); glRotatef(-90., 1., 0., 0); glTranslatef(0, 0, 1.); cuadrado(); glPopMatrix(); } void colorcube2(void){ /* map vertices to faces */ /*cara 1*/ glColor3fv(colors[1]); glPushMatrix(); glTranslatef(0, 0, 1.); cuadrado(); glPopMatrix(); /*cara 2*/ glColor3fv(colors[1]); glPushMatrix(); glRotatef(90., 0., 1., 0); glTranslatef(0, 0, 1.); cuadrado(); glPopMatrix(); /*cara 3*/ glColor3fv(colors[1]); glPushMatrix(); glRotatef(180., 0., 1., 0); glTranslatef(0, 0, 1.); cuadrado(); glPopMatrix(); /*cara 4*/ glColor3fv(colors[1]); glPushMatrix(); glRotatef(270., 0., 1., 0); glTranslatef(0, 0, 1.); cuadrado(); glPopMatrix(); /*cara 5*/ glColor3fv(colors[1]); glPushMatrix(); glRotatef(90., 1., 0., 0); glTranslatef(0, 0, 1.); cuadrado(); glPopMatrix(); /*cara 6*/ glColor3fv(colors[1]); glPushMatrix(); glRotatef(-90., 1., 0., 0); glTranslatef(0, 0, 1.); cuadrado(); glPopMatrix(); } void brazoSinColor(void) { glPushName(BRAZO); glPushMatrix(); glRotatef(giro1, 0.0, 0.0, 1.0); glTranslatef(1.0, 0.0, 0.0); glPushMatrix(); glScalef(2, 0.5, 0.5); uncolored_cube(); glPopMatrix(); glPushName(ANTEBRAZO); //antebrazo glTranslated(2, 0.0, 0.0); glRotatef(giro2, 0.0, 0.0, 1.0); glTranslatef(1.0, 0.0, 0.0); glPushMatrix(); glScalef(1.0, 0.5, 0.5); uncolored_cube(); glPopMatrix(); //Mano glTranslated(1.5, 0.0, 0.0); glRotatef(giro2 * 2, 1.0, 0.0, 0.0); glutSolidCube(1); //Dedos glTranslated(0.7, 0.0, 0.0); glPushMatrix(); glScalef(.4, .15, .1); glutSolidCube(1); glPopMatrix(); glTranslated(0.0, 0.4, 0.0); glPushMatrix(); glScalef(.4, .15, .1); glutSolidCube(1); glPopMatrix(); glTranslated(0.0, -0.8, 0.0); glPushMatrix(); glScalef(.4, .15, .1); glutSolidCube(1); glPopMatrix(); glPopMatrix(); } void brazoColor(int mode) { glPushName(BRAZO); glPushMatrix(); //Brazo glRotatef(giro1, 0.0, 0.0, 1.0); glTranslatef(1.0, 0.0, 0.0); glPushMatrix(); glScalef(2, 0.5, 0.5); colorcube(); glPopMatrix(); //antebrazo glPushName(ANTEBRAZO); glTranslated(2, 0.0, 0.0); glRotatef(giro2, 0.0, 0.0, 1.0); glTranslatef(1.0, 0.0, 0.0); glPushMatrix(); glScalef(1.0, 0.5, 0.5); colorcube2(); glPopMatrix(); //Mano glTranslated(1.5, 0.0, 0.0); glRotatef(giro2 * 2, 1.0, 0.0, 0.0); glColor3f(1.0, 0.0, 1.0); glutSolidCube(1); //Dedos glTranslated(0.7, 0.0, 0.0); glColor3f(0.0, 1.0, 0.0); glPushMatrix(); glScalef(.4, .15, .1); glutSolidCube(1); glPopMatrix(); glTranslated(0.0, 0.4, 0.0); glColor3f(0.0, 1.0, 0.0); glPushMatrix(); glScalef(.4, .15, .1); glutSolidCube(1); glPopMatrix(); glTranslated(0.0, -0.8, 0.0); glColor3f(0.0, 1.0, 0.0); glPushMatrix(); glScalef(.4, .15, .1); glutSolidCube(1); glPopMatrix(); glPopMatrix(); } void objetoCurveado(void) { glEnable(GL_TEXTURE_2D); glEnable(GL_AUTO_NORMAL); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL /* ignora a los demas efectos */);//3 buscar glBindTexture(GL_TEXTURE_2D, texName[0]); glPushMatrix(); glTranslatef(-10, 0,3); glScalef(1, 1, 1); glRotatef(0, 1, 0, 0); glEvalMesh2(GL_FILL, 0, 20, 0, 20); glPopMatrix(); glDisable(GL_TEXTURE_2D); glDisable(GL_AUTO_NORMAL); } void objetoCurveadoSinColor(void) { glPushMatrix(); glTranslatef(-10, 0, 3); glScalef(1, 1, 1); glRotatef(0, 1, 0, 0); glEvalMesh2(GL_FILL, 0, 20, 0, 20); glPopMatrix(); } //Matriz de sombra void gltMakeShadowMatrix(GLfloat vPlaneEquation[], GLfloat vLightPos[], GLfloat destMat[]){ GLfloat dot; // Dot product of plane and light position dot = vPlaneEquation[0] * vLightPos[0] + vPlaneEquation[1] * vLightPos[1] + vPlaneEquation[2] * vLightPos[2] + vPlaneEquation[3] * vLightPos[3]; // Now do the projection // First column destMat[0] = dot - vLightPos[0] * vPlaneEquation[0]; destMat[4] = 0.0f - vLightPos[0] * vPlaneEquation[1]; destMat[8] = 0.0f - vLightPos[0] * vPlaneEquation[2]; destMat[12] = 0.0f - vLightPos[0] * vPlaneEquation[3]; // Second column destMat[1] = 0.0f - vLightPos[1] * vPlaneEquation[0]; destMat[5] = dot - vLightPos[1] * vPlaneEquation[1]; destMat[9] = 0.0f - vLightPos[1] * vPlaneEquation[2]; destMat[13] = 0.0f - vLightPos[1] * vPlaneEquation[3]; // Third Column destMat[2] = 0.0f - vLightPos[2] * vPlaneEquation[0]; destMat[6] = 0.0f - vLightPos[2] * vPlaneEquation[1]; destMat[10] = dot - vLightPos[2] * vPlaneEquation[2]; destMat[14] = 0.0f - vLightPos[2] * vPlaneEquation[3]; // Fourth Column destMat[3] = 0.0f - vLightPos[3] * vPlaneEquation[0]; destMat[7] = 0.0f - vLightPos[3] * vPlaneEquation[1]; destMat[11] = 0.0f - vLightPos[3] * vPlaneEquation[2]; destMat[15] = dot - vLightPos[3] * vPlaneEquation[3]; } //llama objetos sin color void createObjetsNoColor() { brazoSinColor(); objetoCurveadoSinColor(); } //llama objetos con color void createObjects(int mode) { brazoColor(mode); objetoCurveado(); } //Dibujado de lineas void lineas() { glColor3f(0.0, 0., 0.); glBegin(GL_LINES); for (int i = 0; i < 10; i++) { glVertex2f(-1. + i * 2. / 9., 1.); glVertex2f(-1. + i * 2. / 9., -1.); glVertex2f(1, -1. + i * 2. / 9.); glVertex2f(-1., -1. + i * 2. / 9.); } glEnd(); } //Creacion de piso void piso() { glColor4f(0.66, 0.66, 0.66, ALPHA); glPushMatrix(); glTranslatef(0, -Vpizo[3], 0); glRotatef(-90., 1., 0, 0); glScalef(40., 40, 40.); cuadrado(); glDisable(GL_DEPTH_TEST); lineas(); if (bDepth) glEnable(GL_DEPTH_TEST); glPopMatrix(); } //creacion de luz void luz() { glColor3fv(colors[2]); glLightfv(GL_LIGHT0, GL_POSITION, VLuz); glPushMatrix(); glTranslatef(VLuz[0], VLuz[1], VLuz[2]); glutSolidSphere(0.8, 20, 20); glPopMatrix(); } //funcion para crear sombra, se envian objetos sin color, void SombrasObjetos(GLfloat datosdeLuz[], GLfloat datosdePlano[]) { glColor4f(0.33, 0.33, 0.33, ALPHA); glPushMatrix(); gltMakeShadowMatrix(datosdePlano, datosdeLuz, shadowMat); glMultMatrixf(shadowMat); createObjetsNoColor(); glPopMatrix(); } // funcion de configuracion, stencil evita dibujar fuera del area void Stencil_Config() { // turning off writing to the color buffer and depth buffer so we only // write to stencil buffer glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glDepthMask(GL_FALSE); // enable stencil buffer glEnable(GL_STENCIL_TEST); // write a one to the stencil buffer everywhere we are about to draw glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFFF); // this is to always pass a one to the stencil buffer where we draw glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); // render the plane which the shadow will be on // color and depth buffer are disabled, only the stencil buffer // will be modified piso(); // turn the color and depth buffers back on glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glDepthMask(GL_TRUE); // until stencil test is diabled, only write to areas where the // stencil buffer has a one. This is to draw the shadow only on // the floor. glStencilFunc(GL_EQUAL, 1, 0xFFFFFFFF); // don't modify the contents of the stencil buffer glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); } //funcion para renderizado constante de escena void renderScene(int mode){ // Reset coordinate system glMatrixMode(GL_PROJECTION); if (mode == GL_RENDER) glLoadIdentity(); gluPerspective(60.0, 1.0, 1.5, 500.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(ex, ey, ez, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); GLfloat x, y, angle; // Storage for coordinates and angles int iPivot = 1; // Used to flag alternating colors glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); if (bCull) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE); if (bDepth) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST); if (bOutline)glPolygonMode(GL_BACK, GL_LINE); else glPolygonMode(GL_BACK, GL_FILL); glPushMatrix(); glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); Stencil_Config(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* dibujar mundo reflejado 1. invertir orientación: glFrontFace(GL_CCW); 2. aplicar la transformacion reflejo dlTranslatef(0, -vPizo[3] (AlturqaPiso), 0); glScalef(1, -1, 1); dlTranslatef(0, vPizo[3] (AlturqaPiso), 0); 3. dibujar mundo (colorcube) 4. regresar a la orientacion original: glFrontFace(GL_CW); */ glDisable(GL_LIGHTING); piso(); glFrontFace(GL_CCW); glPushMatrix(); glTranslatef(0., -Vpizo[3], 0.); glScalef(1., -1., 1.); glTranslatef(0., Vpizo[3], 0.); luz(); glEnable(GL_LIGHTING); createObjects(mode); glDisable(GL_LIGHTING); glPopMatrix(); glDisable(GL_DEPTH_TEST); SombrasObjetos(VLuz, Vpizo); if (bDepth) glEnable(GL_DEPTH_TEST); glFrontFace(GL_CW); glDisable(GL_STENCIL_TEST); luz(); glEnable(GL_LIGHTING); createObjects(mode); glDisable(GL_LIGHTING); glPopMatrix(); glutSwapBuffers(); } /// Funciones para aumento de velocidad y reconocimiento de clicks void anallizename(int name) { int i; if (name == BRAZO) { for (i = 0; i < 3; i++) { velocidadGiro1 += 1; } } else if (name == ANTEBRAZO) { for (i = 0; i < 3; i++) { velocidadGiro2 += 1; } } glutPostRedisplay(); } void processHits(GLint hits, GLuint buffer[]){ if (hits == 0) { init(); return; } unsigned int i, j; GLuint names; GLuint* ptr; ptr = (GLuint*)buffer; for (i = 0; i < hits; i++) { names = *ptr; ptr += 3; for (j = 0; j < names; j++) anallizename(*ptr++); } } //funcion que ayuda a reconocer zona de clicks void pickAccion(int button, int state, int x, int y) { GLuint selectBuf[BUFSIZE]; GLint hits; GLint viewport[4]; if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN) return; glGetIntegerv(GL_VIEWPORT, viewport); glSelectBuffer(BUFSIZE, selectBuf); (void)glRenderMode(GL_SELECT); glInitNames(); glPushName(0); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluPickMatrix((GLdouble)x, (GLdouble)(viewport[3] - y), 5.0, 5.0, viewport); renderScene(GL_SELECT); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); hits = glRenderMode(GL_RENDER); processHits(hits, selectBuf); glutPostRedisplay(); } void reshape(int w, int h){ glViewport(0, 0, (GLsizei)w, (GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); } //funcion para movimientos con teclas void SpecialKeys(int key, int x, int y){ GLfloat dx, dy, dz; if (key == GLUT_KEY_UP){ dy = -ez; dz = ey; GLfloat s = sqrtf(ey * ey + ex * ex + ez * ez); ey += delta * dy; ez += delta * dz; GLfloat s1 = sqrtf(ey * ey + ex * ex + ez * ez) / s; ey /= s1; ex /= s1; ex /= s1; } if (key == GLUT_KEY_DOWN){ dy = -ez; dz = ey; GLfloat s = sqrtf(ey * ey + ex * ex + ez * ez); ey -= delta * dy; ez -= delta * dz; GLfloat s1 = sqrtf(ey * ey + ex * ex + ez * ez) / s; ey /= s1; ex /= s1; ex /= s1; } if (key == GLUT_KEY_LEFT){ dx = -ez; dz = ex; GLfloat s = sqrtf(ex * ex + ey * ey + ez * ez); ex += delta * dx; ez += delta * dz; GLfloat s1 = sqrtf(ex * ex + ey * ey + ez * ez) / s; ex /= s1; ey /= s1; ey /= s1; } if (key == GLUT_KEY_RIGHT){ dx = -ez; dz = ex; GLfloat s = sqrtf(ex * ex + ey * ey + ez * ez); ex -= delta * dx; ez -= delta * dz; GLfloat s1 = sqrtf(ex * ex + ey * ey + ez * ez) / s; ex /= s1; ey /= s1; ey /= s1; } if (key == GLUT_KEY_F1) bCull = !bCull; if (key == GLUT_KEY_F2)bDepth = !bDepth; if (key == GLUT_KEY_F3)bOutline = !bOutline; if (key == GLUT_KEY_F4){ if (shademode == GL_FLAT) { shademode = GL_SMOOTH; } else { if (shademode == GL_SMOOTH) { shademode = GL_FLAT; } }; glShadeModel(shademode); } if (key == GLUT_KEY_F5) { giro1 = (giro1 - (int)velocidadGiro1) % 360; } if (key == GLUT_KEY_F6) { giro1 = (giro1 + (int)velocidadGiro1) % 360; } if (key == GLUT_KEY_F7) { giro2 = (giro2 + (int)velocidadGiro2) % 360; } if (key == GLUT_KEY_F8) { giro2 = (giro2 - (int)velocidadGiro2) % 360; } if (key == GLUT_KEY_F9) { VLuz[2] += 0.5; } if (key == GLUT_KEY_F10) { VLuz[2] -= 0.5; } if (key == GLUT_KEY_PAGE_UP) { VLuz[0] += 0.5; } if (key == GLUT_KEY_PAGE_DOWN) { VLuz[0] -= 0.5; } if (key == GLUT_KEY_INSERT){ VLuz[1] += 0.5; } if (key == GLUT_KEY_HOME){ VLuz[1] -= 0.5; } glutPostRedisplay(); } void keyboardDown(unsigned char key, int x, int y) { GLfloat dx, dy, dz; //Movimiento del brazo if (key == 'a') { ex += (1.0f + deltaR); } if (key == 's') { ex -= (1.0f + deltaR); } if (key == 'd') { ey += (1.0f + deltaR); } if (key == 'f') { ey -= (1.0f + deltaR); } if (key == 'q') { ex *= (1.0f + deltaR); ey *= (1.0f + deltaR); ez *= (1.0f + deltaR); } if (key == 'w') { ex *= (1.0f - deltaR); ey *= (1.0f - deltaR); ez *= (1.0f - deltaR); } glutPostRedisplay(); } //funcion para mandar a llamar renderscene void display() { renderScene(GL_RENDER); } //main funcion principal que manda a llamar las otras funciones int main(int argc, char** argv){ glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE /*GLUT_SINGLE*/ | GLUT_RGB | GLUT_STENCIL | GLUT_DEPTH); glutInitWindowSize(600, 600); glutInitWindowPosition(200, 200); glutCreateWindow("Proyecto"); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutSpecialFunc(SpecialKeys); glutKeyboardFunc(keyboardDown); glutMouseFunc(pickAccion); glutMainLoop(); }