You are on page 1of 3

ProyeccionesGeometricas.java 1 2 package Laboratorio2; 3 4 import java.awt.

BorderLayout; 16 17 public class ProyeccionesGeometricas extends JFrame implements GLEventListener 18 { 19 int anchura = 500; 20 int altura = 500; 21 int framesSegundo = 10;// Display refresh frames per second 22 JPanel panelDibujo; 23 Container contenedor; 24 FPSAnimator animator; // Used to drive display() 25 26 double x = 10; 27 static GL gl; 28 static GLCanvas canvas; 29 static GLU glu; 30 double x1 = 0, x2 = 0, z1 = 5, z2 = 4; 31 32 // Constructor 33 public ProyeccionesGeometricas() 34 { 35 super( "Proyecto Computacion Grafica" ); 36 37 canvas = new GLCanvas(); 38 gl = canvas.getGL(); 39 glu = new GLU(); 40 41 panelDibujo = new JPanel( new BorderLayout() ); 42 43 panelDibujo.add( canvas, BorderLayout.CENTER ); 44 45 contenedor = this.getContentPane(); 46 contenedor.setLayout( new BorderLayout() ); 47 contenedor.add( panelDibujo, BorderLayout.CENTER ); 48 49 canvas.addGLEventListener( this ); 50 51 // Run the animation loop using the fixed-rate Frame-per-second animator, 52 // which calls back display() at this fixed-rate (FPS). 53 animator = new FPSAnimator( canvas, framesSegundo, true); 54 55 this.setSize( anchura, altura ); 56 this.setVisible( true ); 57 this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); 58 59 animator.start(); 60 } 61 62 // Main program 63 public static void main(String[] args) 64 { 65 new ProyeccionesGeometricas(); 66 } 67 68 // Implement methods defined in GLEventListener 69 @Override 70 public void init(GLAutoDrawable drawable) 71 { Pgina 1

ProyeccionesGeometricas.java // Enable smooth shading, which blends colors nicely, and smoothes out lighting. 73 gl.glShadeModel(GL.GL_FLAT ); 74 // Set background color in RGBA. Alpha: 0 (transparent) 1 (opaque) 75 gl.glClearColor(.5f, 0.0f, 0.0f, 0.0f); 76 // Setup the depth buffer and enable the depth testing 77 //gl.glClearDepth(1.0f); // clear z-buffer to the farthest 78 //gl.glEnable(GL.GL_DEPTH_TEST); // enables depth testing 79 //gl.glDepthFunc(GL.GL_LEQUAL); // the type of depth test to do 80 // Do the best perspective correction 81 //gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); 82 } 83 84 @Override 85 public void display(GLAutoDrawable drawable) { 86 87 // Clear the color and the depth buffers 88 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); 89 // gl.glPushMatrix(); 90 // ----- Render the Pyramid ----91 // gl.glLoadIdentity(); // reset the model-view matrix 92 //glu.gluLookAt(x1, 0, z1, x2, 0, z2, 0, 1, 0 ); 93 gl.glTranslatef( 1, 1, 0); // translate left and into the screen 94 //z2 = z2 +2; 95 //gl.glRotatef(anglePyramid, -0.2f, 1.0f, 0.0f); // rotate about the y-axis 96 gl.glPointSize( 5 ); 97 gl.glColor3i( 1, 7, 100 ); 98 gl.glBegin( GL.GL_POINTS ); 99 for( int i = 1; i < 500; i = i + 15 ) 100 { 101 for( int j = 1; j < 500; j = j + 15 ) 102 gl.glVertex2i( i, j ); 103 } 104 gl.glEnd(); 105 106 //x = x + 0.01; 107 gl.glFlush(); 108 // gl.glPopMatrix(); 109 110 } 111 112 @Override 113 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { 114 115 116 //height = (height == 0) ? 1 : height; // prevent divide by zero 117 float aspect = (float)width / height; 118 119 // Set the current view port to cover full screen 120 gl.glViewport(0, 0, width, height ); 121 122 // Set up the projection matrix - choose perspective view 123 gl.glMatrixMode(GL.GL_PROJECTION); 124 gl.glLoadIdentity(); // reset 125 // Angle of view (fovy) is 45 degrees (in the up y-direction). Based on this 126 // canvas's aspect ratio. Clipping z-near is 0.1f and z-near is 100.0f. 127 //glu.gluPerspective(45.0f, aspect, 0.1f, 100.0f); // fovy, aspect, zNear, zFar 128 // Enable the model-view transform Pgina 2 72

ProyeccionesGeometricas.java 129 130 131 132 133 134 135 136 137 138 139 140 141 142

// gl.glOrtho(0, width, 0, height, -100.0, 100.0); gl.glFrustum( 0, 300, 0, 300, 1, 100 ); //glu.gluPerspective( 60, (double)width/(double)height, 0.1, 1000 ); //gl.glLoadIdentity(); // reset //glu.gluPerspective(60.0, width/ height,0.1, 30.0); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); // reset //canvas.repaint(); }

@Override public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { 143 // Not implemented in JOGL. 144 } 145 }

Pgina 3

You might also like