Ejemplo n.º 1
0
    public override void _Input(InputEvent @event)
    {
        if (@event is InputEventMouseMotion)
        {
            InputEventMouseMotion mouse = (InputEventMouseMotion)@event;
            int relative = (int)mouse.Relative.x;
            try{
                Int32 movel = Convert.ToInt32(relative / (Godot.OS.GetRealWindowSize().x / 24));
                GD.Print(movel);
                Graphics.starton = Convert.ToByte((Graphics.starton + movel) % 24);
                GD.Print(Graphics.starton);
            }catch (Exception e) {}
            return;
        }
        Vector2 tempos = Pos;

        tempos.x += Input.IsActionPressed("ui_left") ? -1 : 0;
        tempos.x += Input.IsActionPressed("ui_right") ? 1 : 0;
        tempos.y += Input.IsActionPressed("ui_up") ? 1 : 0;
        tempos.y += Input.IsActionPressed("ui_down") ? -1 : 0;
        try{
            if ((int)map[(int)tempos.x, (int)tempos.y] < 5 && !entities.ContainsKey(tempos))
            {
                Pos = tempos;
                Graphics.reload();
            }
        }catch (System.IndexOutOfRangeException) {}

        base._Input(@event);
    }
    //Camera movement/Pause start
    public override void _Input(InputEvent @event)
    {
        //Changes camera and rotation values depending on mouse movement
        if (@event is InputEventMouseMotion && Input.GetMouseMode() == Input.MouseMode.Captured)
        {
            InputEventMouseMotion mouseEvent = @event as InputEventMouseMotion;
            head_.RotateX(Mathf.Deg2Rad(-mouseEvent.Relative.y * MouseSenstivity));
            RotateY(Mathf.Deg2Rad(-mouseEvent.Relative.x * MouseSenstivity));
        }
        //Changes mouse mode
        if (Input.IsActionJustPressed("ui_cancel"))
        {
            if (Input.GetMouseMode() == Input.MouseMode.Captured)
            {
                Input.SetMouseMode(Input.MouseMode.Visible);
            }
            else
            {
                Input.SetMouseMode(Input.MouseMode.Captured);
            }
        }
        //Clamps the head x rotation to -90 and 90
        Vector3 HeadRotation = head_.RotationDegrees;

        HeadRotation.x        = Mathf.Clamp(head_.RotationDegrees.x, -90, 90);
        head_.RotationDegrees = HeadRotation;
    }
Ejemplo n.º 3
0
    public override void InteractUpdate(InputEventMouseMotion ev, ref Transform targetTransform)
    {
        var currentAngle = planePosition(ev.Position).Angle();

        targetTransform.basis = targetTransform.basis.Rotated(Transform.basis.Column0.Normalized(), currentAngle - lastAngle);
        lastAngle             = currentAngle;
    }
Ejemplo n.º 4
0
    public void OnInput(InputEvent Event)
    {
        if (Event.IsActionPressed("Click"))
        {
            Global.OnNodeClick = true;
            Movable            = true;
            for (int NodeIndex = 0; NodeIndex < Global.SelectedNodes.Count; NodeIndex++)
            {
                Global.SelectedNodes[NodeIndex].Movable = true;
            }
        }

        else if (Event.IsActionReleased("Click"))
        {
            Global.OnNodeClick = false;
            Movable            = false;
        }

        else if (Movable && Event.GetType() == typeof(InputEventMouseMotion))
        {
            Global.OnNodeClick = true;
            InputEventMouseMotion newEvent = (InputEventMouseMotion)Event;
            for (int NodeIndex = 0; NodeIndex < Global.SelectedNodes.Count; NodeIndex++)
            {
                Global.SelectedNodes[NodeIndex].RectPosition += newEvent.Relative;
            }
        }
    }
Ejemplo n.º 5
0
    public override void _Input(InputEvent ev)
    {
        if (!CanMove)
        {
            return;
        }

        if (ev is InputEventKey key && key.Scancode == (int)KeyList.Tab && key.Pressed)
        {
            if (Input.GetMouseMode() == Input.MouseMode.Visible)
            {
                Input.SetMouseMode(Input.MouseMode.Captured);
            }
            else
            {
                Input.SetMouseMode(Input.MouseMode.Visible);
            }
        }

        if (ev is InputEventMouseMotion && Input.GetMouseMode() == Input.MouseMode.Captured)
        {
            InputEventMouseMotion motion = ev as InputEventMouseMotion;

            Rotation = new Vector3(Rotation.x - motion.Relative.y * MouseSens, Rotation.y, Rotation.z);
            RotateY(-motion.Relative.x * MouseSens);
        }
    }
Ejemplo n.º 6
0
        private void OnWindowMouseEntered()
        {
            var evt = new InputEventMouseMotion();

            evt.Position = Vector2.Left * 100_000_000;
            Main.SendInput(evt);
        }
Ejemplo n.º 7
0
 public void HandleCameraRotation(Player instance, InputEventMouseMotion m)
 {
     instance.cameraBase.RotateY(-m.Relative.x * instance.currentCameraRotationSpeed);
     instance.cameraBase.Orthonormalize();
     instance.camera_x_rot       = Mathf.Clamp(instance.camera_x_rot + m.Relative.y * instance.currentCameraRotationSpeed, Mathf.Deg2Rad(instance.CameraXmin), Mathf.Deg2Rad(instance.CameraXmax));
     instance.cameraRot.Rotation = new Vector3(instance.camera_x_rot, instance.cameraBase.Rotation.y, instance.cameraBase.Rotation.z);
 }
Ejemplo n.º 8
0
        private void HandleMouse(InputEventMouseMotion iemm)
        {
            Vector2 motion = -iemm.GetRelative();

            sharedState.RotateCamera(new Vector3 {
                x = motion.y, y = motion.x
            } *mouseSensitivity);
        }
Ejemplo n.º 9
0
    private void HandleRotation(InputEventMouseMotion mouseMotion)
    {
        this.RotationDegrees -= new Vector3(0, mouseMotion.Relative.x * this.mouseSensitivy, 0);
        float cameraPivotXRotationDegree = this.cameraPivot.RotationDegrees.x - mouseMotion.Relative.y * this.mouseSensitivy;

        cameraPivotXRotationDegree       = Mathf.Clamp(cameraPivotXRotationDegree, this.minPitch, this.maxPitch);
        this.cameraPivot.RotationDegrees = new Vector3(cameraPivotXRotationDegree, 0, 0);
    }
Ejemplo n.º 10
0
 public override void _Input(InputEvent ev)
 {
     if (ev is InputEventMouseMotion)
     {
         InputEventMouseMotion m = (InputEventMouseMotion)ev;
         relative_mouse += m.Relative.x;
     }
 }
Ejemplo n.º 11
0
 public override void _Input(InputEvent @event)
 {
     if (@event is InputEventMouseMotion)
     {
         InputEventMouseMotion input = @event as InputEventMouseMotion;
         camera_change = input.Relative;
     }
 }
Ejemplo n.º 12
0
    private void HandleCameraRotation(InputEventMouseMotion mouseMotion)
    {
        // Rotate up / down
        Head.RotateX(Mathf.Deg2Rad(-mouseMotion.Relative.y * MouseSensitivity));
        Head.RotationDegrees = new Vector3(Mathf.Clamp(Head.RotationDegrees.x, -70, 70), Head.RotationDegrees.y, Head.RotationDegrees.z);

        // Rotate left / right
        RotateY(Mathf.Deg2Rad(-mouseMotion.Relative.x * MouseSensitivity));
    }
Ejemplo n.º 13
0
    public override void _Input(InputEvent motionUnknown)
    {
        InputEventMouseMotion motion = motionUnknown as InputEventMouseMotion;

        if (motion != null)
        {
            MouseMove = motion.Relative;
        }
    }
Ejemplo n.º 14
0
    public override void _Input(InputEvent inputEvent)
    {
        InputEventMouseMotion mouseMotion = inputEvent as InputEventMouseMotion;

        if (mouseMotion != null)
        {
            mouseMove = mouseMotion.Relative;
        }
    }
Ejemplo n.º 15
0
 public override void _Input(InputEvent @event)
 {
     if (@event.IsClass("InputEventMouseMotion"))
     {
         InputEventMouseMotion mouse = (InputEventMouseMotion)@event;
         Vector2 mousepos            = mouse.GlobalPosition;
         Camera  cam = (Camera)GetNode("../Camera");
         lookinat = cam.ProjectPosition(mousepos);
     }
 }
Ejemplo n.º 16
0
    public override void _Input(Godot.InputEvent evt)
    {
        InputEventMouseMotion mot = evt as InputEventMouseMotion;

        if (mot != null)
        {
            mousePosition = mot.GlobalPosition;
            mouseMovement = mot.Relative;
        }
    }
Ejemplo n.º 17
0
    public override void _Input(InputEvent ev)
    {
        if (ev is InputEventMouseButton)
        {
            InputEventMouseButton evMB = (InputEventMouseButton)ev;
            if (evMB.ButtonIndex == (int)ButtonList.Middle)
            {
                dragging = false;
                if (evMB.Pressed)
                {
                    dragging = true;
                }
            }
            else if (evMB.ButtonIndex == (int)ButtonList.WheelDown)
            {
                if (evMB.Pressed)
                {
                    desiredCameraZoom += 1f + desiredCameraZoom * .1f;
                }
            }
            else if (evMB.ButtonIndex == (int)ButtonList.WheelUp)
            {
                if (evMB.Pressed)
                {
                    desiredCameraZoom -= 1f + desiredCameraZoom * .1f;
                }
            }
        }

        if (ev is InputEventMouseMotion)
        {
            InputEventMouseMotion evMM = (InputEventMouseMotion)ev;

            if (dragging)
            {
                if (evMM.Shift)
                {
                    Vector3 localMotion = new Vector3(
                        evMM.Relative.x, evMM.Relative.y, 0f
                        ) * cameraZoom * 0.001f;
                    localMotion.y          = -localMotion.y;
                    desiredAnchorPosition -= GlobalTransform.basis.Xform(localMotion);
                }
                else
                {
                    Vector3 rot = desiredAnchorRotation;

                    rot.y -= evMM.Relative.x * .25f;
                    rot.x -= evMM.Relative.y * .25f;

                    desiredAnchorRotation = rot;
                }
            }
        }
    }
Ejemplo n.º 18
0
 public override void _Input(InputEvent @event)
 {
     if (@event is InputEventMouseMotion && Input.GetMouseMode() == Input.MouseMode.Captured)
     {
         InputEventMouseMotion mouseEvent = @event as InputEventMouseMotion;
         RotateY(Mathf.Deg2Rad(-mouseEvent.Relative.x * MouseSensitivity));
         Head.RotateX(Mathf.Deg2Rad(-mouseEvent.Relative.y * MouseSensitivity));
         Vector3 HeadRot = Head.RotationDegrees;
         HeadRot.x            = Mathf.Clamp(HeadRot.x, -89, 89);
         Head.RotationDegrees = HeadRot;
     }
 }
        public override void _Input(InputEvent @event)
        {
            if (@event is InputEventMouseMotion && Input.GetMouseMode() == Input.MouseMode.Captured)
            {
                InputEventMouseMotion mouseEvent = @event as InputEventMouseMotion;
                rotationHelper.RotateX(Mathf.Deg2Rad(-1.0f * mouseEvent.Relative.y * MouseSensitivity));
                RotateY(Mathf.Deg2Rad(-mouseEvent.Relative.x * MouseSensitivity));

                Vector3 cameraRot = rotationHelper.RotationDegrees;
                cameraRot.x = Mathf.Clamp(cameraRot.x, -70, 70);
                rotationHelper.RotationDegrees = cameraRot;
            }
        }
Ejemplo n.º 20
0
    public override void _Input(InputEvent @event)
    {
        if (@event is InputEventMouseMotion && Input.GetMouseMode() == Input.MouseMode.Captured)
        {
            InputEventMouseMotion mouseMotion = (InputEventMouseMotion)@event;
            rotationBodyTop.RotateX(Mathf.Deg2Rad(mouseMotion.Relative.y * MOUSE_SENSITIVITY));
            this.RotateY(Mathf.Deg2Rad(mouseMotion.Relative.x * MOUSE_SENSITIVITY * -1));

            Vector3 camera_rot = rotationBodyTop.GetRotationDegrees();
            camera_rot.x = Mathf.Clamp(camera_rot.x, -70, 70);
            rotationBodyTop.SetRotationDegrees(camera_rot);
        }
    }
Ejemplo n.º 21
0
    public override void _Input(InputEvent @event)
    {
        if (@event is InputEventMouseMotion && Input.GetMouseMode() == Input.MouseMode.Captured)
        {
            InputEventMouseMotion mouseEvent = @event as InputEventMouseMotion;
            head.RotateX(Mathf.Deg2Rad(mouseEvent.Relative.y * -mouseSensitivity));
            RotateY(Mathf.Deg2Rad(-mouseEvent.Relative.x * mouseSensitivity));

            Vector3 cameraRot = head.RotationDegrees;
            cameraRot.x          = Mathf.Clamp(cameraRot.x, -85, 85);
            head.RotationDegrees = cameraRot;
        }
    }
