Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.sun.opengl.util.Animator;
- import java.awt.Frame;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- import javax.media.opengl.GL;
- import javax.media.opengl.GLAutoDrawable;
- import javax.media.opengl.GLCanvas;
- import javax.media.opengl.GLEventListener;
- import javax.media.opengl.glu.GLU;
- /**
- * Casa4.java <BR>
- * author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) <P>
- *
- * This version is equal to Brian Paul's version 1.2 1999/10/21
- */
- public class Casa4 implements GLEventListener {
- private float velRotacion = 0.0f;
- private float velEscalar=0.0f;
- private float velMover=0.0f;
- public static void main(String[] args) {
- Frame frame = new Frame("Simple JOGL Application");
- GLCanvas canvas = new GLCanvas();
- canvas.addGLEventListener(new Casa4());
- frame.add(canvas);
- frame.setSize(840, 680);
- final Animator animator = new Animator(canvas);
- frame.addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosing(WindowEvent e) {
- // Run this on another thread than the AWT event queue to
- // make sure the call to Animator.stop() completes before
- // exiting
- new Thread(new Runnable() {
- public void run() {
- animator.stop();
- System.exit(0);
- }
- }).start();
- }
- });
- // Center frame
- frame.setLocationRelativeTo(null);
- frame.setVisible(true);
- animator.start();
- }
- public void init(GLAutoDrawable drawable) {
- // Use debug pipeline
- // drawable.setGL(new DebugGL(drawable.getGL()));
- GL gl = drawable.getGL();
- System.err.println("INIT GL IS: " + gl.getClass().getName());
- // Enable VSync
- gl.setSwapInterval(1);
- // Setup the drawing area and shading mode
- gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- gl.glShadeModel(GL.GL_SMOOTH); // try setting this to GL_FLAT and see what happens.
- }
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
- GL gl = drawable.getGL();
- GLU glu = new GLU();
- if (height <= 0) { // avoid a divide by zero error!
- height = 1;
- }
- final float h = (float) width / (float) height;
- gl.glViewport(0, 0, width, height);
- gl.glMatrixMode(GL.GL_PROJECTION);
- gl.glLoadIdentity();
- glu.gluPerspective(50.0f, 5.0, 10.0, 120.0);
- gl.glMatrixMode(GL.GL_MODELVIEW);
- gl.glLoadIdentity();
- }
- public void display(GLAutoDrawable drawable) {
- GL gl = drawable.getGL();
- velRotacion += 2.0f;
- velEscalar+=0.1f;
- velMover+=2.0f;
- gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
- gl.glLoadIdentity();
- gl.glTranslatef(-65.0f, -14.0f, -60.0f);
- // gl.glTranslatef(velMover, 0.0f, 0.0f);
- //gl.glRotatef(velRotacion,0.0f,0.0f , -2.0f);
- gl.glScalef(velEscalar, velEscalar, velEscalar);
- gl.glBegin(GL.GL_LINES);//dibujar ejes
- gl.glColor3f(1.0F, 0.0f, 0.0f);
- gl.glVertex3f(250.0f, 0.0f, 0.0f); //inicia x
- gl.glVertex3f(-250.0f, 0.0f, 0.0f);
- gl.glVertex3f(0.0f, 250.0f, 0.0f); //inicia y
- gl.glVertex3f(0.0f, -250.0f, 0.0f);
- gl.glVertex3f(0.0f, 0.0f, 250.0f); //inicia z
- gl.glVertex3f(0.0f, 0.0f, -250.0f);
- gl.glEnd();
- //Lineas para acompletar la casa
- gl.glBegin(GL.GL_LINE_STRIP);
- gl.glVertex3f(40.0f, 20.0f, 0.0f);//C
- gl.glVertex3f(40.0f, 20.0f, 15.0f);//G
- gl.glEnd();
- gl.glBegin(GL.GL_LINE_STRIP);
- gl.glVertex3f(0.0f, 20.0f, 0.0f); //D
- gl.glVertex3f(0.0f, 20.0f, 15.0f); //H
- gl.glEnd();
- gl.glBegin(GL.GL_LINE_STRIP);
- gl.glVertex3f(0.0f, 0.0f, 0.0f); //A
- gl.glVertex3f(0.0f, 0.0f, 15.0f); //E
- gl.glEnd();
- gl.glBegin(GL.GL_LINE_STRIP);
- gl.glVertex3f(40.0f, 0.0f, 15.0f); //F
- gl.glVertex3f(40.0f, 0.0f, 0.0f); //B
- gl.glEnd();
- gl.glBegin(GL.GL_LINE_STRIP);
- gl.glVertex3f(10.0f, 10.0f, 20.0f); //I
- gl.glVertex3f(30.0f, 10.0f, 20.0f); //J
- gl.glEnd();
- //Puntos de la casa
- //Planta
- gl.glBegin(GL.GL_LINE_STRIP);
- gl.glVertex3f(0.0f, 0.0f, 0.0f); //A
- gl.glVertex3f(40.0f, 0.0f, 0.0f); //B
- gl.glVertex3f(40.0f, 20.0f, 0.0f); //C
- gl.glVertex3f(0.0f, 20.0f, 0.0f); //D
- gl.glVertex3f(0.0f, 0.0f, 0.0f); //A
- gl.glEnd();
- //Tejado
- gl.glBegin(GL.GL_LINE_STRIP);
- gl.glVertex3f(0.0f, 20.0f, 15.0f); //H
- gl.glVertex3f(0.0f, 0.0f, 15.0f); //E
- gl.glVertex3f(40.0f, 0.0f, 15.0f); //F
- gl.glVertex3f(40.0f, 20.0f, 15.0f); //G
- gl.glVertex3f(0.0f, 20.0f, 15.0f); //H
- gl.glEnd();
- //Aguas
- gl.glBegin(GL.GL_LINE_STRIP);
- gl.glVertex3f(0.0f, 20.0f, 15.0f); //H
- gl.glVertex3f(10.0f, 10.0f, 20.0f); //I
- gl.glVertex3f(0.0f, 0.0f, 15.0f); //E
- gl.glBegin(GL.GL_LINES);
- gl.glVertex3f(10.0f, 10.0f, 20.0f); //I
- gl.glVertex3f(30.0f, 10.0f, 20.0f); //J
- gl.glEnd();
- gl.glBegin(GL.GL_LINE_STRIP);
- gl.glVertex3f(40.0f, 20.0f, 15.0f); //G
- gl.glVertex3f(30.0f, 10.0f, 20.0f); //J
- gl.glVertex3f(40.0f, 0.0f, 15.0f); //F
- gl.glEnd();
- //Puerta
- gl.glBegin(GL.GL_LINE_STRIP);
- gl.glVertex3f(0.0f, 8.0f, 0.0f); //k
- gl.glVertex3f(0.0f, 8.0f, 5.0f); //L
- gl.glVertex3f(0.0f, 12.0f, 5.0f); //M
- gl.glVertex3f(0.0f, 12.0f, 0.0f); //N
- gl.glVertex3f(0.0f, 8.0f, 0.0f); //K
- gl.glEnd();
- //Ventana
- gl.glBegin(GL.GL_LINE_STRIP);
- gl.glVertex3f(12.0f, 0.0f, 9.0f); //O
- gl.glVertex3f(24.0f, 0.0f, 9.0f); //P
- gl.glVertex3f(24.0f, 0.0f, 12.0f); //Q
- gl.glVertex3f(12.0f, 0.0f, 12.0f); //R
- gl.glVertex3f(12.0f, 0.0f, 9.0f); //O
- gl.glTranslatef(20f, 0.0f, 0.0f);
- gl.glEnd();
- gl.glFlush();
- }
- public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement