替换 Pano 时 React-VR 设置相机位置
React-VR set camera position when replacing Pano
我是 react-vr 的新手,想制作一个旅游应用程序。在那里我更新了 Pano
图片。当我设置一张新图片时,camera/scene 与加载新图片之前的位置相同。
这是部分代码:
render() {
if (!this.state.data) {
return null;
}
const locationId = this.state.locationId;
const isLoading = this.state.nextLocationId !== this.state.locationId;
return (
<View>
<Pano
style={{
position: 'absolute'
}}
onLoad={() => {
this.setState({
locationId: this.state.nextLocationId
});
}}
source={asset(this.state.data.photos360[this.state.nextLocationId].uri)}
/>
{tooltips && tooltips.map((tooltip, index) => {
return(
<NavButton
key={index}
isLoading={isLoading}
onInput={() => {
this.setState({
nextLocationId: tooltip.linkedPhoto360Id});
}}
source={asset(this.state.data.nav_icon)}
textLabel={tooltip.text}
rotateY={(tooltip.rotationY && tooltip.rotationY) || 0}
rotateX={(tooltip.rotationX && tooltip.rotationX) || 0}
translateZ={(tooltip.translateZ && tooltip.translateZ) || this.translateZ}
/>
);
})}
</View>
);}
现在我想设置相机位置或变换图片,以便从图片上的某个位置开始。
我发现无法在 react-vr 中获取实际相机位置或设置相机位置。
最好的方法是什么?
感谢帮助
我找到了解决方案,如果其他人遇到类似问题,我想post在这里解决。
render() {
//if the pano source changes it renders
//it gets the position in x and y axis in ° via the VrHeadModel
const rotationY=VrHeadModel.yawPitchRoll()[1]+offestY;
const rotationX=VrHeadModel.yawPitchRoll()[0]+offsetX;
return (
<Pano
style={{
position: 'absolute',
transform:[
{rotateY: rotationY},
{rotateX: rotationX},
]
}}
source={asset("photo.png")}
/>
);
}
并从 react-vr.
导入 VrHeadModel
因此,如果全景图发生变化,新图片将旋转到相机的实际位置。每次加载新图片时,相机都设置在全景的同一部分。
我是 react-vr 的新手,想制作一个旅游应用程序。在那里我更新了 Pano
图片。当我设置一张新图片时,camera/scene 与加载新图片之前的位置相同。
这是部分代码:
render() {
if (!this.state.data) {
return null;
}
const locationId = this.state.locationId;
const isLoading = this.state.nextLocationId !== this.state.locationId;
return (
<View>
<Pano
style={{
position: 'absolute'
}}
onLoad={() => {
this.setState({
locationId: this.state.nextLocationId
});
}}
source={asset(this.state.data.photos360[this.state.nextLocationId].uri)}
/>
{tooltips && tooltips.map((tooltip, index) => {
return(
<NavButton
key={index}
isLoading={isLoading}
onInput={() => {
this.setState({
nextLocationId: tooltip.linkedPhoto360Id});
}}
source={asset(this.state.data.nav_icon)}
textLabel={tooltip.text}
rotateY={(tooltip.rotationY && tooltip.rotationY) || 0}
rotateX={(tooltip.rotationX && tooltip.rotationX) || 0}
translateZ={(tooltip.translateZ && tooltip.translateZ) || this.translateZ}
/>
);
})}
</View>
);}
现在我想设置相机位置或变换图片,以便从图片上的某个位置开始。
我发现无法在 react-vr 中获取实际相机位置或设置相机位置。
最好的方法是什么?
感谢帮助
我找到了解决方案,如果其他人遇到类似问题,我想post在这里解决。
render() {
//if the pano source changes it renders
//it gets the position in x and y axis in ° via the VrHeadModel
const rotationY=VrHeadModel.yawPitchRoll()[1]+offestY;
const rotationX=VrHeadModel.yawPitchRoll()[0]+offsetX;
return (
<Pano
style={{
position: 'absolute',
transform:[
{rotateY: rotationY},
{rotateX: rotationX},
]
}}
source={asset("photo.png")}
/>
);
}
并从 react-vr.
导入 VrHeadModel
因此,如果全景图发生变化,新图片将旋转到相机的实际位置。每次加载新图片时,相机都设置在全景的同一部分。