📄 polyhedralboundedsolidexample.java
字号:
gl.glPushAttrib(gl.GL_DEPTH_TEST); gl.glDisable(gl.GL_DEPTH_TEST); gl.glLineWidth(4.0f); gl.glColor3d(0, 0, 0); gl.glBegin(gl.GL_LINES); for ( i = 0; i < contourLines.size(); i++ ) { p = contourLines.get(i); gl.glVertex3d(p.x, p.y, p.z); } gl.glEnd(); gl.glLineWidth(4.0f); gl.glColor3d(0, 0, 0); gl.glBegin(gl.GL_LINES); for ( i = 0; i < visibleLines.size(); i++ ) { p = visibleLines.get(i); gl.glVertex3d(p.x, p.y, p.z); } gl.glEnd();/* gl.glLineWidth(1.0f); gl.glColor3d(0, 0, 0); gl.glBegin(gl.GL_LINES); for ( i = 0; i < hiddenLines.size(); i++ ) { p = hiddenLines.get(i); gl.glVertex3d(p.x, p.y, p.z); } gl.glEnd();*/ gl.glPopAttrib(); } private void drawObjectsGL(GL gl) { gl.glLoadIdentity(); //----------------------------------------------------------------- gl.glDisable(gl.GL_LIGHTING); gl.glLineWidth((float)3.0); if ( edgeIndex > -3 && showCoordinateSystem ) { gl.glBegin(GL.GL_LINES); gl.glColor3d(1, 0, 0); gl.glVertex3d(0, 0, 0); gl.glVertex3d(1, 0, 0); gl.glColor3d(0, 1, 0); gl.glVertex3d(0, 0, 0); gl.glVertex3d(0, 1, 0); gl.glColor3d(0, 0, 1); gl.glVertex3d(0, 0, 0); gl.glVertex3d(0, 0, 1); gl.glEnd(); } //----------------------------------------------------------------- JoglMaterialRenderer.activate(gl, material); JoglLightRenderer.activate(gl, light1); JoglLightRenderer.draw(gl, light1); JoglLightRenderer.activate(gl, light2); JoglLightRenderer.draw(gl, light2); gl.glEnable(gl.GL_LIGHTING); JoglPolyhedralBoundedSolidRenderer.draw(gl, solid, camera, quality); JoglPolyhedralBoundedSolidRenderer.drawDebugFaceBoundary(gl, solid, faceIndex); JoglPolyhedralBoundedSolidRenderer.drawDebugFace(gl, solid, faceIndex); //----------------------------------------------------------------- ArrayList <Vector3D> contourLines; ArrayList <Vector3D> visibleLines; ArrayList <Vector3D> hiddenLines; ArrayList <SimpleBody> bodyArray; SimpleBody body; if ( debugEdges && edgeIndex > -3 ) { JoglPolyhedralBoundedSolidRenderer.drawDebugEdges(gl, solid, camera, edgeIndex); } else if ( edgeIndex == -3 ) { contourLines = new ArrayList <Vector3D>(); visibleLines = new ArrayList <Vector3D>(); hiddenLines = new ArrayList <Vector3D>(); bodyArray = new ArrayList <SimpleBody>(); body = new SimpleBody(); body.setGeometry(solid); body.setPosition(new Vector3D()); body.setRotation(new Matrix4x4()); body.setRotationInverse(new Matrix4x4()); bodyArray.add(body); HiddenLineRenderer.executeAppelAlgorithm(bodyArray, camera, contourLines, visibleLines, hiddenLines); renderLinesResult(gl, contourLines, visibleLines, hiddenLines); } contourLines = null; visibleLines = null; hiddenLines = null; bodyArray = null; body = null; } /** Called by drawable to initiate drawing */ public void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); gl.glClearColor(0.5f, 0.5f, 0.5f, 1); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glColor3d(1, 1, 1); gl.glEnable(gl.GL_DEPTH_TEST); JoglCameraRenderer.activate(gl, camera); drawObjectsGL(gl); } /** Not used method, but needed to instanciate GLEventListener */ public void init(GLAutoDrawable drawable) { ; } /** Not used method, but needed to instanciate GLEventListener */ public void displayChanged(GLAutoDrawable drawable, boolean a, boolean b) { ; } /** Called to indicate the drawing surface has been moved and/or resized */ public void reshape (GLAutoDrawable drawable, int x, int y, int width, int height) { GL gl = drawable.getGL(); gl.glViewport(0, 0, width, height); camera.updateViewportResize(width, height); } public void mouseEntered(MouseEvent e) { canvas.requestFocusInWindow(); } public void mouseExited(MouseEvent e) { //System.out.println("Mouse exited"); } public void mousePressed(MouseEvent e) { if ( cameraController.processMousePressedEventAwt(e) ) { canvas.repaint(); } } public void mouseReleased(MouseEvent e) { if ( cameraController.processMouseReleasedEventAwt(e) ) { canvas.repaint(); } } public void mouseClicked(MouseEvent e) { if ( cameraController.processMouseClickedEventAwt(e) ) { canvas.repaint(); } } public void mouseMoved(MouseEvent e) { if ( cameraController.processMouseMovedEventAwt(e) ) { canvas.repaint(); } } public void mouseDragged(MouseEvent e) { if ( cameraController.processMouseDraggedEventAwt(e) ) { canvas.repaint(); } } /** WARNING: It is not working... check pending */ public void mouseWheelMoved(MouseWheelEvent e) { System.out.println("."); if ( cameraController.processMouseWheelEventAwt(e) ) { canvas.repaint(); } } public void keyPressed(KeyEvent e) { if ( e.getKeyCode() == KeyEvent.VK_ESCAPE ) { System.exit(0); } if ( cameraController.processKeyPressedEventAwt(e) ) { canvas.repaint(); } if ( qualityController.processKeyPressedEventAwt(e) ) { System.out.println(quality); canvas.repaint(); } int unicode_id = e.getKeyChar(); if ( unicode_id != e.CHAR_UNDEFINED ) { switch ( unicode_id ) { case '0': if ( debugEdges ) { debugEdges = false; } else { debugEdges = true; } break; case ' ': if ( showCoordinateSystem ) { showCoordinateSystem = false; } else { showCoordinateSystem = true; } break; case '1': faceIndex --; break; case '2': faceIndex ++; break; case '8': edgeIndex --; break; case '9': edgeIndex ++; break; case 'I': System.out.println(solid); if ( solid.validateModel() ) { System.out.println("SOLID MODEL IS VALID!"); } else { System.out.println("SOLID MODEL IS INVALID!"); } break; case '3': solidType--; if ( solidType < 0 ) solidType = 0; solid = buildSolid(solidType); break; case '4': solidType++; solid = buildSolid(solidType); break; case '5': csgOperation++; if ( csgOperation > 3 ) csgOperation = 0; solid = buildSolid(solidType); break; case '6': csgSample++; if ( csgSample > 4 ) csgSample = 0; solid = buildSolid(solidType); break; } if ( faceIndex < -2 ) faceIndex = -2; if ( edgeIndex < -3 ) edgeIndex = -3; canvas.repaint(); } } public void keyReleased(KeyEvent e) { if ( cameraController.processKeyReleasedEventAwt(e) ) { canvas.repaint(); } } /** Do NOT call your controller from the `keyTyped` method, or the controller will be invoked twice for each key. Call it only from the `keyPressed` and `keyReleased` method */ public void keyTyped(KeyEvent e) { ; }}//===========================================================================//= EOF =//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -