gpt4 book ai didi

javascript - 无限移动鼠标

转载 作者:可可西里 更新时间:2023-11-01 12:48:03 24 4
gpt4 key购买 nike

我正在尝试用 Babylon 做一个游戏,但相机有点问题。

基本上,我希望(就像在所有 FPS 中一样)相机在鼠标到达页面边缘时无限移动而不是停止。我试过这样的事情:

window.mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
window.mouse.y = -( event.clientY / window.innerHeight ) * 2 + 1;
if(mouse.x>0 || mouse.x<0){
scene.cameras[0].rotation = scene.cameras[0].rotation.add( new BABYLON.Vector3(0,(mouse.x)/100,0));
window.mouse.x = 0;
}
else if(mouse.y>0 || mouse.y<0){
scene.cameras[0].rotation = scene.cameras[0].rotation.add( new BABYLON.Vector3(0,(mouse.y)/100,0));
window.mouse.y = 0;
}

但是效果不是很好。因为光标还在左边或右边。

我的问题是:

是否可以将光标固定在页面的中心,只获取鼠标移动,我只需要关心这个移动?

最佳答案

你不能移动我的光标(想象一下它会让互联网变得多么烦人:))但是对于游戏你应该能够利用全屏模式。请注意,它在此阶段(仍)处于试验阶段。

Pointer lock (formerly called mouse lock) provides input methods based on the movement of the mouse over time (i.e., deltas), not just the absolute position of the mouse cursor. It gives you access to raw mouse movement, locks the target of mouse events to a single element, eliminates limits on how far mouse movement can go in a single direction, and removes the cursor from view.

This API is useful for applications that require significant mouse input to control movements, rotate objects, and change entries. It is particularly essential for highly visual applications, such as those that use first-person perspective, as well as 3D views and modeling.

关于javascript - 无限移动鼠标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23871424/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com