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.KeyAdapter;
32 import java.awt.event.KeyEvent;
33 import java.awt.event.MouseMotionListener;
34
35 /***
36 *
37 * @author Fábio Roberto de Miranda, Carlos da Silva dos Santos
38 * @version 27/05/2003
39 */
40 public class ScaleAdapterTester {
41
42 private NodeTester tester;
43 private ColorCube cube;
44 private TransformGroup cubeTG;
45 private ScaleTGAdapter adapter;
46 private Axis cubeAxis;
47 private Axis dummyAxis;
48
49 // to displace cube from origin
50 private TransformGroup dummyTG;
51 private Transform3D dummyT3D;
52
53 private ScalingManipulator manip;
54
55 public ScaleAdapterTester(){
56 tester = new NodeTester();
57 cube = new ColorCube();
58 cubeAxis = new Axis();
59 cubeAxis.setVisible(true);
60
61 dummyT3D = new Transform3D();
62
63 dummyT3D.rotZ(Math.PI/6);
64 dummyT3D.setTranslation(new Vector3d(0.0,0.0,2));
65 cubeTG = new TransformGroup();
66 cubeTG.setTransform(dummyT3D);
67
68 cubeTG.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ);
69 cubeTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
70 cubeTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
71 cubeTG.addChild(cube);
72 cubeAxis.setSize(3.0);
73 cubeTG.addChild(cubeAxis.getRootGroup());
74
75
76 adapter = new ScaleTGAdapter(cubeTG);
77
78 dummyTG = new TransformGroup();
79 dummyT3D.rotX(Math.PI/4);
80 dummyT3D.setTranslation(new Vector3d(0,0,1.0));
81
82 dummyTG.setTransform(dummyT3D);
83 dummyTG.addChild(cubeTG);
84
85 dummyAxis = new Axis();
86 dummyAxis.setVisible(true);
87 dummyTG.addChild(dummyAxis.getRootGroup());
88 tester.add(dummyTG);
89
90 manip = new ScalingManipulator();
91 manip.setScalableObject(adapter);
92 manip.setTransformationMode(TransformMode.RELATIVE);
93 manip.setTransformationScope(TransformScope.X);
94 manip.setCanvas3D(tester.getCanvas3D());
95 InternalListener listener = new InternalListener();
96 tester.getCanvas3D().addMouseListener(listener);
97 tester.getCanvas3D().addMouseMotionListener(listener);
98 tester.getCanvas3D().addKeyListener(new KeybListener());
99 }
100
101 public static void main(String[] args){
102 ScaleAdapterTester scaleTester = new ScaleAdapterTester();
103 }
104
105
106
107 class InternalListener extends MouseAdapter implements MouseMotionListener{
108 public void mouseClicked(MouseEvent e){
109 manip.setBeginPoint(e.getX(),e.getY());
110 }
111
112 public void mousePressed(MouseEvent e){
113 manip.setBeginPoint(e.getX(),e.getY());
114 }
115
116 public void mouseDragged(MouseEvent e){
117 int mod = e.getModifiers();
118 if ((mod&MouseEvent.BUTTON1_MASK)==MouseEvent.BUTTON1_MASK){
119 manip.setCurrentPoint(e.getX(),e.getY());
120 }
121 }
122
123 public void mouseMoved(MouseEvent e){
124 int mod = e.getModifiers();
125 if ((mod&MouseEvent.BUTTON1_MASK)==MouseEvent.BUTTON1_MASK){
126 manip.setCurrentPoint(e.getX(),e.getY());
127 }
128 }
129 }
130
131 class KeybListener extends KeyAdapter{
132 public void keyPressed(KeyEvent k){
133 //debugln("Key Pressed: "+KeyEvent.getKeyText(k.getKeyCode()));
134 /*
135 if (k.getKeyCode() == KeyEvent.VK_ESCAPE){
136 cancelAction();
137 }*/
138 if (k.getKeyCode() == KeyEvent.VK_X){
139 manip.setTransformationScope(TransformScope.X);
140 System.out.println("__X AXIS__");
141 }
142 if (k.getKeyCode() == KeyEvent.VK_Y){
143 manip.setTransformationScope(TransformScope.Y);
144 System.out.println("__Y AXIS__");
145 }
146 if (k.getKeyCode() == KeyEvent.VK_Z){
147 manip.setTransformationScope(TransformScope.Z);
148 System.out.println("__Z AXIS__");
149 }
150 }
151
152 public void keyReleased(KeyEvent k){
153 //debugln("Key Released: "+KeyEvent.getKeyText(k.getKeyCode()));
154 }
155 }
156
157 }
This page was automatically generated by Maven