O'Reilly logo

Killer Game Programming in Java by Andrew Davison

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Managing a Laser Beam

Each LaserShot object creates and manipulates a subgraph holding a beam (a thin red cylinder) and explosion (an animation laid over a quad). The subgraph shown in Figure 24-6 is created by makeBeam().

Scenegraph branch for LaserShot

Figure 24-6. Scenegraph branch for LaserShot

The top-level TransformGroup, beamTG, moves the beam (and explosion), and the Switch allows the beam, explosion, or nothing to be displayed. The beamDir TransformGroup initially positions and orients the cylinder so it's pointing into the scene and appears close to the nozzle of the gun image.

The cylinder has a radius of 0.05 units and a height of 0.5; it's rotated by 90 degrees, moved down by 0.3, and into the scene by 0.25 units. This means that the center of its tail is located at (0, -0.3, 0) relative to the coordinate space of beamTG.

The ImagesCsSeries class is almost identical to the ImagesSeries class in Chapter 23. The two differences are:

  • The object doesn't load its own GIFs. Instead, an array of ImageComponent2D objects is passed to it in the constructor.

  • The shape's position is specified with a center point.

The call to ImageCsSeries's constructor is carried out in makeBeam():

    // create explosion, centered at (0,0,0), size 2.0f
    explShape = new ImageCsSeries( new Point3f(), 2.0f, exploIms);

The explosion is a child of the same TransformGroup as the beam (beamTG), so placing its center at (0, 0, 0) will make it appear ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required