use of com.ardor3d.input.logical.MouseWheelMovedCondition in project energy3d by concord-consortium.
the class CameraControl method setupMouseTriggers.
public void setupMouseTriggers(final LogicalLayer layer, final boolean dragOnly) {
// Mouse look
final Predicate<TwoInputStates> someMouseDown = Predicates.or(TriggerConditions.leftButtonDown(), Predicates.or(TriggerConditions.rightButtonDown(), TriggerConditions.middleButtonDown()));
final Predicate<TwoInputStates> dragged = Predicates.and(TriggerConditions.mouseMoved(), Predicates.and(someMouseDown, Predicates.not(new KeyHeldCondition(Key.LCONTROL))));
final TriggerAction dragAction = new TriggerAction() {
// Test boolean to allow us to ignore first mouse event. First event can wildly vary based on platform.
private boolean firstPing = true;
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (!enabled || !mouseEnabled) {
return;
}
final MouseState mouse = inputStates.getCurrent().getMouseState();
if (mouse.getDx() != 0 || mouse.getDy() != 0) {
if (!firstPing) {
final boolean left = leftMouseButtonEnabled && mouse.getButtonState(MouseButton.LEFT) == ButtonState.DOWN;
final boolean right = rightMouseButtonEnabled && mouse.getButtonState(MouseButton.RIGHT) == ButtonState.DOWN;
final boolean middle = mouse.getButtonState(MouseButton.MIDDLE) == ButtonState.DOWN;
if (left && leftButtonAction == ButtonAction.MOVE || right && rightButtonAction == ButtonAction.MOVE) {
// increase the factor from 150 to speed up moving in the top view
final double fac = Camera.getCurrentCamera().getLocation().length() * 200;
final double dx = -mouse.getDx() * fac / Camera.getCurrentCamera().getWidth();
final double dy = -mouse.getDy() * fac / Camera.getCurrentCamera().getHeight();
move(source.getCanvasRenderer().getCamera(), dx, dy);
SceneManager.getInstance().getCameraNode().updateFromCamera();
Scene.getInstance().updateEditShapes();
} else if (left && leftButtonAction == ButtonAction.ROTATE || right && rightButtonAction == ButtonAction.ROTATE) {
rotate(source.getCanvasRenderer().getCamera(), -mouse.getDx(), -mouse.getDy());
SceneManager.getInstance().getCameraNode().updateFromCamera();
Scene.getInstance().updateEditShapes();
} else if (middle || left && leftButtonAction == ButtonAction.ZOOM || right && rightButtonAction == ButtonAction.ZOOM) {
zoom(source, tpf, -mouse.getDy() * getCurrentExtent() / 100);
}
} else {
firstPing = false;
}
}
}
};
_mouseTrigger = new InputTrigger(dragOnly ? dragged : TriggerConditions.mouseMoved(), dragAction);
layer.registerTrigger(_mouseTrigger);
layer.registerTrigger(new InputTrigger(new MouseWheelMovedCondition(), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
zoom(source, tpf, inputStates.getCurrent().getMouseState().getDwheel() * getCurrentExtent() / 20);
}
}));
}
Aggregations