+ protected synchronized void updateVisibility(GL gl) {
+ IntBuffer buf = ByteBuffer.allocateDirect(9*4*4).order(ByteOrder.nativeOrder()).asIntBuffer();
+ gl.glFlush();
+ gl.glDrawBuffer(GL.GL_BACK);
+ gl.glReadBuffer(GL.GL_BACK);
+ gl.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1);
+ gl.glFlush();
+ gl.glDisable(GL.GL_LIGHTING);
+ gl.glShadeModel(GL.GL_FLAT);
+ gl.glColor3f(0,0,0);
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+ for(Mesh mesh : meshes) mesh.render(gl, Matrix.ONE);
+ for(Mesh mesh : meshes)
+ if (mesh.option_selectable)
+ for(Mesh.Vertex v : mesh.vertices()) {
+ Point p = v.getPoint();
+ gl.glColor3f(1,1,1);
+ gl.glBegin(gl.GL_POINTS);
+ p.glVertex(gl);
+ gl.glEnd();
+ gl.glFlush();
+
+ Point projected = projection.times(p);
+ gl.glReadPixels((int)projected.x-1, (int)projected.y-1, 3, 3, gl.GL_RGB, gl.GL_UNSIGNED_BYTE, buf);
+
+ boolean vis = false;
+ for(int j=0; j<9*4; j++) vis |= buf.get(j)!=0;
+ v.visible = vis;
+ if (vis) {
+ gl.glColor3f(0,0,0);
+ gl.glBegin(gl.GL_POINTS);
+ p.glVertex(gl);
+ gl.glEnd();
+ }
+ }
+ gl.glShadeModel(GL.GL_SMOOTH);
+ gl.glEnable(GL.GL_LIGHTING);
+ gl.glDrawBuffer(GL.GL_FRONT);
+ }
+
+ /** return the position of the mouse as a point in window-space */
+ public Point getMouse() {
+ return new Point(mousex, glcanvas.getHeight()-mousey, 0);
+ }
+
+ /** return the position where the mouse button was pressed, or null if it is not currently pressed */
+ public Point getMouseClick() {
+ return clickPoint;
+ }
+
+ public void mouseWheelMoved(MouseWheelEvent e) {
+ tz -= e.getWheelRotation();
+ }
+
+ public void keyTyped(KeyEvent e) { }
+ public void keyPressed(KeyEvent e) { }
+ public void keyReleased(KeyEvent e) { }
+
+ public void mouseClicked(MouseEvent e) { }
+ public void mouseEntered(MouseEvent e) { mouseInside = true; }
+ public void mouseExited(MouseEvent e) { mouseInside = false; }
+ public void mousePressed(MouseEvent e) {
+ clickPoint = getMouse();
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ clickPoint = null;
+ }
+
+ public void mouseMoved(MouseEvent e) {
+ mousex = e.getX();
+ mousey = e.getY();
+ if ((e.getModifiersEx() & MouseEvent.SHIFT_DOWN_MASK) != 0)
+ updateVisibilities = true;
+ }
+
+ public void mouseDragged(MouseEvent e) {
+ if ((e.getModifiersEx() & MouseEvent.SHIFT_DOWN_MASK) != 0) {
+ if (closest != null && projection != null) {
+ synchronized(this) {
+ if (closestOriginallyAt==null) closestOriginallyAt = closest.getPoint();
+ Vec d1 = projection.inverse().times(getMouse()).minus(projection.inverse().times(clickPoint));
+ Vec delta = d1.plus(closestOriginallyAt).minus(closest.getPoint());
+ closest.move(delta, false);
+ }
+ }
+ } else {
+ anglex -= mousex - e.getX();
+ angley += mousey - e.getY();
+ }
+ mousex = e.getX();
+ mousey = e.getY();
+ }