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().

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
ImageComponent2Dobjects 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access