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

Get Killer Game Programming in Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.