/Users/lyon/j4p/src/j3d/cr325/Bullet.java

1    package j3d.cr325; 
2     
3    import j3d.cr325.BulletBehavior; 
4     
5    import javax.media.j3d.*; 
6    import javax.vecmath.Color3f; 
7     
8    import com.sun.j3d.utils.geometry.Sphere; 
9     
10   /** 
11    * DocJava, Inc. 
12    * http://www.docjava.com 
13    * Programmer: dlyon 
14    * Date: Apr 6, 2004 
15    * Time: 3:53:26 PM 
16    */ 
17   public class Bullet { 
18       /** 
19        * This builds the ball that acts as the bullet for our gun. 
20        * The ball is created from a sphere primitive, and a transform 
21        * group and interpolator are added so that we can 'fire' the 
22        * bullet. 
23        * 
24        * @return BranchGroup that is the root of the ball branch. 
25        * @param simpleGame 
26        */ 
27       public static BranchGroup getBulletGroup(BulletBehavior bb) { 
28           final BranchGroup bulletBranchGroup = new BranchGroup(); 
29    
30           final Appearance bulletAppearance = new Appearance(); 
31           final Color3f ambientColour = new Color3f(1.0f, 0.0f, 0.0f); 
32           final Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); 
33           final Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); 
34           final Color3f diffuseColour = new Color3f(1.0f, 0.0f, 0.0f); 
35           final float shininess = 20.0f; 
36           bulletAppearance.setMaterial(new Material(ambientColour, emissiveColour, 
37                   diffuseColour, specularColour, shininess)); 
38    
39           final Sphere bulletSphere = new Sphere(0.2f, bulletAppearance); 
40    
41           final TransformGroup bulletMoveTransformGroup = new TransformGroup(); 
42           bulletMoveTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); 
43           bulletMoveTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); 
44           bulletMoveTransformGroup.addChild(bulletSphere); 
45           bulletBranchGroup.addChild(bulletMoveTransformGroup); 
46    
47    
48           bb.setBulletInterpolator( new PositionInterpolator(bb.getAlpha(), 
49                   bulletMoveTransformGroup, 
50                   new Transform3D(), 0.0f, 50.0f)); 
51    
52           bulletBranchGroup.addChild(bb.getBulletInterpolator()); 
53    
54           return bulletBranchGroup; 
55    
56       } 
57   } 
58