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