I) Objetivo
Ver Guía de Computación Gráfica III) Prácticas /* * Creado el 23 de mayo, 2012 por Hernán Nina Hanco * * Este trabajo es parte del proyecto CG1, que corresponde a la * implementación de algoritmos de Dibujo de graficas. * * Universidad Nacional de San Antonio Abad del Cusco * Carrera Profesional de Ingeniería Informática y de Sistemas * Asignatura: Computación Gráfica I */ package geometrias.transformaciones; /* * Transformaciones básicas * @author Hernan Nina Hanco */ import javax.media.opengl.*; public class Renderer_Transformaciones2DBasicas implements GLEventListener { protected GL2 gl; /* Vertices de un triangulo */ static float vertices[][] = { {100.0f, 0.0f}, {0.0f, 100.0f}, {-100.0f, 0.0f} }; static float[][] matrizIdentidad = { {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f} }; /* * Inicializar graficador OpenGL */ @Override public void init(GLAutoDrawable gLDrawable) { // Provee un objeto que enlaza las APIs del OpenGL // Que se encargara de realizar las instrucciones de dibujos gl = gLDrawable.getGL().getGL2(); // Color de fondo del GLCanvas gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); gl.glClear(GL2.GL_COLOR_BUFFER_BIT); // definir el color del pincel gl.glColor3f(1.0f, 0.0f, 0.0f); } /* * Método para actualizar el dibujo cuando, * se modifica el tamaño de la ventana. */ @Override public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) { // 7. Especificar el área de dibujo (frame) utilizamos coordenadas gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(-width, width, -height, height, -1.0, 1.0); } @Override public void dispose(GLAutoDrawable glad) { // no implementado } /* * Inicializar y presentar el dibujo de OpenGL */ @Override public void display(GLAutoDrawable drawable) { // Establecer el tamaño y color del punto gl.glPointSize(1); gl.glColor3f(0.0f, 0.0f, 1.0f); dibujarTriangulo(); // trasladar triangulo trasladarTriangulo(150.0f, 0.0f); dibujarTriangulo(); } /* * Operaciones de transformaciones */ protected void trasladarPunto2D(float tx, float ty) { } private void dibujarTriangulo() { gl.glBegin(GL.GL_TRIANGLES); gl.glVertex2f(vertices[0][0], vertices[0][1]); gl.glVertex2f(vertices[1][0], vertices[1][1]); gl.glVertex2f(vertices[2][0], vertices[2][1]); gl.glEnd(); } private void trasladarTriangulo(float tx, float ty) { trasladarPunto2D(vertices[0], tx, ty); trasladarPunto2D(vertices[1], tx, ty); trasladarPunto2D(vertices[2], tx, ty); } private void trasladarTrianguloHomo(float tx, float ty) { trasladarPuntoHomo2D(vertices[0], tx, ty); trasladarPuntoHomo2D(vertices[1], tx, ty); trasladarPuntoHomo2D(vertices[2], tx, ty); } private void trasladarPunto2D(float[] punto, float tx, float ty) { punto[0]=punto[0]+tx; punto[1]=punto[1]+ty; } private void trasladarPuntoHomo2D(float[] punto, float tx, float ty) { float[] puntoHomo = {punto[0], punto[1], 1.0f}; } private void multiplicarAPunto(float[][] matriz, float[] puntoHomo){ for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { //puntoHomo[j] = matriz[i,j]*puntoHomo[j]; } } } } IV) Tarea
|