我用OrbitControls,设置camera.rotation.y = Math.PI/2
ORcontrols.object.rotation.y = Math.PI/2
相机旋转,就可以了。
后controls.update()
。相机返回到原来的位置。鼠标移动时也会发生同样的情况。
如何更新相机的旋转?
OrbitControls
使“查看”位置target
,因此仅旋转相机不会影响控件。然而,移动相机就会。
如果要根据旋转设置相机的位置,可以旋转相机,从相机获取前向矢量,并将其相对于目标位置定位。这是一个粗略的例子:
// ... rotate the camera and update the camera's matrices
// get the forward vector
const fwd = new THREE.Vector3(0,0,1);
fwd.applyMatrix3(cam.matrixWorld).normalize();
// ... generate an offset vector by multiplying the forward vector
// by a desired distance from the target
cam.position.set(controls.target).sub(offset);
controls.update();
Run Code Online (Sandbox Code Playgroud)
希望有帮助!