manager.getBaseAnimationLayer().setCurrentState("walk_anim", true);
manager.findAnimationLayer("head").setCurrentState("head_rotate", true);
// add a head rotator
final int headJoint = pose.getSkeleton().findJointByName("Bip01_Head");
final ManagedTransformSource headSource = (ManagedTransformSource) manager.findAnimationLayer("head")
.getSteadyState("head_rotate").getSourceTree();
_root.addController(new SpatialController<Node>() {
private final Quaternion headRotation = new Quaternion();
public void update(final double time, final Node caller) {
// update the head's position
if (headCheck != null && headCheck.isSelected()) {
double angle = _timer.getTimeInSeconds();
// range 0 to 180 degrees
angle %= MathUtils.PI;
// range -90 to 90 degrees
angle -= MathUtils.HALF_PI;
// range is now 0 to 90 degrees, reflected
angle = Math.abs(angle);
// range is now -45 to 45 degrees
angle -= MathUtils.HALF_PI / 2.0;
headRotation.fromAngleAxis(angle, Vector3.UNIT_X);
headSource.setJointRotation(headJoint, headRotation);
}
}
});
// add callback for our UI