操纵杆的触摸屏幕上的算法 [英] Algorithm of the joystick on the touchable screen

查看:214
本文介绍了操纵杆的触摸屏幕上的算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想模拟喜欢这幅画在触摸屏上的模拟操纵杆。

I would like to simulate an analog joystick on the touchable screen like this picture.

当棍子区域的中心设置为(CX,CY),我应该怎么计算的X方向的比例和Y方向比(-1.0〜1.0),从触摸的位置(TX,TY)?

When the center of the stick area is set to (cx, cy), how should I calculate X-direction ratio and Y-direction ratio(-1.0~1.0) from the touched position(tx, ty)?

推荐答案

的x方向比为(TX-CX)/ r,其中r是圆的半径大小。同样,y方向比为(TY-CY)/ r次。

The x direction ratio is (tx-cx)/r, where r is the radius magnitude of the circle. Similarly, the y direction ratio is (ty-cy)/r.

我假定在画面的右方向为x轴右旋笛卡尔坐标。否则,你可能需要乘以(-1),以调整方向。

I am assuming a right-handed cartesian coordinate with x axis in the direction of the right of the picture. Otherwise, you may need to multiply a (-1) to adjust the direction.

这篇关于操纵杆的触摸屏幕上的算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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