gpt4 book ai didi

javascript - 如何使用 WebVR 和 A-Frame 跟踪 Controller 移动事件?

转载 作者:行者123 更新时间:2023-11-30 14:13:37 25 4
gpt4 key购买 nike

我有一个使用 A-Frame 制作的 WebVR 页面,使用带有触摸 Controller 的 Oculus Rift。我有这些 Controller 元素:

<a-entity oculus-touch-controls="hand: right" right-control-listener></a-entity>
<a-entity oculus-touch-controls="hand: left" left-control-listener></a-entity>
<a-entity laser-controls="hand: right" raycaster="objects: .clickable"></a-entity>

我想选择或抓取一个对象并随着 Controller 的移动而移动它。但我一直没能找到 Controller 移动的事件。 Mousemove 似乎不可用,尽管 mouseupmousedown 可用。

最佳答案

使用tick 方法。如果您想跟踪实体位置或旋转,请执行以下操作:

AFRAME.registerComponent('track', {
init: function () {
this.trackedEl = document.querySelector('#trackedEntity');
},

tick: function () {
this.el.object3D.position.x = this.trackedEl.object3D.position.x;
}
});

查看 demo红色球跟踪相机的 x 位置(使用 wasd 键移动)。您可以为要跟踪的 Controller 实体使用适当的选择器来执行类似的操作。例如:document.querySelector('[laser-controls]');

关于javascript - 如何使用 WebVR 和 A-Frame 跟踪 Controller 移动事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53948178/

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