我正在用a-frame搜索运动检测。我想要实现的是检测是否有人在VR模式下移动头部。我可以检查的实体是否有任何财产?或者相机组件本身是否有任何位置/旋转/可用于检测的任何属性?
答案 0 :(得分:3)
https://aframe.io/docs/0.3.0/core/entity.html#listening-for-component-changes
AFRAME.registerComponent('do-something-on-head-movement', {
init: function () {
var scene = this.el;
var camera = scene.cameraEl;
camera.addEventListener('componentchanged', function (evt) {
if (evt.detail.name === 'rotation' || evt.detail.name === 'position') {
// Do something.
}
});
}
});
<a-scene do-something-on-head-movement>
答案 1 :(得分:1)
我使用此功能来检测耳机何时被放下(面朝下)到&#34;暂停&#34;应用程序
function process(event) {
var gamma = event.gamma;
if((gamma < -10)||(gamma>5)){
playApp();
}else{
pauseApp();
}
}
http://w3c.github.io/deviceorientation/spec-source-orientation.html