gpt4 book ai didi

javascript - 以编程方式更改 webvr 摄像头 View

转载 作者:行者123 更新时间:2023-12-03 02:52:53 27 4
gpt4 key购买 nike

我想以编程方式移动 webvr 场景中 View 的位置。为此,我使用了position.add 方法。

以下是我如何以编程方式移动相机:

 <a-entity position="33 0 -33" rotation="0 180 0" look-controls id="camera" 
camera="userHeight: 1.6" listener></a-entity>

摄像机移至此处:

 var obj3d = document.querySelector("#camera").object3D;
var angleobj = obj3d.getWorldDirection();
angleobj.y = 0;
obj3d.position.add(angleobj.multiplyScalar(0.004*3));

这在正常模式下有效,但在纸板模式下,相机不会移动。如何以编程方式在纸板 View 模式下移动相机?

最佳答案

据我所知,一旦切换到“VR模式”,您就可以使用“VR模式”之外的其他相机。

我认为你应该监听 VR 进入/退出事件,并更改相机引用:

this.el.sceneEl.addEventListener('enter-vr',() => {
obj3d = document.querySelector("#camera").object3D;
}
this.el.sceneEl.addEventListener('exit-vr',() => {
obj3d = document.querySelector("#camera").object3D;
}

<小时/>请重新考虑一下,如果这是必要的,当用户移动头部时,相机会变得疯狂,它会变得非常快,非常头晕。

A-frame 的迭戈·马科斯 (Diego Marcos) 在他的 anwsers 中通常建议视觉指示去哪里看,而不是这样的选项。

<小时/>

如果上述方法不起作用,请尝试抓取相机实体,而不是它的 object3D:

var obj3d = document.querySelector("#camera");

并使用 setAttribute() 方法移动它

obj3d.setAttribute("position", {x: _x, y: _y, z: _z});

关于javascript - 以编程方式更改 webvr 摄像头 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47761920/

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