如何使用 Pygame 设置 Xbox One 控制器触发器的范围? [英] How can I set the range for Xbox One controller Triggers using Pygame?

查看:29
本文介绍了如何使用 Pygame 设置 Xbox One 控制器触发器的范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Pygame 1.9.2 和 Python 3.4 为机器人创建控制程序.控制器是通过 USB 连接的新 Xbox One 控制器,可与 pygame 正常工作.问题是触发按钮被认为是轴,根据您按下的力度,它会给出从 -1 到 1 的值.有没有办法将其更改为从 0 到 1 的范围或任何其他不包含负数的范围?

I am using Pygame 1.9.2 with Python 3.4 to create a control program for a robot. The controller is a new Xbox One controller connected via USB which is working fine with pygame. The problem is that the trigger buttons are considered Axes which give values from -1 to 1 depending on how hard you press. Is there a way to change this to a range from 0 to 1 or any other range that does not include negative numbers?

谢谢

推荐答案

(x + 1.0)/2.0 其中 x 是你从控制器得到的任何东西应该给你0..1 的范围(+ 1.0 是让你进入范围 0..2)

(x + 1.0) / 2.0 where x is whatever you get from the controller should give you a range of 0..1 (the + 1.0 is to get you in the range 0..2)

这篇关于如何使用 Pygame 设置 Xbox One 控制器触发器的范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