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