更新了 gist,因为它订阅了 HM,所以延迟更少:
https://gist.github.com/cidicles/b4e978d3f3e2de8b359bdc51b5fb3261
这就是我目前的做法。它具有视觉滞后并在循环中设置状态但达到了目标。
为 VrheadModel.rotation() 数组创建一个状态
constructor(props) {
super(props);
this.state = {
hmRot: VrHeadModel.rotation()
}
}
启动计时器
componentDidMount(){
this.timer = setInterval(()=>{this.tick()}, 50);
}
componentWillUnmount(){
clearInterval(this.timer);
}
tick(){
this.setState({
hmRot: VrHeadModel.rotation()
});
}
在 0/0/0 创建一个视图,并将您的固定对象放置在场景中,就像您通常的世界一样。在主视图上设置旋转以匹配相机的旋转。
render(){
let {hmRot} = this.state;
return (
<View
style={{
position: 'absolute',
layoutOrigin: [0.5, 0.5],
transform: [
{translate: [0, 0, 0]},
{rotateX: hmRot[0]},
{rotateY: hmRot[1]},
{rotateZ: hmRot[2]}
]
}}>
<Text
style={{
position: 'absolute',
layoutOrigin: [0.5, 0.5],
backgroundColor: '#f00',
transform: [
{translate: [0, 0, -2]},
]
}}>
Fixed
</Text>
</View>
);
}
这里有 React VR 团队围绕此问题发布的相关帖子:
https://github.com/facebook/react-vr/issues/261