|
Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.
Mensajes - politico6
Páginas: [1]
1
« en: Jueves 26 de Mayo de 2011, 20:12 »
Hola a todos, necesito a partir de un pez hecho en 2D con transformaciones geométricas, con su zoom, movimientos de translación..etc.. a partir de eso hacerlo en 3D... y no se como hacerlo ni que funciones utilizar... alguien me puede echar una mano????? Gracias.. Os dejo el codigo: #include <stdio.h> #include <string.h> #include <stdlib.h> #include <GL/gl.h> #include <GL/glu.h> #include <GL/glut.h> int alto=800; int ancho=800; float zoom=1.0, tx=0.0, ty=0.0; static void Init( void ) { glClearIndex( 0.0 ); glShadeModel( GL_FLAT ); } static void Reshape( int width, int height ) { ancho=width; alto=height; glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0.1, 0.1, (GLint)width/2, (GLint)height/2); glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glScalef(zoom,zoom,1.0); glTranslatef(tx,ty,0.0); glClearColor(0.0,0,0.7,0.0); glClear( GL_COLOR_BUFFER_BIT ); glColor3f(0.0,0.0,0.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glCallList(2); //primera figura izquierda abajo glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport((GLint)width/2, 0.0, (GLint)width/2, (GLint)height/2); glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glScalef(zoom,zoom,1.0); glTranslatef(tx,ty,0.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glCallList(2); //segunda figura derecha abajo glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0, (GLint)width/2, (GLint)width/2, (GLint)height/2); glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glScalef(zoom,zoom,1.0); glTranslatef(tx,ty,0.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glCallList(2); // tercera figura izquierda arriba glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport((GLint)width/2, (GLint)width/2, (GLint)width/2, (GLint)height/2); glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glScalef(zoom,zoom,1.0); glTranslatef(tx,ty,0.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glCallList(2); //cuarta figura derecha arriba glFlush(); } static void Key_Esc(unsigned char key, int x, int y ) { if (key==27) if (key ==43){ zoom*=1.1; Reshape(ancho,alto); } if (key==45){ zoom*=0.9; Reshape(ancho,alto); } } static void Special(int key, int x, int y ) { if (key==GLUT_KEY_LEFT){ tx=tx-0.2; Reshape(ancho,alto); } if (key==GLUT_KEY_RIGHT){ tx=tx+0.2; Reshape(ancho,alto); } if (key==GLUT_KEY_UP){ ty=ty+0.2; Reshape(ancho,alto); } if (key==GLUT_KEY_DOWN){ ty=ty-0.2; Reshape(ancho,alto); } } static void triangulo () { glNewList(1, GL_COMPILE); glBegin(GL_TRIANGLES); // Dibujamos un triángulo glColor3f (1.0,0.6, 0.0); // Color glVertex3f(0.0,0.0,0.0); // Coordenadas del primer vértice glVertex3f(0.0,0.4,0.0); // Coordenadas del segundo vértice glVertex3f(0.4,0.0,0.0); // Coordenadas del tercer vértice glEnd(); glEndList(); // Terminamos de dibujar } static void cuadrado() { glBegin(GL_QUADS); glColor3f (1.0,0.6, 0.0); //color glVertex3f(0.0,0.0,0.0); glVertex3f(0.0,0.2,0.0); glVertex3f(0.2,0.2,0.0); glVertex3f(0.2,0.0,0.0); glEnd(); } void pez(){ glNewList(2, GL_COMPILE); glPushMatrix(); glTranslatef(0.0,0.0,0.0); glRotatef(0.0,0.0,0.0,0.0); glCallList(1); glPopMatrix(); // cuerpo de pez 1 glPushMatrix(); glRotatef(180.0,1.0,0.0,0.0); glCallList(1); glPopMatrix(); // cuerpo de pez 2 glPushMatrix(); glTranslatef(0.0,0.2,0.0); glRotatef(180.0,0.0,1.0,0.0); glScalef(0.5,0.5,0.0); glCallList(1); glPopMatrix(); // ala de arriba 1 glPushMatrix(); glTranslatef(-0.2,0.2,0.0); glRotatef(180.0,1.0,0.0,0.0); glScalef(0.5,0.5,0.0); glCallList(1); glPopMatrix(); // ala de arriba 2 glPushMatrix(); glTranslatef(-0.2,-0.2,0.0); glRotatef(0.0,0.0,0.0,0.0); glScalef(0.5,0.5,0.0); glCallList(1); glPopMatrix(); // ala de abajo 1 glPushMatrix(); glTranslatef(0.0,-0.2,0.0); glRotatef(180.0,0.0,0.0,1.0); glScalef(0.5,0.5,0.0); glCallList(1); glPopMatrix(); // ala de abajo 2 glPushMatrix(); glTranslatef(-0.4,0.0,0.0); glRotatef(0.0,0.0,0.0,0.0); glScalef(0.5,0.5,0.0); glCallList(1); glPopMatrix(); // cola 1 glPushMatrix(); glTranslatef(-0.4,0.0,0.0); glRotatef(180.0,1.0,0.0,0.0); glScalef(0.5,0.5,0.0); glCallList(1); glPopMatrix(); // cola 2 glPushMatrix(); glTranslatef(0.5,0.1,0.0); glRotatef(45.0,0.0,0.0,1.0); glScalef(0.5,0.5,0.0); glCallList(1); glPopMatrix(); // gota 1 glPushMatrix(); glTranslatef(0.5,0.38,0.0); glRotatef(225.0,0.0,0.0,1.0); glScalef(0.5,0.5,0.0); glCallList(1); glPopMatrix(); // gota 2 glEndList(); } static void Display( void ) { Reshape(ancho,alto); } int main( int argc, char **argv ) { glutInit(&argc, argv); int a; glutInitDisplayMode( GLUT_RGB ); glutInitWindowPosition(100,100 ); glutInitWindowSize(800, 800 ); glutCreateWindow("Pez con transformaciones geometricas"); Init(); triangulo(); pez(); glutReshapeFunc(Reshape); glutDisplayFunc(Display); glutKeyboardFunc(Key_Esc); glutSpecialFunc(Special); glutMainLoop( ); return 0; }
Páginas: [1]
|
|
|