Exemplo n.º 1
0
        internal void AfterUpdate()
        {
            const float AXIS_EPSILON = 0.000001f;

            for (int jid = 0; jid <= (int)GLFW_Enum.JOYSTICK_LAST; jid++)
            {
                uint index = (uint)jid;

                if (GLFW.JoystickPresent(jid) != 0)
                {
                    if (GLFW.JoystickIsGamepad(jid) != 0 && GLFW.GetGamepadState(jid, ref gamepadState) != 0)
                    {
                        for (int i = 0; i < gamepadState.Buttons.Length; i++)
                        {
                            var button = GamepadButtonToEnum((GLFW_Enum)i);
                            var down   = IsGamepadButtonDown(index, button);
                            var state  = gamepadState.Buttons[i];

                            if (!down && state == 1)
                            {
                                OnGamepadButtonDown(index, button);
                            }
                            else if (down && state == 0)
                            {
                                OnGamepadButtonUp(index, button);
                            }
                        }

                        for (int i = 0; i < gamepadState.Axes.Length; i++)
                        {
                            var axis    = GamepadAxisToEnum((GLFW_Enum)i);
                            var current = GetGamepadAxis(index, axis);
                            var next    = gamepadState.Axes[i];

                            if (Math.Abs(current - next) > AXIS_EPSILON)
                            {
                                OnGamepadAxis(index, axis, next);
                            }
                        }
                    }
                    else
                    {
                        unsafe
                        {
                            char *buttons = (char *)GLFW.GetJoystickButtons(jid, out int buttonCount).ToPointer();
                            for (int i = 0; i < buttonCount; i++)
                            {
                                var button = (uint)i;
                                var down   = IsJoystickButtonDown(index, button);
                                var state  = buttons[i];

                                if (!down && state == 1)
                                {
                                    OnJoystickButtonDown(index, button);
                                }
                                else if (down && state == 0)
                                {
                                    OnJoystickButtonUp(index, button);
                                }
                            }

                            float *axes = (float *)GLFW.GetJoystickAxes(jid, out int axesCount).ToPointer();
                            for (int i = 0; i < axesCount; i++)
                            {
                                var axis    = (uint)i;
                                var current = GetJoystickAxis(index, axis);
                                var next    = axes[i];

                                if (Math.Abs(current - next) > AXIS_EPSILON)
                                {
                                    OnJoystickAxis(index, axis, next);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 public void SetCurrentGLContext(ISystemOpenGL.Context?context)
 {
     if (context is GLFW_GLContext ctx && ctx != null)
     {
         GLFW.MakeContextCurrent(ctx.window);
     }
Exemplo n.º 3
0
 protected override void Disposed()
 {
     GLFW.Terminate();
 }
Exemplo n.º 4
0
 public IntPtr GetGLProcAddress(string name)
 {
     return(GLFW.GetProcAddress(name));
 }