Ejemplo n.º 22
0
    /// <summary>
    /// Move the camera depending of the key pressed or the motion detected
    /// </summary>
    /// <param name="inputEvent"></param>
    public override void _Input(InputEvent inputEvent)
    {
        base._Input(inputEvent);

        // Zoom when wheel is used
        if (inputEvent is InputEventMouseButton)
        {
            InputEventMouseButton mouseButtonEvent = inputEvent as InputEventMouseButton;

            if (mouseButtonEvent.IsAction("camera_zoom_out"))
            {
                if (this.Zoom.x < MAX_ZOOM_OUT.x)
                {
                    this.Zoom = this.Zoom + Vector2.One * ZOOM_SPEED;
                }
            }
            else if (mouseButtonEvent.IsAction("camera_zoom_in"))
            {
                if (this.Zoom.x > MAX_ZOOM_IN.x)
                {
                    this.Zoom = this.Zoom - Vector2.One * ZOOM_SPEED;
                }
            }
        }

        // Detect if the right button is just pressed or just released
        // and start camera movement
        if (inputEvent is InputEventMouseButton)
        {
            InputEventMouseButton mouseButtonEvent = inputEvent as InputEventMouseButton;

            if (mouseButtonEvent.IsActionPressed("camera_move_mouse"))
            {
                Input.SetMouseMode(Input.MouseMode.Captured);
            }

            if (mouseButtonEvent.IsActionReleased("camera_move_mouse"))
            {
                Input.SetMouseMode(Input.MouseMode.Visible);
            }
        }

        // If motion is detected and the right button is pressed, the camera is moved
        if (inputEvent is InputEventMouseMotion & Input.IsActionPressed("camera_move_mouse"))
        {
            InputEventMouseMotion mouseMotionEvent = inputEvent as InputEventMouseMotion;

            this.Translate(mouseMotionEvent.Relative);
        }
    }
Ejemplo n.º 23
0
    public override void _Input(InputEvent @event)
    {
        base._Input(@event);

        // Handle camera rotation
        if (Input.GetMouseMode() == Input.MouseMode.Captured)
        {
            InputEventMouseMotion mouseMotion = @event as InputEventMouseMotion;
            if (mouseMotion != null)
            {
                HandleCameraRotation(mouseMotion);
            }
        }
    }
Ejemplo n.º 24
0
    public override void _Input(InputEvent @event)
    {
        if (Main.i.gameInputActive == false)
        {
            return;
        }
        InputEventMouseMotion motion = @event as InputEventMouseMotion;

        if (motion == null)
        {
            return;
        }
        _fpsCtrl.ProcessMouseMotion(motion, ZqfGodotUtils.GetWindowToScreenRatio());
    }
Ejemplo n.º 25
0
    public override void _Input(InputEvent @event)
    {
        if (@event is InputEventMouseMotion && Input.GetMouseMode() == Input.MouseMode.Captured)
        {
            InputEventMouseMotion mouseEvent = @event as InputEventMouseMotion;

            _RotHelp.RotateX(Mathf.Deg2Rad(mouseEvent.Relative.y * MouseSens));

            RotateY(Mathf.Deg2Rad(-mouseEvent.Relative.x * MouseSens));

            Vector3 camRot = _RotHelp.RotationDegrees;
            camRot.x = Mathf.Clamp(camRot.x, -75.0f, 75.0f);
            _RotHelp.RotationDegrees = camRot;
        }
    }
Ejemplo n.º 26
0
        public void ProcessMouseMotion(InputEventMouseMotion motion, Vector2 screenRatio)
        {
            float sensitivity = MOUSE_SENSITIVITY;

            Vector2 ratio      = Main.i.GetWindowToScreenRatio();
            float   mouseMoveX = motion.Relative.x * sensitivity * ratio.x;

            // flip as we want moving mouse to the right to rotate left
            mouseMoveX = -mouseMoveX;
            yaw       += mouseMoveX;

            float mouseMoveY = motion.Relative.y * sensitivity * ratio.y;

            pitch += mouseMoveY;
        }
