将小值映射到大值以及反之亦然的方法

发布于 2024-09-18 10:48:42 字数 220 浏览 3 评论 0原文

我目前正在开发一个允许 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦年海沫深 2024-09-25 10:48:42

大最大值/小最大值 * 小值 = 大值

Large Maximum / Small Maximum * Small Value = Large Value

不再让梦枯萎 2024-09-25 10:48:42

你的问题实际上和你想象的不一样。我实际上没有 Wiimote(这么奇怪的名字..),但我假设它返回距离而不是位置。所以你要做的就是有一个光标位置:

Point pt=new Point(Width/2, Height/2);
// initialized in the center of the screen

每次收到更新事件时,你都会添加到你的点的距离:

// say you get the distance in dx and dy
pt.x=Math.Max(0,Math.Min(Width,pt.x+dx*sx));  // clamped on screen
pt.y=Math.Max(0,Math.Min(Height,pt.y+dy*sy)); // clamped on screen
// and update your UI acordingly

其中 sxsy 是缩放值为 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:

Point pt=new Point(Width/2, Height/2);
// initialized in the center of the screen

and every time you receive an update event, you add the distance to your point:

// say you get the distance in dx and dy
pt.x=Math.Max(0,Math.Min(Width,pt.x+dx*sx));  // clamped on screen
pt.y=Math.Max(0,Math.Min(Height,pt.y+dy*sy)); // clamped on screen
// and update your UI acordingly

where sx and sy 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文