Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.media.opengl.*;
- import javax.media.opengl.awt.GLCanvas;
- import javax.media.opengl.glu.*;
- import com.sun.opengl.util.Animator;
- import com.sun.opengl.util.FPSAnimator;
- public class Object3D implements GLEventListener, KeyListener {
- float a=10;
- float b=10;
- float c=10;
- float d=0;
- float e=0;
- float f=0;
- float g=0;
- float h=1;
- float i=0;
- GLProfile glp;
- GLCapabilities caps;
- GLCanvas canvas;
- GLU glu;
- Boolean rotating = false;
- public Object3D()
- {
- glp = GLProfile.getDefault();
- caps = new GLCapabilities(glp);
- canvas = new GLCanvas(caps);
- // the camera
- glu = new GLU();
- Frame frame = new Frame("AWT Window Test");
- frame.setSize(400, 400);
- frame.add(canvas);
- frame.setVisible(true);
- frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- System.exit(0);
- }
- });
- canvas.addGLEventListener(this);
- canvas.addKeyListener(this);
- canvas.requestFocus();
- Animator animator = new FPSAnimator(canvas,60);
- animator.add(canvas);
- animator.start();
- }
- public static void main(String[] args) {
- Object3D obj3d = new Object3D();
- }
- }
- @Override
- public void display(GLAutoDrawable drawable) {
- GL2 gl = drawable.getGL().getGL2();
- GLU glu = new GLU();
- gl.glClear(GL.GL_COLOR_BUFFER_BIT);
- //make sure we are in model_view mode
- gl.glMatrixMode(GL2.GL_MODELVIEW);
- gl.glLoadIdentity();
- glu.gluLookAt(a,b,c,d,e,f,g, h, i);
- gl.glColor3f(1, 1, 1);
- // build the house thing here
- gl.glBegin(gl.GL_LINE_LOOP);
- gl.glVertex3f(3,4,3);
- gl.glVertex3f(-3,4,3);
- gl.glVertex3f(-3,0,3);
- gl.glVertex3f(3,0,3);
- gl.glEnd();
- gl.glBegin(gl.GL_LINE_LOOP);
- gl.glVertex3f(3,4,-1);
- gl.glVertex3f(-3,4,-1);
- gl.glVertex3f(-3,0,-1);
- gl.glVertex3f(3,0,-1);
- gl.glEnd();
- gl.glBegin(gl.GL_LINE_LOOP);
- gl.glVertex3f(3,0,-1);
- gl.glVertex3f(3,0,3);
- gl.glEnd();
- gl.glBegin(gl.GL_LINE_LOOP);
- gl.glVertex3f(-3,4,3);
- gl.glVertex3f(-3,4,-1);
- gl.glEnd();
- gl.glBegin(gl.GL_LINE_LOOP);
- gl.glVertex3f(-3,0,3);
- gl.glVertex3f(-3,0,-1);
- gl.glEnd();
- gl.glBegin(gl.GL_LINE_LOOP);
- gl.glVertex3f(3,4,-1);
- gl.glVertex3f(3,4,3);
- gl.glEnd();
- }
- public void update(GLAutoDrawable drawable)
- {
- }
- @Override
- public void dispose(GLAutoDrawable drawable) {
- // TODO Auto-generated method stub
- }
- @Override
- public void init(GLAutoDrawable drawable) {
- // TODO Auto-generated method stub
- GL2 gl = drawable.getGL().getGL2();
- gl.glMatrixMode(gl.GL_PROJECTION);
- gl.glLoadIdentity();
- gl.glOrtho(0, 300, 0, 300, -1, 1);
- gl.glViewport(0, 0, 400, 400);
- }
- @Override
- public void reshape(GLAutoDrawable drawable, int x, int y, int width,
- int height) {
- // TODO Auto-generated method stub
- GL2 gl = drawable.getGL().getGL2();
- GLU glu = new GLU();
- if (height < 1) { // avoid a divide by zero error!
- height = 1;
- }
- float aspect = (float) width / (float) height;
- gl.glViewport(0, 0, width, height);
- //set up the camera
- gl.glMatrixMode(gl.GL_PROJECTION);
- gl.glLoadIdentity();
- glu.gluPerspective(45.0f, aspect, 1.0, 30.0);
- }
- @Override
- public void keyPressed(KeyEvent arg0) {
- // TODO Auto-generated method stub
- }
- @Override
- public void keyReleased(KeyEvent arg0) {
- // TODO Auto-generated method stub
- }
- @Override
- public void keyTyped(KeyEvent arg0) {
- // TODO Auto-generated method stub
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement