我怎样才能听到相机世界的位置?

时间:2016-08-15 02:51:11

标签: aframe

我有以下组件,我附加到场景中的所有摄像机,并为每个检查点注册操作,用户可以使用此摄像机输入。现在它的工作原理是检查相机相对于相机起点的位置,但是如何才能获得相机的世界位置并确保这是有源相机?因为似乎不活动的摄像机在某些物理改变它们的位置时会发射事件。

AFRAME.registerComponent('user-checkpoints', {
  init: function () {
    var self = this;
    this.el.addEventListener('componentchanged', isOnCheckPoint);
    // Is user in checkpoint
    function isOnCheckPoint (evt) {
      // We don't want such precision what event emits
      if (evt.detail.name !== 'position' || (
        (evt.detail.oldData.x).toFixed(1) === (evt.detail.newData.x).toFixed(1) && 
        (evt.detail.oldData.y).toFixed(1) === (evt.detail.newData.y).toFixed(1) && 
        (evt.detail.oldData.z).toFixed(1) === (evt.detail.newData.z).toFixed(1))
    ) { return; }

    // Position has changed enough to check it
    self.LookForCheckPoint(evt.detail.newData.x, evt.detail.newData.y, evt.detail.newData.z);
    }
  },
  LookForCheckPoint: function (x, y, z) {
    // All the chekpoints are checked here
    console.log('x:' + x + ' y:' + y + ' z:' + z);
  }
});

修改 我从How to listen to camera's world position in A-Frame?

的其他帖子得到了我的问题的答案

0 个答案:

没有答案