Javascript 更换Pano时,反应VR设置摄像头位置
我是react vr的新手,想制作一款旅游应用程序。在那里我更新了Javascript 更换Pano时,反应VR设置摄像头位置,javascript,three.js,react-360,Javascript,Three.js,React 360,我是react vr的新手,想制作一款旅游应用程序。在那里我更新了Pano图片。当我设置新图片时,相机/场景与加载新图片之前的位置相同 以下是代码的一部分: render() { if (!this.state.data) { return null; } const locationId = this.state.locationId; const isLoading = this.state.nextLocationId !== this.state.locationId; ret
Pano
图片。当我设置新图片时,相机/场景与加载新图片之前的位置相同
以下是代码的一部分:
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>
);}
render(){
如果(!this.state.data){
返回null;
}
const locationId=this.state.locationId;
const isLoading=this.state.nextLocationId!==this.state.locationId;
返回(
{
这是我的国家({
locationId:this.state.nextLocationId
});
}}
source={asset(this.state.data.photos360[this.state.nextLocationId].uri)}
/>
{tooltips&&tooltips.map((工具提示,索引)=>{
返回(
{
这是我的国家({
nextLocationId:tooltip.linkedPhoto360Id});
}}
source={asset(this.state.data.nav_图标)}
textLabel={tooltip.text}
rotateY={(tooltip.rotationY&&tooltip.rotationY)| | 0}
rotateX={(tooltip.rotationX&&tooltip.rotationX)| | 0}
translateZ={(tooltip.translateZ&&tooltip.translateZ)| | this.translateZ}
/>
);
})}
);}
现在我想设置相机位置或变换图片,以便从图片上的某个位置开始
我没有发现在react vr中获取实际摄像机位置或设置摄像机位置的可能性
最好的方法是什么?感谢您的帮助我找到了解决方案,如果其他人有类似问题,我想在这里发布
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")}
/>
);
}
render(){
//如果“全景”源发生更改,则会进行渲染
//它通过VrHeadModel获取x轴和y轴上的位置,单位为°
const rotationY=VrHeadModel.yawPitchRoll()[1]+offestY;
const rotationX=VrHeadModel.yawPitchRoll()[0]+offsetX;
返回(
);
}
并从react vr导入VrHeadModel
。因此,如果全景图发生变化,新图片将旋转到相机的实际位置。每次加载新图片时,相机都被设置为全景的同一部分。我找到了解决方案,如果其他人有类似问题,我想将其发布到这里
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")}
/>
);
}
render(){
//如果“全景”源发生更改,则会进行渲染
//它通过VrHeadModel获取x轴和y轴上的位置,单位为°
const rotationY=VrHeadModel.yawPitchRoll()[1]+offestY;
const rotationX=VrHeadModel.yawPitchRoll()[0]+offsetX;
返回(
);
}
并从react vr导入VrHeadModel
。因此,如果全景图发生变化,新图片将旋转到相机的实际位置。每次加载新图片时,相机都会被设置为与全景相同的位置。听起来您只是想旋转全景,以便在加载时它可以看到特定的方向。如果是这样的话,你可以使用全景的“样式”属性设置旋转。我已经尝试旋转全景,但是我需要知道相机的实际旋转。因为如果用户旋转180°,而我更换了全景,相机的旋转仍然是180°。所以我必须得到摄像机的旋转角度,把全景的旋转角度设置为这个值。但是我不知道如何获得旋转。明白了-你正在寻找VRHeadModel:哦,是的,谢谢,这就是我正在寻找的API:)听起来你只是想旋转你的全景,这样它在加载时会朝某个方向看。如果是这样的话,你可以使用全景的“样式”属性设置旋转。我已经尝试旋转全景,但是我需要知道相机的实际旋转。因为如果用户旋转180°,而我更换了全景,相机的旋转仍然是180°。所以我必须得到摄像机的旋转角度,把全景的旋转角度设置为这个值。但我不知道如何获得旋转。明白了-你正在寻找VRHeadModel:哦,是的,谢谢,这就是我要找的API:)