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

Adding an Image to the Viewpoint

The call to gunHand() inside initUserControls() hides the creation of a TexturedPlane object just in front of and below the user's viewpoint:

    private PlatformGeometry gunHand()
    {
      PlatformGeometry pg = new PlatformGeometry();
      // define a square of sides 0.2f, facing along the z-axis
      Point3f p1 = new Point3f(-0.1f, -0.3f, -0.7f);
      Point3f p2 = new Point3f(0.1f, -0.3f, -0.7f);
      Point3f p3 = new Point3f(0.1f, -0.1f, -0.7f);
      Point3f p4 = new Point3f(-0.1f, -0.1f, -0.7f);
      TexturedPlane tp = new TexturedPlane(p1, p2, p3, p4, GUN_PIC);
      pg.addChild( tp );
      return pg;
    }

The Java 3D PlatformGeometry is nothing more than a detachable BranchGroup (confirmed by looking at its source code in java3d-utils-src.jar). It's added to ViewPlatform's TransformGroup by a call to ViewingPlatform's setPlatformGeometry().

My TexturedPlane class is a Shape3D holding a four-point QuadArray; the constructor is called with the points and a transparent GIF that will be pasted onto the quad's front face. TexturedPlane is a simplification of the ImagesSeries class of the last chapter, which lays a sequence of GIFs over a quad to exhibit an animation.

The most complicated aspect of using TexturedPlane is determining its scene coordinates. I used trial and error until the image appeared at the bottom edge of the screen. It's helpful to remember that the (x, y) coordinate pair (0, 0) corresponds to the middle of the canvas, and that negative z-coordinates are farther into the scene. For ...

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