Skip to Content
Killer Game Programming in Java
book

Killer Game Programming in Java

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

Moving a Limb

MoveableLimb allows a limb to be moved around the x-, y-, and z-axes. This is achieved by affecting the xAxisTG, yAxisTG, and zAxisTG TransformGroups in the limb's subgraph.

MoveableLimb maintains range information for the three axes and ignores rotations that would move the limb outside of those ranges. If a range isn't specified, then it will be assumed to be 0 (i.e., rotation is not possible around that axis). The programmer calls setRanges() or setRange() to initialize the range details for different axes:

    // globals: the axis ranges
    private double xMin, xMax, yMin, yMax, zMin, zMax;


    public void setRanges(double x1, double x2, double y1, double y2,
                                    double z1, double z2)
    { setRange(X_AXIS, x1, x2);
      setRange(Y_AXIS, y1, y2);
      setRange(Z_AXIS, z1, z2);
    }


    public void setRange(int axis, double angle1, double angle2)
    // set the range for axis only
    {
      if (angle1 > angle2) {
        System.out.println(limbName + ": wrong order... swapping");
        double temp = angle1;
        angle1 = angle2;
        angle2 = temp;
      }
      if (axis == X_AXIS) {
        xMin = angle1;  xMax = angle2;

      }
      else if (axis == Y_AXIS) {
        yMin = angle1;  yMax = angle2;
      }
      else {  // Z_AXIS
        zMin = angle1;  zMax = angle2;
      }
    }  // end of setRange()

The methods initialize the xMin, xMax, yMin, yMax, zMin, and zMax globals and ensure the ranges are given in the right order.

Rotations are processed by updateLimb(), which is called from the Figure object with axis and angle arguments:

 public void updateLimb(int axis, double angleStep) // Attempt to rotate ...
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

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Learning Java Through Games

Learning Java Through Games

Lubomir Stanchev

Publisher Resources

ISBN: 0596007302Errata Page