Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3.  
  4. import javax.media.opengl.*;
  5. import javax.media.opengl.awt.GLCanvas;
  6. import javax.media.opengl.glu.*;
  7.  
  8. import com.sun.opengl.util.Animator;
  9. import com.sun.opengl.util.FPSAnimator;
  10.  
  11.  
  12. public class Object3D implements GLEventListener, KeyListener {
  13. float a=10;
  14. float b=10;
  15. float c=10;
  16. float d=0;
  17. float e=0;
  18. float f=0;
  19. float g=0;
  20. float h=1;
  21. float i=0;
  22. GLProfile glp;
  23. GLCapabilities caps;
  24. GLCanvas canvas;
  25. GLU glu;
  26. Boolean rotating = false;
  27.  
  28. public Object3D()
  29. {
  30. glp = GLProfile.getDefault();
  31. caps = new GLCapabilities(glp);
  32. canvas = new GLCanvas(caps);
  33. // the camera
  34. glu = new GLU();
  35.  
  36. Frame frame = new Frame("AWT Window Test");
  37. frame.setSize(400, 400);
  38. frame.add(canvas);
  39. frame.setVisible(true);
  40.  
  41. frame.addWindowListener(new WindowAdapter() {
  42. public void windowClosing(WindowEvent e) {
  43. System.exit(0);
  44. }
  45. });
  46.  
  47. canvas.addGLEventListener(this);
  48. canvas.addKeyListener(this);
  49. canvas.requestFocus();
  50. Animator animator = new FPSAnimator(canvas,60);
  51. animator.add(canvas);
  52. animator.start();
  53.  
  54. }
  55.  
  56. public static void main(String[] args) {
  57.  
  58. Object3D obj3d = new Object3D();
  59.  
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  
  66. }
  67. @Override
  68. public void display(GLAutoDrawable drawable) {
  69. GL2 gl = drawable.getGL().getGL2();
  70. GLU glu = new GLU();
  71. gl.glClear(GL.GL_COLOR_BUFFER_BIT);
  72.  
  73.  
  74. //make sure we are in model_view mode
  75. gl.glMatrixMode(GL2.GL_MODELVIEW);
  76. gl.glLoadIdentity();
  77.  
  78. glu.gluLookAt(a,b,c,d,e,f,g, h, i);
  79.  
  80. gl.glColor3f(1, 1, 1);
  81. // build the house thing here
  82. gl.glBegin(gl.GL_LINE_LOOP);
  83. gl.glVertex3f(3,4,3);
  84. gl.glVertex3f(-3,4,3);
  85. gl.glVertex3f(-3,0,3);
  86. gl.glVertex3f(3,0,3);
  87. gl.glEnd();
  88. gl.glBegin(gl.GL_LINE_LOOP);
  89. gl.glVertex3f(3,4,-1);
  90. gl.glVertex3f(-3,4,-1);
  91. gl.glVertex3f(-3,0,-1);
  92. gl.glVertex3f(3,0,-1);
  93. gl.glEnd();
  94. gl.glBegin(gl.GL_LINE_LOOP);
  95. gl.glVertex3f(3,0,-1);
  96. gl.glVertex3f(3,0,3);
  97. gl.glEnd();
  98. gl.glBegin(gl.GL_LINE_LOOP);
  99. gl.glVertex3f(-3,4,3);
  100. gl.glVertex3f(-3,4,-1);
  101. gl.glEnd();
  102. gl.glBegin(gl.GL_LINE_LOOP);
  103. gl.glVertex3f(-3,0,3);
  104. gl.glVertex3f(-3,0,-1);
  105. gl.glEnd();
  106. gl.glBegin(gl.GL_LINE_LOOP);
  107. gl.glVertex3f(3,4,-1);
  108. gl.glVertex3f(3,4,3);
  109. gl.glEnd();
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116. }
  117.  
  118.  
  119. public void update(GLAutoDrawable drawable)
  120. {
  121.  
  122.  
  123. }
  124.  
  125.  
  126.  
  127.  
  128.  
  129. @Override
  130. public void dispose(GLAutoDrawable drawable) {
  131. // TODO Auto-generated method stub
  132.  
  133. }
  134.  
  135. @Override
  136. public void init(GLAutoDrawable drawable) {
  137. // TODO Auto-generated method stub
  138. GL2 gl = drawable.getGL().getGL2();
  139. gl.glMatrixMode(gl.GL_PROJECTION);
  140. gl.glLoadIdentity();
  141. gl.glOrtho(0, 300, 0, 300, -1, 1);
  142. gl.glViewport(0, 0, 400, 400);
  143.  
  144. }
  145.  
  146. @Override
  147. public void reshape(GLAutoDrawable drawable, int x, int y, int width,
  148. int height) {
  149. // TODO Auto-generated method stub
  150. GL2 gl = drawable.getGL().getGL2();
  151. GLU glu = new GLU();
  152.  
  153. if (height < 1) { // avoid a divide by zero error!
  154. height = 1;
  155. }
  156.  
  157. float aspect = (float) width / (float) height;
  158. gl.glViewport(0, 0, width, height);
  159. //set up the camera
  160. gl.glMatrixMode(gl.GL_PROJECTION);
  161. gl.glLoadIdentity();
  162.  
  163. glu.gluPerspective(45.0f, aspect, 1.0, 30.0);
  164.  
  165. }
  166.  
  167. @Override
  168. public void keyPressed(KeyEvent arg0) {
  169. // TODO Auto-generated method stub
  170.  
  171. }
  172.  
  173. @Override
  174. public void keyReleased(KeyEvent arg0) {
  175. // TODO Auto-generated method stub
  176.  
  177. }
  178.  
  179. @Override
  180. public void keyTyped(KeyEvent arg0) {
  181. // TODO Auto-generated method stub
  182.  
  183. }
  184.  
  185.  
  186.  
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement