简体   繁体   English

如何使用WebVR和A-Frame跟踪控制器运动事件?

[英]How can I track controller movement events with WebVR and A-Frame?

I have a WebVR page made with A-Frame, using an Oculus Rift with touch controllers. 我有一个使用A-Frame制作的WebVR页面,使用带有触摸控制器的Oculus Rift。 I have these elements for the controllers: 我为控制器提供了以下元素:

<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>

I want to select or grip an object and move it as a controller moves. 我想选择或抓取一个对象,然后随着控制器的移动来移动它。 But I haven't been able to find an event for controller movement. 但是我还没有找到控制器运动的事件。 Mousemove doesn't seem to be available, even though mouseup and mousedown are. 即使mouseupmousedown可用, Mousemove似乎也不可用。

Use the tick method. 使用tick方法。 If you want to track an entity position or rotation do: 如果要跟踪实体位置或旋转,请执行以下操作:

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

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

See a demo where the red ball tracks the x position of the camera (moved with wasd keys). 观看演示 ,其中红球跟踪摄像机的x位置(使用wasd键移动)。 You can do something similar using an appropriate selector for the controller entity you want to track. 您可以为要跟踪的控制器实体使用适当的选择器来执行类似的操作。 eg: document.querySelector('[laser-controls]'); 例如: document.querySelector('[laser-controls]');

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

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