This is probably something simple (I hope)… I have a CameraNode that I'm trying to make controllable by the keyboard. I've used some FlagRush tutorial code as a guide, and I can rotate like this:
KeyInputAction turnAction = new KeyInputAction() {
private final Matrix3f incr = new Matrix3f();
private final Matrix3f tempMa = new Matrix3f();
private final Matrix3f tempMb = new Matrix3f();
private Vector3f rotAxis = new Vector3f(0, 1, 0);
public void performAction(InputActionEvent evt) {String triggerName = evt.getTriggerName();
if (triggerName.equals("turnLeft")) {
incr.fromAngleNormalAxis(1 * evt.getTime(), rotAxis);
} else {
incr.fromAngleNormalAxis(-1 * evt.getTime(), rotAxis);
}
camNode.getLocalRotation().fromRotationMatrix(incr.mult(camNode.getLocalRotation().toRotationMatrix(tempMa), tempMb));
camNode.getLocalRotation().normalize();
}
};
addAction(turnAction, "turnRight", true);
addAction(turnAction, "turnLeft", true);
That works fine, however, I'd also like to be able to rotate up and down with the keyboard (look up, look down):
KeyInputAction lookDirAction = new KeyInputAction() {
private final Matrix3f incr = new Matrix3f();
private final Matrix3f tempMa = new Matrix3f();
private final Matrix3f tempMb = new Matrix3f();
private Vector3f rotAxis = new Vector3f(1, 0, 0);
public void performAction(InputActionEvent evt) {
String triggerName = evt.getTriggerName();
if (triggerName.equals("lookDown")) {
incr.fromAngleNormalAxis(1 * evt.getTime(), rotAxis);
} else {
incr.fromAngleNormalAxis(-1 * evt.getTime(), rotAxis);
}
camNode.getLocalRotation().fromRotationMatrix(
incr.mult(camNode.getLocalRotation().toRotationMatrix(tempMa), tempMb));
camNode.getLocalRotation().normalize();
}
};
addAction(lookDirAction, "lookDown", true);
addAction(lookDirAction, "lookUp", true);
This works fine, as long as the camera node is looking "forward" (straight along the Z axis), however, obviously rotating to the left (rotating counterclockwise along the Y axis) changes things. Then the lookDown action results in a roll instead of a look down.
How do people normally deal with this?