我只是想知道是否有一个BUIT,在功能重头转动。 我见过(魔环,Carboard等)最VR的SDK有一种方法,使当前旋转的默认正转。 有一个简单的方法在一个框架来做到这一点?
Answer 1:
您可以添加一个包装实体相机周围,并在一个事件,设置实体包装的绕Y轴旋转为负相机的绕Y轴旋转。
下面是一个例子使用@jhsu shake.js(但反应):
import React from 'react';
import Camera from './Camera';
import Shake from 'shake.js';
class Player extends Component {
componentDidMount() {
this.shaker = new Shake({
threshold: 5,
timeout: 250,
});
this.shaker.start();
window.addEventListener('shake', this.reorient, false);
}
reorient() {
if (this.camera) {
const rotation = this.camera.getAttribute('rotation');
this.setState({
orientation: { x: 0, y: -1 * rotation.y, z: 0 }
});
}
}
cameraMounted = (camera) => {
this.camera = camera;
}
render() {
return <Camera
rotation={this.state.orientation}
onMount={this.cameraMounted}
/>
}
}
A组份为:
AFRAME.registerComponent('resetorientation', {
init: function () {
var el = this.el;
el.addEventListener('resetorientation', function () {
var y = el.querySelector('[camera]').getAttribute('rotation').y;
el.setAttribute('rotation', {y: -1 * y});
});
}
});
<a-entity id="cameraWrapper" resetorientation><a-camera></a-camera></a-entity>
document.querySelector('#cameraWrapper').emit('resetorientation');
文章来源: Is there a way to recenter / reset orientation?