0

シーン内のすべてのカメラにアタッチし、ユーザーがこのカメラで入力できる各チェックポイントのアクションを登録する次のコンポーネントがあります。現在、カメラの開始点に対するカメラの位置を確認することで機能しますが、そのカメラのワールド位置を取得し、これがアクティブなカメラであることを確認するにはどうすればよいですか? 非アクティブなカメラは、一部の物理現象が位置を変更したときにイベントを放出し続けるようです。

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? の 他のスレッドから質問に対する回答を得ました。

4

1 に答える 1

0

次のようにして、カメラがアクティブかどうかを確認できます。

el.getAttribute('camera').active === true

于 2016-08-15T17:26:15.327 に答える