I want the same behavior like in each simple 3D Viewer, where the model is in the middle of the scene and I can zoom and turnaroud it. The zoom works via the mouse wheel, the ratation via mouse left and translation via mouse right button.
I’ve implemented my own camera extened from ChaseCamera but due to the rotation node the behavoir isn’t the same.
If I move the rotation center(by mouse right click) and next try to turn the model of course it doesn’t work correctly because the center has moved. What I want is to move the camera around the model and not moving the rotation center itself.
I hope this is just common use case and there is an easy solution for that.
public class MyCamera extends ChaseCamera {
private static final float MOVE_SPEED = 6;
private Node rotationCenterNode;
Vector3f tmp = new Vector3f();
Quaternion tmpQuat = new Quaternion();
boolean shift;
boolean panning;
public MyCamera(SimpleApplication app, Node rotationCenterNode) {
this(app.getCamera(), rotationCenterNode, app.getInputManager());
}
public MyCamera(Camera cam, Node rotationCenterNode, InputManager inputManager) {
super(cam, rotationCenterNode, inputManager);
this.rotationCenterNode = rotationCenterNode;
inputManager.addMapping("rightClick", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
inputManager.addMapping("up", new MouseAxisTrigger(MouseInput.AXIS_Y, true));
inputManager.addMapping("down", new MouseAxisTrigger(MouseInput.AXIS_Y, false));
inputManager.addListener(new AnalogListener() {
public void onAnalog(String name, float value, float tpf) {
if (panning) {
value *= MOVE_SPEED;
if (name.equals("up")) {
tmp.set(cam.getUp()).multLocal(value);
rotationCenterNode.move(tmp);
}
if (name.equals("down")) {
tmp.set(cam.getUp()).multLocal(-value);
rotationCenterNode.move(tmp);
}
}
}
}, "up", "down");
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
panning = name.equals("rightClick") && isPressed;
}
}, "click", "rightClick");
}
public void setRotationCenter(Vector3f rotationCenter) {
rotationCenterNode.setLocalTranslation(rotationCenter);
}
public void setDefaultSettings() {
setZoomSensitivity(0.03f);
setMinVerticalRotation(-FastMath.HALF_PI / 2f);
setInvertVerticalAxis(true);
setHideCursorOnRotate(false);
setRotationSpeed(7f);
setDragToRotate(true);
}
}