three.js OrbitControls. How update rotation camera?
我使用OrbitControls,设置为
相机旋转,没关系。
如何更新相机的旋转度?
OrbitControls控制您的相机。
您不能独立于OrbitControls旋转相机。
我所做的是修改OrbitControls.js本身,以公开一个称为" rotateLeft"的内部方法,以便可以从我的代码中调用它。
将此添加到OrbitControls:
1 2 3 4 | this.rotate = function(degrees) { rotateLeft(degrees); this.update(); } |
,然后您可以手动执行
如果要基于旋转来设置摄像机的位置,则可以旋转摄像机,从摄像机获取前向矢量,并将其相对于目标位置进行定位。这是一个粗略的示例:
1 2 3 4 5 6 7 8 9 10 11 12 | // ... 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(); |
希望有帮助!