/Users/lyon/j4p/src/j3d/GunController.java

1    package j3d; 
2     
3    import ip.raul.Point3D; 
4     
5    import javax.media.j3d.*; 
6    import javax.vecmath.Matrix3d; 
7    import javax.vecmath.Vector3d; 
8    import javax.vecmath.Point3d; 
9    import javax.vecmath.Tuple3d; 
10    
11    
12   public class GunController implements 
13           java.awt.event.KeyListener { 
14       private View view = null; 
15       private BranchGroup gun = null; 
16       private TransformGroup gunXformGroup = null; 
17       private Canvas3D c3d = null; 
18    
19       public GunController() { 
20       } 
21    
22       public void setCanvas3D(Canvas3D c3d){ 
23           this.c3d = c3d; 
24       } 
25       public void setView(View view) { 
26           this.view = view; 
27       } 
28    
29       public void setGun(BranchGroup gun) { 
30           this.gun = gun; 
31       } 
32       public void setTransformGroup(TransformGroup gunXformGroup){ 
33           this.gunXformGroup = gunXformGroup; 
34    
35       } 
36       float x = 0; 
37       float y = 0; 
38       float z = 0; 
39       public void trackView() { 
40    
41          ViewPlatform vp = view.getViewPlatform(); 
42           view.setUserHeadToVworldEnable(true); 
43    
44          PhysicalBody pb = view.getPhysicalBody(); 
45           Point3d p3d = new Point3d(); 
46           pb.getLeftEyePosition(p3d); 
47           view.getLeftManualEyeInCoexistence(p3d); 
48           PhysicalEnvironment pe = view.getPhysicalEnvironment(); 
49           /* 
50                   c3d.getCenterEyeInImagePlate(p3d); 
51           Transform3D t3d = new Transform3D(); 
52           c3d.getImagePlateToVworld(t3d); 
53           t3d.transform(p3d); 
54           System.out.println("p3d="+p3d); 
55    
56           /// 
57          boolean b = view.getTrackingEnable(); 
58           Matrix3d gunXfmMat = new Matrix3d(); 
59           //gunXfmMat.rotX(Math.PI / 2); 
60           //gunXfmMat.transform(new Point3D(0,0,0)); 
61           Transform3D gunXfm = new Transform3D(); 
62           double d[] = new double[3]; 
63           p3d.get(d); 
64           Vector3d v3d = new Vector3d(d); 
65           gunXfm.set(gunXfmMat, v3d, 0.2); 
66           gunXformGroup.setTransform(gunXfm); 
67           */ 
68       } 
69    
70       public void keyPressed(java.awt.event.KeyEvent e) { 
71           trackView(); 
72          System.out.println( e.getKeyChar() ); 
73       } 
74    
75       public void keyPressed2(java.awt.event.KeyEvent e) { 
76           char keyChar = e.getKeyChar(); 
77           int keyCode = e.getKeyCode(); 
78           int modifiers = e.getModifiers(); 
79    
80       } 
81    
82    
83       public void keyTyped(java.awt.event.KeyEvent e) { 
84       } 
85    
86       public void keyReleased(java.awt.event.KeyEvent e) { 
87       } 
88   }