May 2005
Intermediate to advanced
998 pages
26h
English
WrapShooter3D's createSceneGraph() calls makeGun() to initialize various elements:
private void makeGun(Canvas3D canvas3D)
{ // starting vector for the gun cone and beam
Vector3d startVec = new Vector3d(0, 2, 0);
// the gun
GunTurret gun = new GunTurret(startVec);
sceneBG.addChild( gun.getGunBG() );
// explosion and sound
PointSound explPS = initSound("Explo1.wav");
ExplosionsClip expl = new ExplosionsClip( startVec, explPS);
sceneBG.addChild( expl.getExplBG() );
// laser beam and sound
PointSound beamPS = initSound("laser2.wav");
LaserBeam laser = new LaserBeam( startVec, beamPS);
sceneBG.addChild( laser.getBeamBG() );
// the behavior that controls the shooting
ShootingBehaviour shootBeh =
new ShootingBehaviour(canvas3D, sceneBG, bounds,
new Point3d(0,2,0), expl, laser, gun );
sceneBG.addChild(shootBeh);
} // end of makeGun()The position vector of the gun cone is hardwired to be (0, 2, 0). The same vector is used to place the laser beam (a red cylinder) inside the cone. The hardwiring makes the coding easier and highlights a major simplification of this example: the base of the gun doesn't move.