I want moving my ChaseCamera with the right mouse button. Zoom and rotate works well.
I think that’s a very common issue. In each 3D viewer one can move your object with the right mouse button.
If the right button clicked and the mouse moves then the view point to object is changing.
I hope there’s a simple solution.
public class TestChaseCamera extends SimpleApplication {
private Geometry teaGeom;
private ChaseCamera chaseCam;
public static void main(String[] args) {
TestChaseCamera app = new TestChaseCamera();
app.start();
}
@Override
public void simpleInitApp() {
// Load a teapot model
teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
Material mat_tea = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
teaGeom.setMaterial(mat_tea);
rootNode.attachChild(teaGeom);
flyCam.setEnabled(false);
chaseCam = new ChaseCamera(cam, teaGeom, inputManager);
chaseCam.setSmoothMotion(true);
initRaw();
}
public void initRaw(){
inputManager.addRawInputListener(new RawInputListener() {
private boolean isRightButtonPressed = false;
@Override
public void beginInput() { }
@Override
public void endInput() { }
@Override
public void onJoyAxisEvent(JoyAxisEvent evt) { }
@Override
public void onJoyButtonEvent(JoyButtonEvent evt) { }
@Override
public void onMouseMotionEvent(MouseMotionEvent evt) {
if(isRightButtonPressed) {
// here the camera must be moved
}
}
@Override
public void onMouseButtonEvent(MouseButtonEvent evt) {
isRightButtonPressed = evt.getButtonIndex() == MouseInput.BUTTON_RIGHT && evt.isPressed();
}
@Override
public void onKeyEvent(KeyInputEvent evt) { }
@Override
public void onTouchEvent(TouchEvent evt) { }
});
}
}
There is ChaseCameraAppState where you can call the setToggleRotationTrigger method with the correct trigger(s).
You can use ‘new MouseButtonTrigger(MouseInput.BUTTON_RIGHT)’ as trigger.