6
如何获取相机的当前位置?这样我可以旋转我的天空实体。如何在A帧中聆听相机的世界位置?
假设我有:
<a-scene>
<a-camera id="camera></a-camera>
<a-sky id="mySky"></a-sky>
</a-scene>
如何获取相机的当前位置?这样我可以旋转我的天空实体。如何在A帧中聆听相机的世界位置?
假设我有:
<a-scene>
<a-camera id="camera></a-camera>
<a-sky id="mySky"></a-sky>
</a-scene>
让相机的位置:
var pos = document.querySelector('#camera').getAttribute('position');
让相机的世界上的地位,我们可以将相机的局部位置:
var cameraEl = document.querySelector('#camera');
var worldPos = new THREE.Vector3();
worldPos.setFromMatrixPosition(cameraEl.object3D.matrixWorld);
console.log(worldPos.x);
要聆听更改,请使用componentchanged
活动:
cameraEl.addEventListener('componentchanged', function (evt) {
if (evt.detail.name !== 'position') { return; }
console.log(evt.detail.newData);
});
更好的性能,可能是轮询:
AFRAME.registerComponent('camera-listener', {
tick: function() {
var cameraEl = this.el.sceneEl.camera.el;
cameraEl.getAttribute('position');
cameraEl.getAttribute('rotation');
// Do something.
}
});
超级有用的感谢。希望A帧将所有列表作为文档的一部分 – benbyford
https://aframe.io/docs/0.4.0/core/entity.html#events – ngokevin
@ngokevin是可以检索的视频球的当前位置吗? –