1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
| public class ArtLab implements GLEventListener{ private float LOOK_AT_DIST = 100.0f; private final static float FOV = 45.0f; private final static float DEFAULT_ART_SIZE = 10.0f; private final static float CAMERA_MOVEMENT_INCREMENT = 0.2f; private GL gl; private GLU glu = new GLU(); private Point3D CameraLook = new Point3D(0.0f, 1.0f, 0.0f); private Point3D Camera = new Point3D(5.0f, 5.0f, 10.0f, 0,270,0);
private Point3D standAloneCamera = standAloneCameraReset; private LinkedList <Plane> walls = new LinkedList <Plane> (); private Plane floor = null; private Plane ceiling = null; private LinkedList <Art> artThumbNails = new LinkedList <Art> (); private Art standAlone = null; private HeadsUpDisplay cursor = new HeadsUpDisplay(0.50f, 0.50f, 0.064f, 0.128f); private int room; private int art; private ArtLabAppletLaunch artLabTOP;
private int lastSelectedImage = -1, galleryImage = -1; private boolean inGallery = true; private boolean hasResetCamera = false; public ArtLab(ArtLabAppletLaunch cg) { cg.addKeyListener(new KeyboardListenerInterface() { public void buttonPressed(int i){handleKeyboardInput(i);} }); artLabTOP = cg; } public void init(GLAutoDrawable drawable) { gl = drawable.getGL(); gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); gl.glEnable(GL.GL_DEPTH_TEST); gl.glClearDepth(1.0f); gl.glDepthFunc(GL.GL_LEQUAL); gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); updateCamera(); walls.add(new Plane(15f, 5.0f, 0f, 30.0f, 10.0f, 0.0f)); walls.add(new Plane(15f, 5.0f, 30f, 30.0f, 10.0f, 0.0f)); walls.add(new Plane(0f, 5.0f, 15f, 0.0f, 10.0f, 30.0f)); walls.add(new Plane(30f, 5.0f, 15f, 0.0f, 10.0f, 30.0f)); floor = new Plane(15f, 0.0f, 15f, 30.0f, 0.0f, 30.0f); ceiling = new Plane(15f, 10.0f, 15f, 30.0f, 0.0f, 30.0f); artThumbNails.add(new Art(15f, 5.0f, 0.2f, 5.0f, 4.5f, 0.0f)); standAlone = new Art(0.0f, 5.0f, 0f, 5.0f, 5.0f, 0.0f);
room = gl.glGenLists(1); art = gl.glGenLists(2); gl.glNewList(room, GL.GL_COMPILE); for(int index = 0; index < walls.size(); index++){ gl.glPushMatrix(); gl.glTranslatef(walls.get(index).X, walls.get(index).Y, walls.get(index).Z); walls.get(index).draw(gl); gl.glPopMatrix(); } gl.glPushMatrix(); gl.glTranslatef(floor.X, floor.Y, floor.Z); floor.draw(gl); gl.glPopMatrix(); gl.glPushMatrix(); gl.glTranslatef(ceiling.X, ceiling.Y, ceiling.Z); ceiling.draw(gl); gl.glPopMatrix(); gl.glEndList(); gl.glNewList(art, GL.GL_COMPILE); for(int index = 0; index < artThumbNails.size(); index++){ gl.glPushMatrix(); gl.glTranslatef(artThumbNails.get(index).X, artThumbNails.get(index).Y,artThumbNails.get(index).Z); artThumbNails.get(index).draw(gl); gl.glPopMatrix(); } gl.glEndList(); } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { GL gl = drawable.getGL(); if (height == 0){height = 1;} gl.glViewport(x, y, width, height); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(FOV, (float)width/(float)height, 1, LOOK_AT_DIST);
gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); } public void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity();
if(inGallery){ glu.gluLookAt(Camera.X, Camera.Y, Camera.Z, CameraLook.X, CameraLook.Y, CameraLook.Z, 0,1,0); gl.glCallList(room); gl.glCallList(art); begin2D(); gl.glPushMatrix(); cursor.draw(gl); gl.glPopMatrix(); end2D(); } else { glu.gluLookAt(standAloneCamera.X, standAloneCamera.Y, standAloneCamera.Z, CameraLook.X, CameraLook.Y, CameraLook.Z, 0,1,0); gl.glPushMatrix(); gl.glTranslatef(standAlone.X, standAlone.Y, standAlone.Z); standAlone.drawBigArt(gl); gl.glPopMatrix(); } gl.glFlush(); } private void begin2D() { gl.glMatrixMode(GL.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glOrtho(0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glDisable(GL.GL_DEPTH_TEST); gl.glDisable(GL.GL_LIGHTING); } private void end2D() { gl.glEnable(GL.GL_LIGHTING); gl.glEnable(GL.GL_DEPTH_TEST); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPopMatrix(); } } |