将小值映射到大值以及反之亦然的方法
我目前正在开发一个允许 Wiimote 用作计算机鼠标的工具,但遇到了一个问题。 Wiimote 返回的 x 和 y 坐标与我的电脑屏幕分辨率相比非常小,我正在寻找一种方法将这些小值映射到我的大分辨率值。
例如,pc 的最小 x 值为 0,最大 x 值为 1300,我也知道 wiimote 最小 x 值为 0,但不知道最大值。
我只希望 Wiimote 在屏幕上移动鼠标指针而不跨越屏幕坐标。
I am currently working on a tool that will allow Wiimote to be used as computer mouse and am stuck in a problem. The wiimote returns x and y co-ordinates which are very small as compared to screen resolution of my pc and I am looking for a way to map these small values to my large resolution values.
For example, pc least x value is 0 and most x value is 1300 and I also know wiimote least x value is 0 but don't know most value.
I just want the wiimote to move mouse pointer on screen without crossing the screen co-ordinates.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
大最大值/小最大值 * 小值 = 大值
Large Maximum / Small Maximum * Small Value = Large Value
你的问题实际上和你想象的不一样。我实际上没有 Wiimote(这么奇怪的名字..),但我假设它返回距离而不是位置。所以你要做的就是有一个光标位置:
每次收到更新事件时,你都会添加到你的点的距离:
其中
sx
和sy
是缩放值为 X 和 Y 坐标。每个从 1.0 开始,不断尝试,直到获得所需的移动速率。Your problem is actually different than what you think it is. I don't actually have a Wiimote (such a screwy name..) but I'd assume it returns distance as opposed to position. So what you have to do is have a cursor position:
and every time you receive an update event, you add the distance to your point:
where
sx
andsy
are scaling values for the X and Y coordonates. Start with 1.0 for each and play around until you get the movement rate you want.