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

Creating the Scene

WrapMover3D is like previous Wrap classes: it creates a 3D scene inside a JPanel, made up of a checkerboard floor, blue sky, lighting, and an OrbitBehavior node to allow the user to adjust the viewpoint. Much of this is done in the createSceneGraph() method:

    private void createSceneGraph()
    {
      sceneBG = new BranchGroup();
      bounds = new BoundingSphere(new Point3d(0,0,0), BOUNDSIZE);

      lightScene();         // add the lights
      addBackground();      // add the sky
      sceneBG.addChild( new CheckerFloor().getBG() );  // add the floor
      addFigure();
      sceneBG.compile();   // fix the scene
    }

The code that distinguishes WrapMover3D from earlier Wrap classes is mostly contained in addFigure():

    // global: the multilimbed figure
    private Figure figure;

    private void addFigure()
    // add the figure and its behavior to the scene
    {
      figure = new Figure();
      sceneBG.addChild( figure.getFigureTG() );  // add figure's TG


      // add behavior
      LocationBeh
                locBeh = new LocationBeh( figure );
      locBeh.setSchedulingBounds(bounds);
      sceneBG.addChild(locBeh);
    }

The Figure object constructs the articulated figure, and its top-level TransformGroup is added to the scene. The LocationBeh object converts user key presses into figure commands.

Mover3D uses the getFigure() method to obtain a reference to the Figure object, which it passes to the CommandsPanel:

    public Figure getFigure()
    { return figure; }
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