View Javadoc
1 /*** 2 * Virtual Mockup for Machine Vision Copyright (C) 2001-2003 Fabio R. de 3 * Miranda, João E. Kogler Jr., Carlos S. Santos. Virtual Mockup for Machine 4 * Vision Project funded by SENAC-SP Permission is granted to redistribute 5 * and/or modify this software under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either version 2.1 of 7 * the License, or (at your option) any later version. This software is 8 * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 * PARTICULAR PURPOSE. See the GNU Lesser General Public License 11 * (http://www.gnu.org/copyleft/lesser.html) for more details. 12 */ 13 14 package camera3d.manipulation; 15 import camera3d.Axis; 16 import camera3d.TransformMode; 17 import camera3d.TransformScope; 18 19 import camera3d.test.NodeTester; 20 import com.sun.j3d.utils.geometry.ColorCube; 21 import java.awt.event.KeyAdapter; 22 import java.awt.event.KeyEvent; 23 import java.awt.event.MouseAdapter; 24 import java.awt.event.MouseEvent; 25 import java.awt.event.MouseMotionListener; 26 import javax.media.j3d.*; 27 import javax.vecmath.*; 28 29 /*** 30 * A simple test for the RotTGAdapter class. It creates a scene with a color 31 * cube which can be rotate with the mouse. Use the "X", "Y" or "Z" key for 32 * changing the axis of rotation. The "A" key changes the rotation mode to 33 * absolute: rotations will be performed considering the virtual world axis 34 * system. The "R" key changes the rotation mode to relative: rotations will be 35 * performed considering the object's local coordinate system. 36 * 37 *@author Fábio Roberto de Miranda, Carlos da Silva dos Santos 38 *@created November 13, 2003 39 *@version 23/05/2003 40 */ 41 public class RotAdapterTester { 42 /*** 43 * Creates j3d infrastructure 44 */ 45 private NodeTester tester; 46 private ColorCube cube; 47 private TransformGroup cubeTG; 48 private RotTGAdapter adapter; 49 private Axis cubeAxis; 50 private Axis dummyAxis; 51 52 // to displace cube from origin 53 private TransformGroup dummyTG; 54 private Transform3D dummyT3D; 55 56 private RotationManipulator manip; 57 58 private boolean isStandalone = true; 59 60 61 /*** 62 * Constructor for the RotAdaptertester object 63 */ 64 public RotAdapterTester() { 65 this(true); 66 } 67 68 69 /*** 70 * Constructor for the RotAdapterTester object 71 * 72 *@param isStandalone determines whether the tester will run as standalone 73 * application. 74 */ 75 public RotAdapterTester(boolean isStandalone) { 76 this.isStandalone = isStandalone; 77 tester = new NodeTester(isStandalone); 78 79 cube = new ColorCube(); 80 // represents the cube's local coordinate system 81 cubeAxis = new Axis(); 82 cubeAxis.setVisible(true); 83 84 // sets cube transform so it differs from identity 85 dummyT3D = new Transform3D(); 86 dummyT3D.rotZ(Math.PI / 6); 87 dummyT3D.setTranslation(new Vector3d(-1.0, -1.0, -1.0)); 88 cubeTG = new TransformGroup(); 89 cubeTG.setTransform(dummyT3D); 90 91 cubeTG.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ); 92 cubeTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); 93 cubeTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); 94 cubeTG.addChild(cube); 95 cubeAxis.setSize(3.0); 96 cubeTG.addChild(cubeAxis.getRootGroup()); 97 98 adapter = new RotTGAdapter(cubeTG); 99 100 dummyTG = new TransformGroup(); 101 102 dummyT3D.rotY(Math.PI / 4); 103 dummyT3D.setTranslation(new Vector3d(0, 1, -5.0)); 104 dummyTG.setTransform(dummyT3D); 105 dummyTG.addChild(cubeTG); 106 107 dummyAxis = new Axis(); 108 dummyAxis.setVisible(true); 109 dummyTG.addChild(dummyAxis.getRootGroup()); 110 111 tester.add(dummyTG); 112 113 manip = new RotationManipulator(); 114 manip.setRotatableObject(adapter); 115 //manip.setTransformationMode(TransformMode.RELATIVE); 116 manip.setTransformationMode(TransformMode.ABSOLUTE); 117 manip.setTransformationScope(TransformScope.X); 118 manip.setCanvas3D(tester.getCanvas3D()); 119 120 //repositioning the camera 121 dummyT3D.setIdentity(); 122 dummyT3D.setTranslation(new Vector3d(0.0, 1.0, 4.0)); 123 tester.setViewTransform(dummyT3D); 124 125 InternalListener listener = new InternalListener(); 126 tester.getCanvas3D().addMouseListener(listener); 127 tester.getCanvas3D().addMouseMotionListener(listener); 128 tester.getCanvas3D().addKeyListener(new KeybListener()); 129 } 130 131 132 /*** 133 * The main program for the RotAdapterTester class 134 * 135 *@param args The command line arguments 136 */ 137 public static void main(String[] args) { 138 RotAdapterTester taTester = new RotAdapterTester(); 139 } 140 141 142 /*** 143 * Gets the canvas3D attribute of the TransAdapterTester object 144 * 145 *@return The canvas3D value 146 */ 147 public Canvas3D getCanvas3D() { 148 return this.tester.getCanvas3D(); 149 } 150 151 152 /*** 153 * Returns flag indicating whether this object is running inside its own 154 * window. 155 * 156 *@return The standalone value 157 */ 158 public boolean isStandalone() { 159 return this.isStandalone; 160 } 161 162 163 /*** 164 * Description of the Method 165 */ 166 public void cleanup() { 167 tester.cleanup(); 168 } 169 170 171 /*** 172 * Mouse listener which forwards mouse events to the RotationManipulator. 173 * 174 *@author carlos.ssantos 175 *@created November 13, 2003 176 */ 177 class InternalListener extends MouseAdapter implements MouseMotionListener { 178 /*** 179 * Description of the Method 180 * 181 *@param e Description of the Parameter 182 */ 183 public void mouseClicked(MouseEvent e) { 184 manip.setBeginPoint(e.getX(), e.getY()); 185 } 186 187 188 /*** 189 * Description of the Method 190 * 191 *@param e Description of the Parameter 192 */ 193 public void mousePressed(MouseEvent e) { 194 manip.setBeginPoint(e.getX(), e.getY()); 195 } 196 197 198 /*** 199 * Description of the Method 200 * 201 *@param e Description of the Parameter 202 */ 203 public void mouseDragged(MouseEvent e) { 204 int mod = e.getModifiers(); 205 if((mod & MouseEvent.BUTTON1_MASK) == MouseEvent.BUTTON1_MASK) { 206 manip.setCurrentPoint(e.getX(), e.getY()); 207 } 208 } 209 210 211 /*** 212 * Description of the Method 213 * 214 *@param e Description of the Parameter 215 */ 216 public void mouseMoved(MouseEvent e) { 217 int mod = e.getModifiers(); 218 if((mod & MouseEvent.BUTTON1_MASK) == MouseEvent.BUTTON1_MASK) { 219 manip.setCurrentPoint(e.getX(), e.getY()); 220 } 221 } 222 } 223 224 225 /*** 226 * Keyboard listener for using keystrokes to change rotation axis and mode. 227 * 228 *@author carlos.ssantos 229 *@created November 13, 2003 230 */ 231 class KeybListener extends KeyAdapter { 232 /*** 233 * Description of the Method 234 * 235 *@param k Description of the Parameter 236 */ 237 public void keyPressed(KeyEvent k) { 238 //debugln("Key Pressed: "+KeyEvent.getKeyText(k.getKeyCode())); 239 if(k.getKeyCode() == KeyEvent.VK_X) { 240 manip.setTransformationScope(TransformScope.X); 241 System.out.println("__X AXIS__"); 242 } 243 if(k.getKeyCode() == KeyEvent.VK_Y) { 244 manip.setTransformationScope(TransformScope.Y); 245 System.out.println("__Y AXIS__"); 246 } 247 if(k.getKeyCode() == KeyEvent.VK_Z) { 248 manip.setTransformationScope(TransformScope.Z); 249 System.out.println("__Z AXIS__"); 250 } 251 if(k.getKeyCode() == KeyEvent.VK_A) { 252 manip.setTransformationMode(TransformMode.ABSOLUTE); 253 System.out.println("__ABSOLUTE MODE__"); 254 } 255 if(k.getKeyCode() == KeyEvent.VK_R) { 256 manip.setTransformationMode(TransformMode.RELATIVE); 257 System.out.println("__RELATIVE MODE__"); 258 } 259 } 260 261 } 262 263 } 264

This page was automatically generated by Maven