func (i *input) update(window *glfw.Window, scale int) error { for g, e := range glfwKeyCodeToKey { i.keyPressed[e] = window.GetKey(g) == glfw.Press } for g, e := range glfwMouseButtonToMouseButton { i.mouseButtonPressed[e] = window.GetMouseButton(g) == glfw.Press } x, y := window.GetCursorPos() i.cursorX = int(math.Floor(x)) / scale i.cursorY = int(math.Floor(y)) / scale for id := glfw.Joystick(0); id < glfw.Joystick(len(i.gamepads)); id++ { if !glfw.JoystickPresent(id) { continue } axes32 := glfw.GetJoystickAxes(id) i.gamepads[id].axisNum = len(axes32) for a := 0; a < len(i.gamepads[id].axes); a++ { if len(axes32) <= a { i.gamepads[id].axes[a] = 0 continue } i.gamepads[id].axes[a] = float64(axes32[a]) } buttons := glfw.GetJoystickButtons(id) i.gamepads[id].buttonNum = len(buttons) for b := 0; b < len(i.gamepads[id].buttonPressed); b++ { if len(buttons) <= b { i.gamepads[id].buttonPressed[b] = false continue } i.gamepads[id].buttonPressed[b] = glfw.Action(buttons[b]) == glfw.Press } } return nil }
func (e *EventHandler) JoystickButtons(joystick Joystick) []byte { return glfw.GetJoystickButtons(glfw.Joystick(joystick)) }
func (e *EventHandler) JoystickAxes(joystick Joystick) []float32 { return glfw.GetJoystickAxes(glfw.Joystick(joystick)) }
func (e *EventHandler) JoystickPresent(joystick Joystick) bool { return glfw.JoystickPresent(glfw.Joystick(joystick)) }