简体   繁体   English

鼠标光标上的中心指针锁定控件

[英]Center pointerlockcontrols on the mouse curosr

The problem问题

As the cursor locks, the cursor is set to the position of the screen where i clicked.当光标锁定时,光标被设置到我点击的屏幕位置。 But i would like to have my cursor centered to the screen.但我想让我的光标以屏幕为中心。 As that is not possible for security reasons, the only available option is to move the camera(maybe with lookAt) towards the cursor position.由于出于安全原因这是不可能的,唯一可用的选项是将相机(可能带有lookAt)移向光标位置。

In my example i would like that when the cursor is locked that the little gray square in the center of the screen provokes a hover.在我的示例中,我希望当光标被锁定时,屏幕中央的灰色小方块会引发悬停。 This meaning that the cursor is exactly in the center of my camera.这意味着光标正好在我的相机的中心。

The reason i want to achieve this is because i would like my clicks to be performed from the center of the screen, if i for instance want to trigger the onclick of a 3D object in front of the camera.我想要实现这一点的原因是因为我希望从屏幕中心执行我的点击,例如,如果我想在相机前触发 3D 对象的点击。

I would like to know if it is possible to do so with the pointerlockcontrols and if yes, how could one proceed ?我想知道是否可以使用指针锁定控件来做到这一点,如果可以,如何进行?

What i have so far到目前为止我所拥有的

At the time i've just tried the basic implementation of pointerlockcontrols but can't figure out the way to put the cursor in the desired position.当时我刚刚尝试了指针锁定控件的基本实现,但无法弄清楚将光标放在所需位置的方法。

Unfortunately pointerlockcontrols does not work on my codesandbox example.不幸的是,pointerlockcontrols 不适用于我的代码和框示例。 The code sandbox that unfortunately does not work 不幸的是,代码沙箱不起作用

Thanks in advance for your help.在此先感谢您的帮助。

Found my answer here : Screen centered pointer lock controls在这里找到我的答案: 屏幕居中指针锁定控件

the trick is just to move the raycast to the center of the screen.诀窍就是将光线投射到屏幕的中心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM