Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.58 KB | None | 0 0
  1. import com.sun.opengl.util.Animator;
  2. import java.awt.Frame;
  3. import java.awt.event.WindowAdapter;
  4. import java.awt.event.WindowEvent;
  5. import javax.media.opengl.GL;
  6. import javax.media.opengl.GLAutoDrawable;
  7. import javax.media.opengl.GLCanvas;
  8. import javax.media.opengl.GLEventListener;
  9. import javax.media.opengl.glu.GLU;
  10.  
  11.  
  12.  
  13. /**
  14. * Casa4.java <BR>
  15. * author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) <P>
  16. *
  17. * This version is equal to Brian Paul's version 1.2 1999/10/21
  18. */
  19. public class Casa4 implements GLEventListener {
  20. private float velRotacion = 0.0f;
  21. private float velEscalar=0.0f;
  22. private float velMover=0.0f;
  23. public static void main(String[] args) {
  24. Frame frame = new Frame("Simple JOGL Application");
  25. GLCanvas canvas = new GLCanvas();
  26.  
  27. canvas.addGLEventListener(new Casa4());
  28. frame.add(canvas);
  29. frame.setSize(840, 680);
  30. final Animator animator = new Animator(canvas);
  31. frame.addWindowListener(new WindowAdapter() {
  32.  
  33. @Override
  34. public void windowClosing(WindowEvent e) {
  35. // Run this on another thread than the AWT event queue to
  36. // make sure the call to Animator.stop() completes before
  37. // exiting
  38. new Thread(new Runnable() {
  39.  
  40. public void run() {
  41. animator.stop();
  42. System.exit(0);
  43. }
  44. }).start();
  45. }
  46. });
  47. // Center frame
  48. frame.setLocationRelativeTo(null);
  49. frame.setVisible(true);
  50. animator.start();
  51. }
  52.  
  53. public void init(GLAutoDrawable drawable) {
  54. // Use debug pipeline
  55. // drawable.setGL(new DebugGL(drawable.getGL()));
  56.  
  57. GL gl = drawable.getGL();
  58. System.err.println("INIT GL IS: " + gl.getClass().getName());
  59.  
  60. // Enable VSync
  61. gl.setSwapInterval(1);
  62.  
  63. // Setup the drawing area and shading mode
  64. gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  65. gl.glShadeModel(GL.GL_SMOOTH); // try setting this to GL_FLAT and see what happens.
  66. }
  67.  
  68. public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
  69. GL gl = drawable.getGL();
  70. GLU glu = new GLU();
  71.  
  72. if (height <= 0) { // avoid a divide by zero error!
  73.  
  74. height = 1;
  75. }
  76. final float h = (float) width / (float) height;
  77. gl.glViewport(0, 0, width, height);
  78. gl.glMatrixMode(GL.GL_PROJECTION);
  79. gl.glLoadIdentity();
  80. glu.gluPerspective(50.0f, 5.0, 10.0, 120.0);
  81. gl.glMatrixMode(GL.GL_MODELVIEW);
  82. gl.glLoadIdentity();
  83.  
  84. }
  85.  
  86. public void display(GLAutoDrawable drawable) {
  87. GL gl = drawable.getGL();
  88. velRotacion += 2.0f;
  89. velEscalar+=0.1f;
  90. velMover+=2.0f;
  91. gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
  92.  
  93. gl.glLoadIdentity();
  94.  
  95. gl.glTranslatef(-65.0f, -14.0f, -60.0f);
  96. // gl.glTranslatef(velMover, 0.0f, 0.0f);
  97. //gl.glRotatef(velRotacion,0.0f,0.0f , -2.0f);
  98. gl.glScalef(velEscalar, velEscalar, velEscalar);
  99. gl.glBegin(GL.GL_LINES);//dibujar ejes
  100. gl.glColor3f(1.0F, 0.0f, 0.0f);
  101. gl.glVertex3f(250.0f, 0.0f, 0.0f); //inicia x
  102. gl.glVertex3f(-250.0f, 0.0f, 0.0f);
  103. gl.glVertex3f(0.0f, 250.0f, 0.0f); //inicia y
  104. gl.glVertex3f(0.0f, -250.0f, 0.0f);
  105. gl.glVertex3f(0.0f, 0.0f, 250.0f); //inicia z
  106. gl.glVertex3f(0.0f, 0.0f, -250.0f);
  107. gl.glEnd();
  108.  
  109. //Lineas para acompletar la casa
  110. gl.glBegin(GL.GL_LINE_STRIP);
  111. gl.glVertex3f(40.0f, 20.0f, 0.0f);//C
  112. gl.glVertex3f(40.0f, 20.0f, 15.0f);//G
  113. gl.glEnd();
  114.  
  115. gl.glBegin(GL.GL_LINE_STRIP);
  116.  
  117. gl.glVertex3f(0.0f, 20.0f, 0.0f); //D
  118. gl.glVertex3f(0.0f, 20.0f, 15.0f); //H
  119. gl.glEnd();
  120.  
  121. gl.glBegin(GL.GL_LINE_STRIP);
  122.  
  123. gl.glVertex3f(0.0f, 0.0f, 0.0f); //A
  124. gl.glVertex3f(0.0f, 0.0f, 15.0f); //E
  125. gl.glEnd();
  126.  
  127. gl.glBegin(GL.GL_LINE_STRIP);
  128.  
  129. gl.glVertex3f(40.0f, 0.0f, 15.0f); //F
  130. gl.glVertex3f(40.0f, 0.0f, 0.0f); //B
  131. gl.glEnd();
  132.  
  133. gl.glBegin(GL.GL_LINE_STRIP);
  134.  
  135. gl.glVertex3f(10.0f, 10.0f, 20.0f); //I
  136. gl.glVertex3f(30.0f, 10.0f, 20.0f); //J
  137. gl.glEnd();
  138.  
  139. //Puntos de la casa
  140. //Planta
  141. gl.glBegin(GL.GL_LINE_STRIP);
  142.  
  143. gl.glVertex3f(0.0f, 0.0f, 0.0f); //A
  144. gl.glVertex3f(40.0f, 0.0f, 0.0f); //B
  145. gl.glVertex3f(40.0f, 20.0f, 0.0f); //C
  146. gl.glVertex3f(0.0f, 20.0f, 0.0f); //D
  147. gl.glVertex3f(0.0f, 0.0f, 0.0f); //A
  148. gl.glEnd();
  149.  
  150. //Tejado
  151. gl.glBegin(GL.GL_LINE_STRIP);
  152.  
  153. gl.glVertex3f(0.0f, 20.0f, 15.0f); //H
  154. gl.glVertex3f(0.0f, 0.0f, 15.0f); //E
  155. gl.glVertex3f(40.0f, 0.0f, 15.0f); //F
  156. gl.glVertex3f(40.0f, 20.0f, 15.0f); //G
  157. gl.glVertex3f(0.0f, 20.0f, 15.0f); //H
  158. gl.glEnd();
  159.  
  160. //Aguas
  161. gl.glBegin(GL.GL_LINE_STRIP);
  162.  
  163. gl.glVertex3f(0.0f, 20.0f, 15.0f); //H
  164. gl.glVertex3f(10.0f, 10.0f, 20.0f); //I
  165. gl.glVertex3f(0.0f, 0.0f, 15.0f); //E
  166. gl.glBegin(GL.GL_LINES);
  167.  
  168. gl.glVertex3f(10.0f, 10.0f, 20.0f); //I
  169. gl.glVertex3f(30.0f, 10.0f, 20.0f); //J
  170. gl.glEnd();
  171. gl.glBegin(GL.GL_LINE_STRIP);
  172.  
  173. gl.glVertex3f(40.0f, 20.0f, 15.0f); //G
  174. gl.glVertex3f(30.0f, 10.0f, 20.0f); //J
  175. gl.glVertex3f(40.0f, 0.0f, 15.0f); //F
  176. gl.glEnd();
  177.  
  178. //Puerta
  179. gl.glBegin(GL.GL_LINE_STRIP);
  180.  
  181. gl.glVertex3f(0.0f, 8.0f, 0.0f); //k
  182. gl.glVertex3f(0.0f, 8.0f, 5.0f); //L
  183. gl.glVertex3f(0.0f, 12.0f, 5.0f); //M
  184. gl.glVertex3f(0.0f, 12.0f, 0.0f); //N
  185. gl.glVertex3f(0.0f, 8.0f, 0.0f); //K
  186. gl.glEnd();
  187.  
  188. //Ventana
  189. gl.glBegin(GL.GL_LINE_STRIP);
  190.  
  191. gl.glVertex3f(12.0f, 0.0f, 9.0f); //O
  192. gl.glVertex3f(24.0f, 0.0f, 9.0f); //P
  193. gl.glVertex3f(24.0f, 0.0f, 12.0f); //Q
  194. gl.glVertex3f(12.0f, 0.0f, 12.0f); //R
  195. gl.glVertex3f(12.0f, 0.0f, 9.0f); //O
  196. gl.glTranslatef(20f, 0.0f, 0.0f);
  197. gl.glEnd();
  198.  
  199. gl.glFlush();
  200.  
  201. }
  202.  
  203.  
  204. public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
  205. }
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement