Search in sources :

Example 1 with MouseAxisEvent

use of org.terasology.engine.input.events.MouseAxisEvent in project Terasology by MovingBlocks.

the class InputSystem method processMouseInput.

/**
 * Processes the current input state of the mouse, sends input events and updates bind buttons.
 * <p>
 * Mouse position actions are handled here, while mouse button and mouse wheel actions are handled at {@link
 * #processMouseButtonInput(float, MouseAction)} and {@link #processMouseWheelInput(float, MouseAction)}
 * accordingly.
 *
 * @param delta The length of the current frame.
 */
private void processMouseInput(float delta) {
    if (!isCapturingMouse()) {
        return;
    }
    this.mouse.update();
    Vector2d deltaMouse = mouse.getDelta();
    // process mouse movement x axis
    if (deltaMouse.x != 0) {
        double xValue = deltaMouse.x * inputDeviceConfig.getMouseSensitivity();
        MouseAxisEvent event = MouseAxisEvent.create(MouseAxis.X, xValue, delta);
        send(event);
    }
    // process mouse movement y axis
    if (deltaMouse.y != 0) {
        double yMovement = inputDeviceConfig.isMouseYAxisInverted() ? deltaMouse.y * -1 : deltaMouse.y;
        double yValue = yMovement * inputDeviceConfig.getMouseSensitivity();
        MouseAxisEvent event = MouseAxisEvent.create(MouseAxis.Y, yValue, delta);
        send(event);
    }
    // process mouse clicks
    for (MouseAction action : mouse.getInputQueue()) {
        switch(action.getInput().getType()) {
            case MOUSE_BUTTON:
                processMouseButtonInput(delta, action);
                break;
            case MOUSE_WHEEL:
                processMouseWheelInput(delta, action);
                break;
            default:
                break;
        }
    }
}
Also used : MouseAction(org.terasology.input.device.MouseAction) Vector2d(org.joml.Vector2d) MouseAxisEvent(org.terasology.engine.input.events.MouseAxisEvent)

Example 2 with MouseAxisEvent

use of org.terasology.engine.input.events.MouseAxisEvent in project Terasology by MovingBlocks.

the class EventCopier method copyEvent.

