this.cameraControl = new CameraControl(renderer, camera, () => {
// you might want to rerender on camera update if you are not rerendering all the time
window.requestAnimationFrame(() => renderer.render(scene, camera))
})
控制:
移动 [holding mouse left / single finger on trackpad] 移动相机在x / y平面
move [mouse wheel / two fingers on trackpad] 在z方向上/下移动
hold shift + [mouse wheel / two fingers on trackpad] 通过增加/减少视野来放大/缩小
移动 holding [mouse right / two fingers on trackpad] 旋转相机(四元数)
5 回答
看看下面的例子
http://threejs.org/examples/#misc_controls_orbit
http://threejs.org/examples/#misc_controls_trackball
还有其他不同鼠标控件的例子,但这两个都允许相机围绕一个点旋转并使用鼠标滚轮进行放大和缩小,主要区别在于OrbitControls强制执行摄像机向上方向,而TrackballControls允许摄像机向上旋转-下 .
您所要做的就是在html文档中包含控件
并在您的来源中包含此行
OrbitControls和TrackballControls似乎很适合这个目的 .
在渲染中更新
这可能是移动/ rotating /用鼠标/触控板缩放相机的好起点(在打字稿中):
把它放进去:
控制:
移动 [holding mouse left / single finger on trackpad] 移动相机在x / y平面
move [mouse wheel / two fingers on trackpad] 在z方向上/下移动
hold shift + [mouse wheel / two fingers on trackpad] 通过增加/减少视野来放大/缩小
移动 holding [mouse right / two fingers on trackpad] 旋转相机(四元数)
另外:
如果你想通过改变'距离'(沿着yz)而不是改变视野,你可以提高/减小相机的位置y和z,同时保持位置y和z的比例不变,如:
Here's a project with a rotating camera . 从源头看,似乎只是将相机位置移动了一圈 .
Here's another demo并且在这一个中我认为它只是以相机作为参数创建一个新的
THREE.TrackballControls
对象,这可能是更好的方法 .看看THREE.PointerLockControls