Algorithm of the joystick on the touchable screen

天大地大妈咪最大 提交于 2019-12-04 23:49:41

问题


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

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)?


回答1:


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.

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.



来源:https://stackoverflow.com/questions/11807047/algorithm-of-the-joystick-on-the-touchable-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!