public Event copyEvent(Event toBeCopied) {
    if (toBeCopied instanceof PlaySoundEvent) {
        return toBeCopied;
    } else if (toBeCopied instanceof BindButtonEvent) {
        BindButtonEvent originalEvent = (BindButtonEvent) toBeCopied;
        BindButtonEvent newEvent = (BindButtonEvent) createNewBindEvent(originalEvent);
        newEvent.prepare(originalEvent.getId(), originalEvent.getState(), originalEvent.getDelta());
        inputEventSetup(newEvent, originalEvent);
        return newEvent;
    } else if (toBeCopied instanceof KeyEvent) {
        KeyEvent originalEvent = (KeyEvent) toBeCopied;
        KeyEvent newEvent = createNewKeyEvent(originalEvent);
        inputEventSetup(newEvent, originalEvent);
        return newEvent;
    } else if (toBeCopied instanceof BindAxisEvent) {
        BindAxisEvent originalEvent = (BindAxisEvent) toBeCopied;
        BindAxisEvent newEvent = (BindAxisEvent) createNewBindEvent(originalEvent);
        newEvent.prepare(originalEvent.getId(), (float) originalEvent.getValue(), originalEvent.getDelta());
        inputEventSetup(newEvent, originalEvent);
        return newEvent;
    } else if (toBeCopied instanceof MouseAxisEvent) {
        MouseAxisEvent originalEvent = (MouseAxisEvent) toBeCopied;
        MouseAxisEvent newEvent = createNewMouseAxisEvent(originalEvent);
        inputEventSetup(newEvent, originalEvent);
        return newEvent;
    } else if (toBeCopied instanceof CameraTargetChangedEvent) {
        CameraTargetChangedEvent originalEvent = (CameraTargetChangedEvent) toBeCopied;
        return new CameraTargetChangedEvent(originalEvent.getOldTarget(), originalEvent.getNewTarget());
    } else if (toBeCopied instanceof CharacterMoveInputEvent) {
        CharacterMoveInputEvent originalEvent = (CharacterMoveInputEvent) toBeCopied;
        return new CharacterMoveInputEvent(originalEvent.getSequenceNumber(), originalEvent.getPitch(), originalEvent.getYaw(), originalEvent.getMovementDirection(), originalEvent.isRunning(), originalEvent.isCrouching(), originalEvent.isJumping(), originalEvent.getDeltaMs());
    } else if (toBeCopied instanceof MouseButtonEvent) {
        MouseButtonEvent originalEvent = (MouseButtonEvent) toBeCopied;
        MouseButtonEvent newEvent = new MouseButtonEvent(originalEvent.getButton(), originalEvent.getState(), originalEvent.getDelta());
        newEvent.setMousePosition(originalEvent.getMousePosition());
        inputEventSetup(newEvent, originalEvent);
        return newEvent;
    } else if (toBeCopied instanceof MouseWheelEvent) {
        MouseWheelEvent originalEvent = (MouseWheelEvent) toBeCopied;
        MouseWheelEvent newEvent = new MouseWheelEvent(originalEvent.getMousePosition(), originalEvent.getWheelTurns(), originalEvent.getDelta());
        inputEventSetup(newEvent, originalEvent);
        return newEvent;
    } else if (toBeCopied instanceof GetMaxSpeedEvent) {
        GetMaxSpeedEvent originalEvent = (GetMaxSpeedEvent) toBeCopied;
        GetMaxSpeedEvent newEvent = new GetMaxSpeedEvent(originalEvent.getBaseValue(), originalEvent.getMovementMode());
        newEvent.setModifiers(originalEvent.getModifiers());
        newEvent.setMultipliers(originalEvent.getMultipliers());
        newEvent.setPostModifiers(originalEvent.getPostModifiers());
        return newEvent;
    } else if (toBeCopied instanceof AttackEvent) {
        AttackEvent originalEvent = (AttackEvent) toBeCopied;
        AttackEvent newEvent = new AttackEvent(originalEvent.getInstigator(), originalEvent.getDirectCause());
        return newEvent;
    } else {
        return null;
    }
}
Also used : KeyEvent(org.terasology.engine.input.events.KeyEvent) CameraTargetChangedEvent(org.terasology.engine.input.cameraTarget.CameraTargetChangedEvent) BindButtonEvent(org.terasology.engine.input.BindButtonEvent) MouseWheelEvent(org.terasology.engine.input.events.MouseWheelEvent) GetMaxSpeedEvent(org.terasology.engine.logic.characters.GetMaxSpeedEvent) PlaySoundEvent(org.terasology.engine.audio.events.PlaySoundEvent) BindAxisEvent(org.terasology.engine.input.BindAxisEvent) MouseAxisEvent(org.terasology.engine.input.events.MouseAxisEvent) CharacterMoveInputEvent(org.terasology.engine.logic.characters.CharacterMoveInputEvent) MouseButtonEvent(org.terasology.engine.input.events.MouseButtonEvent) AttackEvent(org.terasology.engine.logic.characters.events.AttackEvent)

Aggregations

MouseAxisEvent (org.terasology.engine.input.events.MouseAxisEvent)2 Vector2d (org.joml.Vector2d)1 PlaySoundEvent (org.terasology.engine.audio.events.PlaySoundEvent)1 BindAxisEvent (org.terasology.engine.input.BindAxisEvent)1 BindButtonEvent (org.terasology.engine.input.BindButtonEvent)1 CameraTargetChangedEvent (org.terasology.engine.input.cameraTarget.CameraTargetChangedEvent)1 KeyEvent (org.terasology.engine.input.events.KeyEvent)1 MouseButtonEvent (org.terasology.engine.input.events.MouseButtonEvent)1 MouseWheelEvent (org.terasology.engine.input.events.MouseWheelEvent)1 CharacterMoveInputEvent (org.terasology.engine.logic.characters.CharacterMoveInputEvent)1 GetMaxSpeedEvent (org.terasology.engine.logic.characters.GetMaxSpeedEvent)1 AttackEvent (org.terasology.engine.logic.characters.events.AttackEvent)1 MouseAction (org.terasology.input.device.MouseAction)1