/Users/lyon/j4p/src/j3d/cr325/killTheStudent/MyLevittownDoomKeyboard.java

1    package j3d.cr325.killTheStudent; 
2     
3    /** 
4     * Created by IntelliJ IDEA. 
5     * User: jgervasio 
6     * Date: Feb 23, 2004 
7     * Time: 12:11:58 PM 
8     * To change this template use Options | File Templates. 
9     */ 
10    
11    
12   import com.sun.j3d.utils.applet.MainFrame; 
13   import com.sun.j3d.utils.universe.SimpleUniverse; 
14   import com.sun.j3d.utils.universe.ViewingPlatform; 
15   import j3d.GunController; 
16   import j3d.cr325.killTheStudent.MyKeyBehavior; 
17   import j3d.cr325.Shapes; 
18    
19   import javax.media.j3d.*; 
20   import javax.vecmath.Matrix3d; 
21   import javax.vecmath.Point3d; 
22   import javax.vecmath.Vector3d; 
23   import javax.vecmath.Vector3f; 
24   import java.applet.Applet; 
25   import java.awt.*; 
26    
27    
28   //   BillboardApp renders a simple landscape with billboard animated trees 
29    
30   public class MyLevittownDoomKeyboard extends Applet { 
31    
32       Alpha joeAlpha = new Alpha(-1, 0, 0, 4000, 0, 0); 
33       private BoundingSphere bounds 
34               = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); 
35       public static Switch joeSwitch = JoeSphere.getJoeSwitch(); 
36    
37       public BranchGroup getSceneBranchGroup(TransformGroup viewTransformGroup) { 
38    
39           BranchGroup bg = new BranchGroup(); 
40    
41           Vector3f translate = new Vector3f(); 
42           Transform3D T3D = new Transform3D(); 
43    
44           BoundingSphere bs = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 20000); 
45           bg.addChild(Shapes.getLand()); 
46    
47           AddSceneGeometry.addTrees(this, translate, T3D, bs, bg); 
48           AddSceneGeometry.addHouses(this, translate, T3D, bs, bg); 
49           //AddSceneGeometry.addTanks(this, translate, T3D, bs, bg); 
50    
51           raiseViewAboveGround(translate, T3D, viewTransformGroup); 
52           addKeyboardNavigation(viewTransformGroup, bg); 
53    
54           BranchGroup textureSphere = new BranchGroup(); 
55           textureSphere.addChild(JoeSphere.getJoeGroup(this)); 
56           bg.addChild(textureSphere); 
57    
58    
59           Matrix3d viewTilt = new Matrix3d(); 
60           viewTilt.rotX(Math.PI / -6); 
61           T3D.set(viewTilt, new Vector3d(0.0, 10.0, 10.0), 1.0); 
62    
63           TransformGroup viewXfmGroup = new TransformGroup(T3D); 
64           //ViewPlatform myViewPlatform = new ViewPlatform(); 
65           PhysicalBody myBody = new PhysicalBody(); 
66           PhysicalEnvironment myEnvironment = new PhysicalEnvironment(); 
67           //viewXfmGroup.addChild(myViewPlatform); 
68           bg.addChild(viewXfmGroup); 
69    
70           view = new View(); 
71           //myView.addCanvas3D(Utils.getCanvas3D(this)); 
72           //myView.attachViewPlatform(myViewPlatform); 
73           view.setPhysicalBody(myBody); 
74           view.setPhysicalEnvironment(myEnvironment); 
75           //gc.setView(view); 
76           bg.compile(); 
77           return bg; 
78       } // end of CreateSceneGraph method of BillboardApp 
79    
80       MyKeyBehavior keyNavBeh = null; 
81    
82    
83       public void addKeyboardNavigation(TransformGroup transformGroup, BranchGroup bg) { 
84           keyNavBeh = new MyKeyBehavior(transformGroup); 
85           keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(), 10000.0)); 
86    
87           BranchGroup bulletBranchGroup = new BranchGroup(); 
88           keyNavBeh.setGunTransformGroup(); 
89           bulletBranchGroup = TheGun.getBulletGroup(this); 
90           bg.addChild(keyNavBeh); 
91    
92           bg.addChild(bulletBranchGroup); 
93       } 
94    
95        private void raiseViewAboveGround(Vector3f translate, Transform3D t3D, TransformGroup tg) { 
96           translate.set(0.0f, 0.3f, 0.0f); 
97           t3D.setTranslation(translate); 
98           tg.setTransform(t3D); 
99       } 
100   
101       public MyLevittownDoomKeyboard() { 
102   
103          Canvas3D c3d = Utils.getCanvas3D(this); 
104   
105          setLayout(new BorderLayout()); 
106          add("Center", c3d); 
107   
108          // SimpleUniverse is a Convenience Utility class 
109          SimpleUniverse su = new SimpleUniverse(c3d); 
110   
111          ViewingPlatform vp = su.getViewingPlatform(); 
112          vp.setNominalViewingTransform(); 
113   
114          vp.setPlatformGeometry(TheGun.buildGunPlatform()); 
115          TransformGroup steerTg = vp.getViewPlatformTransform(); 
116   
117          Transform3D t3d = new Transform3D(); 
118          steerTg.getTransform(t3d); 
119   
120          su.addBranchGraph(AddSceneGeometry.createBackground(this)); 
121   
122          viewTransformGroup 
123                  = su.getViewingPlatform().getViewPlatformTransform(); 
124   
125          su.addBranchGraph(getSceneBranchGroup(viewTransformGroup)); 
126      } 
127   
128      TransformGroup viewTransformGroup = null; 
129      private View view = null; 
130   
131   
132      BoundingSphere getBackgroundBoundingSphere() { 
133          //return new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 200.0); 
134          return new BoundingSphere(); 
135      } 
136   
137      BoundingSphere getBoundingSphere() { 
138          return  bounds; 
139      } 
140   
141      /*public static void main(String[] args) { 
142          new MainFrame(new MyLevittownDoomKeyboard(), 700, 600); 
143      } // end of main (method of BillboardApp) 
144      */ 
145  } 
146