Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Three.js沿样条线定向摄影机_Javascript_Three.js - Fatal编程技术网

Javascript Three.js沿样条线定向摄影机

Javascript Three.js沿样条线定向摄影机,javascript,three.js,Javascript,Three.js,这个问题源于,但不是沿路径定向网格,而是无法定向摄影机 完整的源代码在中,但我已使用这些源代码设置了一个。我认为问题在于函数setCameraOnSplinePath。我使样条曲线显示为紫色线,以使调试更容易 如果这有意义的话,我们的目标是像汽车在网格表面上行驶一样移动相机 如果我只是像复制摄影机位置一样复制摄影机旋转,则摄影机会以看似随机的方向旋转: camera.position.x = camPos.x; camera.position.y = camPos.y; camera.posit

这个问题源于,但不是沿路径定向网格,而是无法定向摄影机

完整的源代码在中,但我已使用这些源代码设置了一个。我认为问题在于函数
setCameraOnSplinePath
。我使样条曲线显示为紫色线,以使调试更容易

如果这有意义的话,我们的目标是像汽车在网格表面上行驶一样移动相机

如果我只是像复制摄影机位置一样复制摄影机旋转,则摄影机会以看似随机的方向旋转:

camera.position.x = camPos.x;
camera.position.y = camPos.y;
camera.position.z = camPos.z;

camera.rotation.x = camRot.x;
camera.rotation.y = camRot.y;
camera.rotation.z = camRot.z;
我现在已将相机固定为沿y轴和z轴固定,并在x轴上稍微倾斜:

if(camera.position.z <= 150) {
    camera.rotation.x = 0.7;
} else if(camera.position.z >= 180) {
    camera.rotation.x = 0;
} else {
    var r = ((180 - camera.position.z) / 30) * 0.7;
    camera.rotation.x = r;
}
camera.rotation.y = 0;
camera.rotation.z = 0;
if(摄像机位置z=180){
摄像机旋转x=0;
}否则{
var r=((180-摄像机位置z)/30)*0.7;
摄像机旋转x=r;
}
相机旋转y=0;
摄像机旋转z=0;
我试过在y轴上旋转几次,但似乎没有任何效果。上述答案的解非常接近,但路径与网格平行,而不是垂直

const targetRotation = mobiusrune.degToRad(80); //0.7;
if(camera.position.z <= 120) {
    camera.lookAt(routeSpline.getPoint((camPosIndex+1) / fragmentSize));
    //camera.rotation.x = targetRotation;
    // camera.rotation.y = 0; //mobiusrune.degToRad(camPosIndex);
    // camera.rotation.z = 0; //mobiusrune.degToRad(-30);
} else if(camera.position.z >= 150) {
    camera.rotation.x = 0;
} else {
    var r = ((150 - camera.position.z) / 30) * targetRotation;
    camera.rotation.x = r;
}
const targetoration=mobiusrune.degToRad(80)//0.7;
if(摄像机位置z=150){
摄像机旋转x=0;
}否则{
变量r=((150-摄像机位置z)/30)*目标位置;
摄像机旋转x=r;
}

也许有帮助。或者。@WestLangley那些看起来不错,谢谢!很有趣的例子,不幸的是,相机代码非常复杂。我添加了替换的
camera.lookAt(routesline.getPoint((camposidex+1)/fragmentSize))使用来自的零件,这确实更加稳定,但我真的不知道从何处开始将相机旋转90度,使其垂直于其行驶的“轨道”。@mdworld嘿,您是否找到过将相机垂直于轨道或路径旋转90度的解决方案?我正在尝试做同样的事情,恐怕不行,我又回到了一个更简单的动画,它不使用跟随路径。