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

1    /** 
2     * Created by IntelliJ IDEA. 
3     * User: jgervasio 
4     * Date: Apr 20, 2004 
5     * Time: 12:00:50 PM 
6     * To change this template use Options | File Templates. 
7     */ 
8    package j3d.cr325.killTheStudent; 
9     
10   import j3d.cr325.killTheStudent.MyLevittownDoomKeyboard; 
11   import j3d.cr325.Shapes; 
12    
13   import javax.vecmath.Vector3f; 
14   import javax.media.j3d.*; 
15    
16   import com.sun.j3d.utils.geometry.Sphere; 
17   import com.sun.j3d.utils.geometry.Primitive; 
18    
19   public class AddSceneGeometry { 
20       public static void addTrees(MyLevittownDoomKeyboard myLevittownDoomKeyboard, Vector3f translate, 
21                             Transform3D t3D, 
22                             BoundingSphere bSphere, 
23                             BranchGroup bg) { 
24           SharedGroup share = new SharedGroup(); 
25           share.addChild(Shapes.getTrees()); 
26    
27           float position[][] = {{0.0f, 0f, -3.0f}, 
28                                 {6.0f, 0f, 0.0f}, 
29                                 {6.0f, 0f, 6.0f}, 
30                                 {3.0f, 0f, -10.0f}, 
31                                 {13.0f, 0f, -30.0f}, 
32                                 {-13.0f, 0f, 30.0f}, 
33                                 {-13.0f, 0f, 23.0f}, 
34                                 {13.0f, 0f, 3.0f}}; 
35    
36           placeStuff(position, translate, t3D, bSphere, bg, share); 
37       } 
38    
39       public static void addTanks(MyLevittownDoomKeyboard myLevittownDoomKeyboard, Vector3f translate, 
40                             Transform3D t3D, 
41                             BoundingSphere bSphere, 
42                             BranchGroup bg) { 
43           SharedGroup share = new SharedGroup(); 
44           //share.addChild(Tetrahedron.createTetrahedronBranchGroup()); 
45    
46           float position[][] = {{4.0f, 0.5f, -3.0f}, 
47                                 {2.0f, 0.5f, 0.0f}, 
48                                 {2.0f, 0.5f, 6.0f}, 
49                                 {7.0f, 0.5f, -10.0f}, 
50                                 {20.0f, 0.5f, -30.0f}, 
51                                 {-11.0f, 0.5f, 30.0f}, 
52                                 {-18.0f, 0.5f, 23.0f}, 
53                                 {16.0f, 0.5f, 3.0f}}; 
54    
55           placeStuff(position, translate, t3D, bSphere, bg, share); 
56       } 
57    
58       public static void addHouses(MyLevittownDoomKeyboard myLevittownDoomKeyboard, Vector3f translate, 
59                              Transform3D t3D, 
60                              BoundingSphere bSphere, 
61                              BranchGroup bg) { 
62           SharedGroup share = new SharedGroup(); 
63    
64           share.addChild(Shapes.getHouses()); 
65    
66           float position[][] = {{0.0f, 0f, -2.0f}, 
67                                 {3.0f, 0f, 0.0f}, 
68                                 {3.0f, 0f, 4.0f}, 
69                                 {4.0f, 0f, -8.0f}, 
70                                 {6.0f, 0f, -25.0f}, 
71                                 {-6.0f, 0f, 25.0f}, 
72                                 {-6.0f, 0f, 15.0f}, 
73                                 {6.0f, 0f, 1.0f}}; 
74    
75           placeStuff(position, translate, t3D, bSphere, bg, share); 
76       } 
77    
78       public static BranchGroup createBackground(MyLevittownDoomKeyboard levitown) { 
79           // create a parent BranchGroup for the Background 
80           BranchGroup backgroundGroup = new BranchGroup(); 
81    
82           // create a new Background node 
83           Background back = new Background(); 
84    
85           // set the range of influence of the background 
86           back.setApplicationBounds(levitown.getBackgroundBoundingSphere()); 
87    
88           // create a BranchGroup that will hold 
89           // our Sphere geometry 
90           BranchGroup bgGeometry = new BranchGroup(); 
91    
92           // create the Sphere geometry with radius 1.0 
93           // we tell the Sphere to generate texture coordinates 
94           // to enable the texture image to be rendered 
95           // and because we are *inside* the Sphere we have to generate 
96           // Normal coordinates inwards or the Sphere will not be visible. 
97           Appearance appearance = new Appearance(); 
98           appearance.setTexture(Utils.getMandleTexture(640, 480)); 
99           Sphere sphere = new Sphere(0.50f, 
100                  Primitive.GENERATE_TEXTURE_COORDS | 
101                  Primitive.GENERATE_NORMALS_INWARD, 
102                  appearance); 
103   
104          // start wiring everything together 
105          // add the Sphere to its parent BranchGroup 
106          bgGeometry.addChild(sphere); 
107   
108          // assign the BranchGroup to the Background as geometry. 
109          back.setGeometry(bgGeometry); 
110   
111          // add the Background node to its parent BranchGroup 
112          backgroundGroup.addChild(back); 
113   
114          return backgroundGroup; 
115      } 
116   
117      public static void placeStuff(float[][] position, 
118                              Vector3f translate, 
119                              Transform3D t3D, 
120                              BoundingSphere bSphere, 
121                              BranchGroup bg, 
122                              SharedGroup share) { 
123          TransformGroup TGT; 
124          TransformGroup TGR; 
125          Billboard billboard; 
126          for (int i = 0; i < position.length; i++) { 
127              translate.set(position[i]); 
128              t3D.setTranslation(translate); 
129              TGT = new TransformGroup(t3D); 
130              TGR = new TransformGroup(); 
131              TGR.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); 
132              billboard = new Billboard(TGR); 
133              billboard.setSchedulingBounds(bSphere); 
134              billboard.setAlignmentMode(Billboard.ROTATE_ABOUT_POINT); 
135              bg.addChild(TGT); 
136              bg.addChild(billboard); 
137              TGT.addChild(TGR); 
138              TGR.addChild(new Link(share)); 
139          } 
140      } 
141  } 
142