View Javadoc
1 /***************************************************************************** 2 * Virtual Mockup for Machine Vision 3 * Copyright (C) 2001-2003 Fabio R. de Miranda, João E. Kogler Jr., 4 * Carlos S. Santos. 5 * Virtual Mockup for Machine Vision Project funded by SENAC-SP 6 * 7 * Permission is granted to redistribute and/or modify this 8 * software under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This software is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License (http://www.gnu.org/copyleft/lesser.html) 16 * for more details. 17 * 18 *****************************************************************************/ 19 20 package camera3d.manipulation; 21 22 import camera3d.test.NodeTester; 23 import camera3d.TransformMode; 24 import camera3d.TransformScope; 25 import camera3d.Axis; 26 import com.sun.j3d.utils.geometry.ColorCube; 27 import javax.media.j3d.*; 28 import javax.vecmath.*; 29 import java.awt.event.MouseEvent; 30 import java.awt.event.MouseAdapter; 31 import java.awt.event.MouseMotionListener; 32 import java.awt.event.KeyAdapter; 33 import java.awt.event.KeyEvent; 34 import com.sun.j3d.utils.picking.PickTool; 35 36 /* 37 * camera3d.manipulation.PickRotateBehavior is still very buggy. 38 * Clicking on the void makes the program fail with a NullPointerException, as there 39 * is no object set for manipulation. 40 */ 41 42 /*** 43 * A test for camera3d.manipulation.PickRotateBehavior. 44 * @author Fábio Roberto de Miranda, Carlos da Silva dos Santos 45 * @version 23/05/2003 46 */ 47 public class PickRotateTester { 48 NodeTester nodeTester; 49 ColorCube cube; 50 TransformGroup cubeTG; 51 52 Axis cubeAxis; 53 Axis dummyAxis; 54 55 // to displace cube from origin 56 TransformGroup dummyTG; 57 Transform3D dummyT3D; 58 BranchGroup testerBG; 59 camera3d.manipulation.PickRotateBehavior rotate; 60 61 public PickRotateTester(){ 62 63 nodeTester = new NodeTester(); 64 testerBG = new BranchGroup(); 65 testerBG.setPickable(true); 66 67 68 cube = new ColorCube(); 69 cube.setPickable(true); 70 cube.setCapability(Node.ENABLE_PICK_REPORTING); 71 PickTool.setCapabilities(cube,PickTool.INTERSECT_FULL); 72 73 cubeAxis = new Axis(); 74 cubeAxis.setVisible(true); 75 76 dummyT3D = new Transform3D(); 77 78 dummyT3D.rotZ(Math.PI/6); 79 dummyT3D.setTranslation(new Vector3d(0.0,0.0,2)); 80 cubeTG = new TransformGroup(); 81 cubeTG.setTransform(dummyT3D); 82 83 cubeTG.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ); 84 cubeTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); 85 cubeTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); 86 cubeTG.setPickable(true); 87 cubeTG.setCapability(Node.ENABLE_PICK_REPORTING); 88 cubeTG.addChild(cube); 89 cubeAxis.setSize(3.0); 90 cubeTG.addChild(cubeAxis.getRootGroup()); 91 92 dummyTG = new TransformGroup(); 93 dummyTG.setPickable(true); 94 //dummyTG.setCapability(Node.ENABLE_PICK_REPORTING); 95 96 dummyT3D.rotY(Math.PI/4); 97 dummyT3D.setTranslation(new Vector3d(0,0,1.0)); 98 dummyTG.setTransform(dummyT3D); 99 dummyTG.addChild(cubeTG); 100 101 dummyAxis = new Axis(); 102 dummyAxis.setVisible(true); 103 dummyTG.addChild(dummyAxis.getRootGroup()); 104 105 testerBG.addChild(dummyTG); 106 107 rotate = new camera3d.manipulation.PickRotateBehavior(nodeTester.getCanvas3D(), 108 testerBG, 109 new BoundingSphere(new Point3d(),1000.0)); 110 111 testerBG.addChild(rotate); 112 nodeTester.add(testerBG); 113 rotate.setTransformationMode(TransformMode.ABSOLUTE); 114 rotate.setRotationAxis(TransformScope.X); 115 116 //InternalListener listener = new InternalListener(); 117 //tester.getCanvas3D().addMouseListener(listener); 118 //tester.getCanvas3D().addMouseMotionListener(listener); 119 nodeTester.getCanvas3D().addKeyListener(new KeybListener()); 120 } 121 /* 122 class InternalListener extends MouseAdapter implements MouseMotionListener{ 123 124 public void mouseClicked(MouseEvent e){ 125 manip.setBeginPoint(e.getX(),e.getY()); 126 } 127 128 public void mousePressed(MouseEvent e){ 129 manip.setBeginPoint(e.getX(),e.getY()); 130 } 131 132 public void mouseDragged(MouseEvent e){ 133 int mod = e.getModifiers(); 134 if ((mod&MouseEvent.BUTTON1_MASK)==MouseEvent.BUTTON1_MASK){ 135 manip.setCurrentPoint(e.getX(),e.getY()); 136 } 137 } 138 139 public void mouseMoved(MouseEvent e){ 140 int mod = e.getModifiers(); 141 if ((mod&MouseEvent.BUTTON1_MASK)==MouseEvent.BUTTON1_MASK){ 142 manip.setCurrentPoint(e.getX(),e.getY()); 143 } 144 } 145 }*/ 146 147 148 class KeybListener extends KeyAdapter{ 149 public void keyPressed(KeyEvent k){ 150 //debugln("Key Pressed: "+KeyEvent.getKeyText(k.getKeyCode())); 151 /* 152 if (k.getKeyCode() == KeyEvent.VK_ESCAPE){ 153 cancelAction(); 154 }*/ 155 if (k.getKeyCode() == KeyEvent.VK_X){ 156 rotate.setRotationAxis(TransformScope.X); 157 System.out.println("__X AXIS__"); 158 } 159 if (k.getKeyCode() == KeyEvent.VK_Y){ 160 rotate.setRotationAxis(TransformScope.Y); 161 System.out.println("__Y AXIS__"); 162 } 163 if (k.getKeyCode() == KeyEvent.VK_Z){ 164 rotate.setRotationAxis(TransformScope.Z); 165 System.out.println("__Z AXIS__"); 166 } 167 if (k.getKeyCode() == KeyEvent.VK_A){ 168 rotate.setTransformationMode(TransformMode.ABSOLUTE); 169 System.out.println("__ABSOLUTE MODE__"); 170 } 171 if (k.getKeyCode() == KeyEvent.VK_R){ 172 rotate.setTransformationMode(TransformMode.RELATIVE); 173 System.out.println("__RELATIVE MODE__"); 174 } 175 } 176 177 } 178 179 public static void main(String[] args){ 180 PickRotateTester prTester = new PickRotateTester(); 181 } 182 183 } 184

This page was automatically generated by Maven