2
中將某些元素固定在屏幕上我想在react-vr應用程序中始終顯示分數或健康狀況欄。如何在反應-Vr
我可以使用VrHeadModel - 旋轉,yawPitchRoll和位置,但不得不計算它只是爲了保持它的固定...似乎我失去了一些東西。
我該怎麼做?
中將某些元素固定在屏幕上我想在react-vr應用程序中始終顯示分數或健康狀況欄。如何在反應-Vr
我可以使用VrHeadModel - 旋轉,yawPitchRoll和位置,但不得不計算它只是爲了保持它的固定...似乎我失去了一些東西。
我該怎麼做?
更新要點有哪些,因爲它是訂閱的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>
);
}
周圍有從陣營VR隊這邊這個問題相關的職位: https://github.com/facebook/react-vr/issues/261
感謝,它工作得很好,當用戶查找非常高,或者在地面除 - 然後我得分(在屏幕的頂部)在屏幕上方偏移 –
,當我嘗試調整旋轉X到高或低時的效果,除了向後看時,屏幕上的分數全部移動 –
太棒了,很高興它解決了。 – cidicles