Import Com
Import Com
Import Com
GL2 ;
Import com.jogamp.opengl.GLAutoDrawable ;
Import com.jogamp.opengl.GLCapabilities ;
Import com.jogamp.opengl.GLEventListener ;
Import com.jogamp.opengl.GLProfile ;
Import com.jogamp.opengl.awt.GLCanvas ;
Import com.jogamp.opengl.glu.GLU ;
Import com.jogamp.opengl.util.Animator ;
Import com.jogamp.opengl.util.gl2.GLUT ;
Import java.awt.Frame ;
Import java.awt.event.WindowAdapter ;
Import java.awt.event.WindowEvent ;
canvas.addGLEventListener(reloj);
frame.add(canvas);
frame.setSize(640,480);
final Animator animator = new Animator(canvas);
frame.addWindowListener(newWindowAdapter(){
@Override
Public void windowClosing(WindowEvent e){
New Thread(new Runnable(){
Public void run(){
animator.stop();
System.exit(0);
}
}).start();
}
});
frame.setLocationRelativeTo(null);
frame.setVisible(true);
animator.start();
}
Public void init(GLAutoDrawable drawable){
GL2 gl = drawable.getGL().getGL2();
glut = new GLUT();
gl.setSwapInterval(1);
gl.glClearColor(0.5f,0.5f,0.5f,0.0f);// Fondo gris (R, G, B, A)
gl.glShadeModel(GL2.GL_SMOOTH);
}
Public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height){
GL2 gl = drawable.getGL().getGL2();
GLU glu = new GLU();
if(height <=0){ height =1; } finalfloath =(float)width /(float)height;
gl.glViewport(0,0,width,height); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity();
glu.gluPerspective(45.0f,h,1.0,20.0); gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity(); } publicvoiddisplay(GLAutoDrawable drawable){ GL2 gl
=drawable.getGL().getGL2(); gl.glClear(GL2.GL_COLOR_BUFFER_BIT |
GL2.GL_DEPTH_BUFFER_BIT); gl.glClearColor(0.5f,0.5f,0.5f,0.0f); TEMA 3 -Actividades ©
Universidad Internacional de La Rioja (UNIR)
AsignaturaDatos del alumnoFecha InformáticaGráfica yVisualizaciónApellidos: Diaz Hernandez
06/11/2023 Nombre: Jorge Alberto gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity(); gl.glLoadIdentity(); gl.glTranslatef(-1.5f,0.0f,-6.0f);
gl.glColor3f(1.0f,1.0f,1.0f); gl.glLineWidth(3.0f); gl.glBegin(GL2.GL_LINE_LOOP); for(inti =0;i
<360;i++){ doubletheta =2.0*Math.PI *i /360.0; doublex =Math.cos(theta); doubley
=Math.sin(theta); gl.glVertex2d(x,y); } gl.glEnd(); gl.glLineWidth(2.0f);
gl.glBegin(GL2.GL_LINES); for(inti =0;i <12;i++){ doubletheta =2.0*Math.PI *i /12.0; doublex
=0.8*Math.cos(theta); doubley =0.8*Math.sin(theta); gl.glVertex2d(x,y);
gl.glVertex2d(0.9*x,0.9*y); } gl.glEnd(); for(inti =1;i <=12;i++){ doubletheta =2.0*Math.PI *i
/12.0; doublex =0.85*Math.cos(theta); doubley =0.85*Math.sin(theta); drawRhombs(gl,i,(float)x,
(float)y); } gl.glPushMatrix();// Guarda la matriz de modelo/vista // Dibuja las manecillas después
del fondo gl.glLineWidth(2.0f); gl.glRotatef(30.0f,0.0f,0.0f,1.0f);// Gira 30 grados cada hora
gl.glBegin(GL2.GL_LINES); drawHand(gl,0.5f,0.0f,0.0f);// Manecilla de las horas gl.glEnd();
gl.glPopMatrix();// Restaura la matriz de modelo/vista gl.glPushMatrix();// Guarda la matriz de
modelo/vista gl.glRotatef(6.0f,0.0f,0.0f,1.0f);// Gira 6 grados cada minuto
gl.glBegin(GL2.GL_LINES); drawHand(gl,0.8f,0.0f,0.0f);// Manecilla de los minutos gl.glEnd();
gl.glPopMatrix();// Restaura la matriz de modelo/vista gl.glPushMatrix();// Guarda la matriz de
modelo/vista gl.glRotatef(6.0f,0.0f,0.0f,1.0f);// Gira 6 grados cada segundo
gl.glBegin(GL2.GL_LINES); drawHand(gl,0.9f,-0.3f,0.0f);// Manecilla de los segundos gl.glEnd();
gl.glPopMatrix();// Restaura la matriz de modelo/vista gl.glFlush(); }
publicvoiddisplayChanged(GLAutoDrawable drawable,booleanmodeChanged,
booleandeviceChanged){ } @Override publicvoiddispose(GLAutoDrawable glad){ }
privatevoiddrawRhombs(GL2 gl,intnumber,floatx,floaty){ TEMA 3 -Actividades © Universidad
Internacional de La Rioja (UNIR)
AsignaturaDatos del alumnoFecha InformáticaGráfica yVisualizaciónApellidos: Diaz Hernandez
06/11/2023 Nombre: Jorge Alberto gl.glBegin(GL2.GL_POLYGON); gl.glVertex2f(x -0.03f,y);
gl.glVertex2f(x,y +0.03f); gl.glVertex2f(x +0.03f,y); gl.glVertex2f(x,y -0.03f); gl.glEnd(); }
privatevoiddrawHand(GL2 gl,floatx,floaty,floatz){ gl.glVertex3f(x,y,z);
gl.glVertex3f(0.0f,0.0f,0.0f); } }