📄 cohensutherlandclipping.java
字号:
} /** 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); camera1.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(); } } 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) { ; } public JMenuBar buildMenu() { //------------------------------------------------------------ JMenuBar menubar; JMenu popup; JMenuItem option; menubar = new JMenuBar(); //------------------------------------------------------------ popup = new JMenu("File"); menubar.add(popup); option = popup.add(new JMenuItem("Exit")); option.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); }}); popup.getPopupMenu().setLightWeightPopupEnabled(false); //------------------------------------------------------------ popup = new JMenu("Help"); menubar.add(popup); option = popup.add(new JMenuItem("About")); MyActionListener mostrador_ayuda = new MyActionListener(menubar); option.addActionListener(mostrador_ayuda); popup.getPopupMenu().setLightWeightPopupEnabled(false); //------------------------------------------------------------ return menubar; }}class MyActionListener implements ActionListener { private Component parent; MyActionListener(Component parent) { this.parent = parent; } public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(parent, "This program is a test for the Cohen-Sutherland 3D line clipping algorithm " + "implemented in the Camera class of the VSDK. Move each line edge with the " + "sliders and observe the line behavior respect the second camera view volume." ); }}class ControlPanel extends JPanel implements AdjustmentListener, ActionListener{ private CohenSutherlandClipping parent; public ControlPanel(CohenSutherlandClipping parent) { //----------------------------------------------------------------- JScrollBar sb; JLabel jl; JPanel frame = null; JPanel innerframe = null; String names[] = new String[6]; this.parent = parent; setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); //----------------------------------------------------------------- JRadioButton rb; ButtonGroup bg = new ButtonGroup(); frame = new JPanel(); frame.setLayout(new BoxLayout(frame, BoxLayout.X_AXIS)); add(frame); frame.add(new JLabel("CAMERAS CONTROL -> ")); innerframe = new JPanel(); innerframe.setBorder( BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); innerframe.setLayout(new BoxLayout(innerframe, BoxLayout.X_AXIS)); rb = new JRadioButton("Primary camera selected for control"); rb.setSelected(true); rb.setActionCommand("ActivateCamera1"); rb.addActionListener(this); bg.add(rb); innerframe.add(rb); rb = new JRadioButton("Secondary camera selected for control"); rb.setSelected(false); rb.setActionCommand("ActivateCamera2"); rb.addActionListener(this); bg.add(rb); innerframe.add(rb); frame.add(innerframe); //----------------------------------------------------------------- JPanel frame2; frame2 = new JPanel(); JButton b; b = new JButton("Top view"); b.addActionListener(this); frame2.add(b); b = new JButton("Front view"); b.addActionListener(this); frame2.add(b); b = new JButton("Left view"); b.addActionListener(this); frame2.add(b); b = new JButton("Perspective view"); b.addActionListener(this); frame2.add(b); add(frame2); //----------------------------------------------------------------- names[0] = "x1"; names[1] = "y1"; names[2] = "z1"; names[3] = "x2"; names[4] = "y2"; names[5] = "z2"; for ( int i = 0; i < 6; i++ ) { if ( i == 0 || i == 3 ) { frame = new JPanel(); frame.setLayout(new BoxLayout(frame, BoxLayout.X_AXIS)); add(frame); if ( i == 0 ) frame.add(new JLabel(" FIRST POINT -> ")); else frame.add(new JLabel(" SECOND POINT -> ")); innerframe = new JPanel(); innerframe.setBorder( BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); innerframe.setLayout(new BoxLayout(innerframe, BoxLayout.X_AXIS)); frame.add(innerframe); } jl = new JLabel(names[i] + ": "); innerframe.add(jl); sb = new JScrollBar(JScrollBar.HORIZONTAL); sb.setName(names[i]); sb.addAdjustmentListener(this); sb.setMinimum(0); sb.setMaximum(100); //sb.setValue(50); innerframe.add(sb); } //----------------------------------------------------------------- } public void adjustmentValueChanged(AdjustmentEvent ev) { double val = (((double)ev.getValue()) - 50.0) / 10.0; if ( ((JScrollBar)ev.getAdjustable()).getName().equals("x1") ) { parent.point0.x = val; } else if ( ((JScrollBar)ev.getAdjustable()).getName().equals("y1") ) { parent.point0.y = val; } else if ( ((JScrollBar)ev.getAdjustable()).getName().equals("z1") ) { parent.point0.z = val; } else if ( ((JScrollBar)ev.getAdjustable()).getName().equals("x2") ) { parent.point1.x = val; } else if ( ((JScrollBar)ev.getAdjustable()).getName().equals("y2") ) { parent.point1.y = val; } else if ( ((JScrollBar)ev.getAdjustable()).getName().equals("z2") ) { parent.point1.z = val; } parent.canvas.repaint(); } public void actionPerformed(ActionEvent e) { if ( ((String)e.getActionCommand()).equals("ActivateCamera1") ) { parent.cameraController = new CameraControllerAquynza(parent.camera1); } else if ( ((String)e.getActionCommand()).equals("Top view") ) { parent.setTopView(); } else if ( ((String)e.getActionCommand()).equals("Front view") ) { parent.setFrontView(); } else if ( ((String)e.getActionCommand()).equals("Left view") ) { parent.setLeftView(); } else if ( ((String)e.getActionCommand()).equals("Perspective view") ) { parent.setPerspectiveView(); } else { parent.cameraController = new CameraControllerAquynza(parent.camera2); } parent.canvas.repaint(); }}//===========================================================================//= EOF =//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -