Skip to Main Content
Killer Game Programming in Java
book

Killer Game Programming in Java

by Andrew Davison
May 2005
Intermediate to advanced content levelIntermediate to advanced
998 pages
26h
English
O'Reilly Media, Inc.
Content preview from Killer Game Programming in Java

Controlling the Gun

The GunTurret class builds the scene graph branch for the cylinder and cone and has two public methods: getGunBG() and makeRotation(). getGunBG() is used by WrapShooter3D to retrieve a reference to the gun's top-level BranchGroup, gunBG, so it can be added to the scene. makeRotation() is called by ShootingBehaviour to rotate the cone to point at the clicked position.

The scene graph branch built inside GunTurret is shown in Figure 23-4.

The GunTurret constructor is:

    public GunTurret(Vector3d svec)
    { startVec = svec;
      gunBG = new BranchGroup();
      Appearance apStone = stoneApp();
      placeGunBase(apStone);
      placeGun(apStone);
    }

startVec contains the position of the gun cone: (0, 2, 0).

Scenegraph branch for GunTurret

Figure 23-4. Scenegraph branch for GunTurret

Tip

There's no particular significance to this coordinate, but it works well, so I've stayed with it.

apStone is a blending of a stone texture and white material, with lighting enabled, which allows lighting effects to be seen on the gun's surfaces. The blending is done using the TextureAttribute.MODULATE setting for the texture mode.

Tip

A similar approach was used in Chapter 21 for the texture applied to the particle system of quads.

placeGunBase() creates the lefthand side of the subgraph shown in Figure 23-4, and placeGun() handles the right side.

The cylinder and cone are unpickable (you only want the gun to shoot at the tiles):

 cyl.setPickable(false); ...
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.
Start your free trial

You might also like

Java Game Development with LibGDX: From Beginner to Professional

Java Game Development with LibGDX: From Beginner to Professional

Lee Stemkoski

Publisher Resources

ISBN: 0596007302Supplemental ContentErrata Page