长话短说,我有一个 Oculus dk2 VR 耳机、一个蓝牙适配器和 psmove 运动控制器。我玩的《毁灭战士3》完全是VR游戏,你可以用鼠标在视野之外单独控制瞄准。
现在我能够让我的 psmove 像带有内置陀螺仪的鼠标一样工作,这听起来比实际更困难。我使用一个名为 psmoveservice 的应用程序,它可以通过蓝牙将 psmove 连接到电脑,然后我使用另一个名为 psmovefreepiebridge 的应用程序,它将原始数据发送到一个名为 freepie 的应用程序。
Freepie 基于 python 语法,您可以导入库。我从这段代码开始,它将一些按钮分配给 psmove,并使 psmove 像鼠标一样工作。
def update():
#define globals
#define constants
mag = 1000
dz = 0.005
i=0
j=0
#bind left mouse to cross button
#Right mouse to circle button
#Middle mouse to move
mouse.leftButton = joystick[j].getDown(14)
mouse.rightButton = joystick[j].getDown(13)
mouse.middleButton = joystick[j].getDown(19)
#Mouse movement using Gryoscope
# Only moves when the trigger is held down
mdX = -1 * filters.deadband(filters.delta(freePieIO[i].yaw),dz) * mag
mdY = -1 * filters.deadband(filters.delta(freePieIO[i].pitch),dz) * mag
if joystick[j].getDown(20):
mouse.deltaX = mdX
mouse.deltaY = mdY
if starting:
freePieIO[0].update += update
当然,现在因为 psmove 在这里不使用任何位置跟踪,所以它与游戏中的瞄准失去了很多对齐,尤其是在改变方向之后。我可以通过瞄准枪所在的位置并按住一个按钮来将其重新对齐,但我认为这有点麻烦,并在切换按钮中更改了此按钮。它工作得很好,但问题是有时目标不在我的视野范围内,这让我在必须搜索我的枪在哪里时变得非常烦人。
我想要的是,当我按下按钮时,目标会移动到中心,因为您主要瞄准您所看的地方,我知道您在想什么,为什么不将耳机与十字准线对齐,但问题是,如果当你想要瞄准某个东西时,你会先看它,但你的眼球瞄准得越仔细。它也不像用枪瞄准那么有趣。
所以我认为它会工作得很好,然后更改了我的代码,这样当我按下按钮时,鼠标就会移动到屏幕中央。这是代码(它还有一些其他代码来映射按钮)
def update():
#define globals
#define constants
mag = 1000
dz = 0.005
i=0
j=0
#bind left mouse to trigger button
#Right mouse to circle
#Middle mouse to triangle
#up arrow key to square
#down arrow key to cross
#B Key to select ps button
#N key to select button
#Esc key to start button
mouse.leftButton = joystick[j].getDown(20)
mouse.rightButton = joystick[j].getDown(13)
mouse.middleButton = joystick[j].getDown(12)
keyboard.setKey(Key.UpArrow, joystick[j].getDown(15))
keyboard.setKey(Key.DownArrow, joystick[j].getDown(14))
keyboard.setKey(Key.B, joystick[j].getDown(16))
keyboard.setKey(Key.N, joystick[j].getDown(0))
keyboard.setKey(Key.Escape, joystick[j].getDown(3))
#Mouse movement using Gryoscope
# move button centers aim
mdX = -1 * filters.deadband(filters.delta(freePieIO[i].yaw),dz) * mag
mdY = -1 * filters.deadband(filters.delta(freePieIO[i].pitch),dz) * mag
mouse.deltaX = mdX
mouse.deltaY = mdY
if joystick[j].getDown(19):
import ctypes
ctypes.windll.user32.SetCursorPos(1000, 500)
if starting:
freePieIO[0].update += update
现在用于将鼠标设置到屏幕中心的命令是 setcursor 命令,该命令可以正常工作,只是在游戏中不起作用。
通过进行一些研究,我意识到游戏不使用窗口的鼠标位置,而是使用来自鼠标驱动程序的原始数据,或者类似的东西。
所以我认为我只能通过使用一段代码来解决这个问题,该代码在按下一个按钮时记住鼠标位置,然后在按下另一个按钮时返回到该位置。我可以弄清楚按钮映射、记住并返回到某个位置的代码,但我却做不到。
要么是这样,要么是与其中一个驱动程序(鼠标驱动程序、直接输入)通信,这更加困难。
因此,如果有人知道我需要从哪里开始,我会非常高兴。
我认为你可以使用
pyautogui
来做到这一点。
import pyautogui
pyautogui.position() # gets mouse position returns pixel value E.G: (975,400)
pyautogui.moveTo(975,400) # move mouse to this location
您可以根据需要将它们放入函数中,并根据需要将其映射到按钮。
制作一个将鼠标居中,抓取位置,将其放入变量中以供以后使用。
只是一个想法。