以编程方式更改 webvr 相机视图
Programmatically change webvr camera view
我想以编程方式移动视图在 webvr 场景中的位置。为此,我使用 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));
这在正常模式下有效,但在纸板模式下,相机不动。如何以编程方式在纸板视图模式下移动相机?
据我所知,一旦你切换到 "VR mode",你就可以使用 "VR mode" 之外的其他相机。
我认为您应该监听 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 在他的 中经常推荐视觉指示 WHERE to look,而不是这些选项。
如果上述方法不起作用,请尝试抓取相机实体,如果它的 object3D:
var obj3d = document.querySelector("#camera");
并使用 setAttribute() 方法移动它
obj3d.setAttribute("position", {x: _x, y: _y, z: _z});
我想以编程方式移动视图在 webvr 场景中的位置。为此,我使用 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));
这在正常模式下有效,但在纸板模式下,相机不动。如何以编程方式在纸板视图模式下移动相机?
据我所知,一旦你切换到 "VR mode",你就可以使用 "VR mode" 之外的其他相机。
我认为您应该监听 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 在他的
如果上述方法不起作用,请尝试抓取相机实体,如果它的 object3D:
var obj3d = document.querySelector("#camera");
并使用 setAttribute() 方法移动它
obj3d.setAttribute("position", {x: _x, y: _y, z: _z});