Título: Ayuda con este programa? Publicado por: V_Dan en 27 Septiembre 2012, 05:28 am Hola!
Es un "brazo" y necesito que se mueva 180 grados por el teclado , son dos piezas diferentes pero no se como hacer lo del teclado y la transformación :o :o no me salee Una ayudita me caería bien Gracias!!! :o CÓDIGO: #include<GL/glut.h> #include <math.h> //Este es el tuyo float y; float q0[2]={-30,50}; float q1[2]={-30,230}; float q2[2]={30,230}; float q3[2]={30,50}; float b0[2] ,b1[2] ,b2[2],b3[2], t[2]; float save0[2],save1[2],save2[2],save3[2]; float ang; //****************************************** TRASLACIONES************************************************** void operaciones (float p[2], float p1[2]) //Parámetros de Entrada { float R[3][3]={1,0,0, 0,1,0, 0,0,1}; p1[0]= R[0][0]*p[0]+ R[0][1]*p[1] + R[0][2]*1; p1[1]= R[1][0]*p[0]+ R [1][1]*p[1] + R[1][2]*1; return; } void escalado2D (float p[2], float p1[2], float s[2]) //Parámetros de Entrada y parámetros de traslación x0 y y0 { float S[3][3]={0,0,0, 0,1,0, 0,0,1}; S[0][0]=s[0]; //s[0] es sx S[1][1]=s[1]; //s[1] es sy p1[0]= S[0][0]*p[0]+ S
//Matriz de traslación. return; } void traslacion2D (float p[2], float p1[2], float t[2]) //Parámetros de Entrada y parámetros de traslación x0 y y0 { float T[3][3]={0,0,0, 0,1,0, 0,0,1}; T[0][1]=t[0]; //t[0] es sx T[1][0]=t[1]; //t[1] es sy p1[0]= T[0][0]*p[0]+ T
//Matriz de traslación. return; } void rotacion2D (float p[2], float p1[2], float ang) //Parámetros de Entrada y parámetros de traslación x0 y y0 { float R[3][3]={0,0,0, 0,1,0, 0,0,1}; float theta; theta=ang*3.1415/180; R[0][0]=cos(theta); R[0][1]=-sin(theta); R[1][0]=sin(theta); R[1][1]=cos(theta); p1[0]= R[0][0]*p[0]+ R
//Matriz de Rotación. return; } //******************************************FIN TRASLACIONES*************************************************** void ejesguia() { y=500-y; glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0,1.0,0.0); glBegin(GL_LINES); glPointSize(0.8); glVertex2i(0,10); glVertex2i(0,490); glVertex2i(-240,10); glVertex2i(240,10); glEnd(); // Base glColor3f(1.0,1.0,0.0); glBegin(GL_POLYGON); glVertex2f(-150,10); glVertex2f(-150,80); glVertex2f(150,80); glVertex2f(150,10); glEnd(); // PIVOTE1 (No funciona) glColor3f(1.0,0.10,0.10); glBegin(GL_POINT); glPointSize(30.0); glVertex2f(0,80); glEnd (); glFlush(); } void Brazo1() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,0.0,1.0); glBegin(GL_POLYGON); glVertex2f(-30,50); glVertex2f(-30,230); glVertex2f(30,230); glVertex2f(30,50); glEnd(); glFlush(); } void Brazo2() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,0.0,1.0); glVertex2f(-30,210); glVertex2f(-30,430); glVertex2f(30,430); glVertex2f(30,210); glEnd(); glFlush(); } void moveBrazo1 () { //traslada origen t[0]=0.0; t[1]=0.0; traslacion2D(q0,b0,t); traslacion2D(q1,b1,t); traslacion2D(q2,b2,t); traslacion2D(q3,b3,t); save0[0]=q0[0]; save1[0]=q1[0]; save2[0]=q2[0]; save3[0]=q3[0]; save0[1]=q0[1]; save1[1]=q1[1]; save2[1]=q2[1]; save3[1]=q3[1]; // rota cada 10 grados ang= 10; rotacion2D(q0,b0,ang); rotacion2D(q1,b1,ang); rotacion2D(q2,b2,ang); rotacion2D(q3,b3,ang); //Posicion Inciial } void teclasEspeciales(int key, int x, int y) { /*switch (key) { case GLUT_KEY_LEFT: if (// lame la funcion que me rota o hace ); break; case GLUT_KEY_RIGHT: if (); break; case GLUT_KEY_UP: if () ; break; case GLUT_KEY_DOWN: if (); break; } */ } void init () { glClearColor (0.0, 0.0, 0.0, 0.0); glColor3f(1.0, 1.0, 1.0); glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho(-250, 250, 0, 500, -1.0, 1.0); } int main(int argc, char** argv) { glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(0,0); glutCreateWindow("Brazo"); glutDisplayFunc(ejesguia); init(); glutMainLoop(); } |