Ejemplo n.º 27
0
    public override void _Input(InputEvent @event)
    {
        if (@event is InputEventMouseMotion && Input.GetMouseMode() == Input.MouseMode.Captured)
        {
            //Cast is needed to be able to access correct properties
            InputEventMouseMotion mouse_event = (InputEventMouseMotion)@event;

            rotation_helper.RotateX(Mathf.Deg2Rad(mouse_event.Relative.y * MOUSE_SENSITIVITY));

            this.RotateY(Mathf.Deg2Rad(mouse_event.Relative.x * MOUSE_SENSITIVITY * -1));

            var camera_rot = rotation_helper.RotationDegrees;
            camera_rot.x = Mathf.Clamp(camera_rot.x, -70, 70);
            rotation_helper.RotationDegrees = camera_rot;
        }
    }
Ejemplo n.º 28
0
 public override void _Input(InputEvent @event)
 {
     if (@event is InputEventMouseMotion && Input.GetMouseMode() == Input.MouseMode.Captured)
     {
         InputEventMouseMotion m = @event as InputEventMouseMotion;
         if (m.Relative.Normalized().x > 0 && this.Steering > -0.8f)
         {
             this.Steering -= 1f * _steeringSensitivity;
             this._steeringWheel.RotateObjectLocal(Vector3.Up, -2f * _steeringSensitivity);
         }
         else if (m.Relative.Normalized().x < 0 && this.Steering < 0.8f)
         {
             this.Steering += 1f * _steeringSensitivity;
             this._steeringWheel.RotateObjectLocal(Vector3.Up, 2f * _steeringSensitivity);
         }
     }
 }
Ejemplo n.º 29
0
    public override void _Input(InputEvent @event)
    {
        if (_isDead)
        {
            return;
        }
        // Rotates player and camera based on mouse input, but only if it's captured.
        if (@event is InputEventMouseMotion && Input.GetMouseMode() == Input.MouseMode.Captured)
        {
            InputEventMouseMotion mouseEvent = @event as InputEventMouseMotion;
            // Rotate camera around the x-axis
            _rotationHelper.RotateX(Mathf.Deg2Rad(mouseEvent.Relative.y * MouseSensitivity));
            // Rotate player around the y-axis
            RotateY(Mathf.Deg2Rad(-mouseEvent.Relative.x * MouseSensitivity));

            Vector3 cameraRot = _rotationHelper.RotationDegrees;
            // Clamp rotation around x-axis so that player doesn't overturn
            cameraRot.x = Mathf.Clamp(cameraRot.x, -89, 89);
            _rotationHelper.RotationDegrees = cameraRot;
            if (mouseEvent.ButtonMask == 4 || mouseEvent.ButtonMask == 5)
            {
                if (mouseEvent.ButtonMask == 4)
                {
                    _mouseScrollValue += _mouseSensitivityScrollWheel;
                }
                else if (mouseEvent.ButtonMask == 5)
                {
                    _mouseScrollValue -= _mouseSensitivityScrollWheel;
                }

                _mouseScrollValue = Mathf.Clamp(_mouseScrollValue, 0, _weaponNumberToName.Count - 1);

                if (!_changingWeapon && !_reloadingWeapon)
                {
                    int _roundMouseScrollValue = (int)Mathf.Round(_mouseScrollValue);
                    if (_weaponNumberToName[_roundMouseScrollValue] != _currentWeaponName)
                    {
                        _changingWeaponName = _weaponNumberToName[_roundMouseScrollValue];
                        _changingWeapon     = true;
                        _mouseScrollValue   = _roundMouseScrollValue;
                    }
                }
            }
        }
    }
Ejemplo n.º 30
0
    public override void _Input(InputEvent evt)
    {
        if (evt is InputEventMouseButton && Input.GetMouseMode() != Input.MouseMode.Captured)
        {
            Input.SetMouseMode(Input.MouseMode.Captured);
        }

        if (evt is InputEventMouseMotion && Input.GetMouseMode() == Input.MouseMode.Captured)
        {
            InputEventMouseMotion mouseEvent = evt as InputEventMouseMotion;
            _rotationHelper.RotateX(Mathf.Deg2Rad(-mouseEvent.Relative.y * MouseSensitivity));
            RotateY(Mathf.Deg2Rad(-mouseEvent.Relative.x * MouseSensitivity));

            Vector3 cameraRot = _rotationHelper.RotationDegrees;
            cameraRot.x = Mathf.Clamp(cameraRot.x, -70, 70);
            _rotationHelper.RotationDegrees = cameraRot;
        }
    }