简体   繁体   English

使用鼠标围绕中心旋转Three.js相机

[英]Rotate Three.js camera around center using mouse

I'm trying to rotate the camera around the center point (0, 0, 0) using the mouse but if I rotate to the right or left 180deg, then the try to rotate up or down, it doesn't rotate vertically at all. 我正在尝试使用鼠标围绕中心点(0、0、0)旋转相机,但是如果我向右或向左旋转180度,则尝试向上或向下旋转时,它根本不会垂直旋转。

I'm trying to use latitude/longitude coordinates then convert it to cartesian like: 我正在尝试使用经度/纬度坐标,然后将其转换为笛卡尔坐标,例如:

this.camera.position.x = Math.sin(this.lat) * this.alt;
this.camera.position.z = Math.cos(this.lat) * Math.cos(this.lng) * this.alt;
this.camera.position.y = Math.cos(this.lat) * Math.sin(this.lng) * this.alt;
this.camera.lookAt(new THREE.Vector3(0, 0, 0));

A minimal example is here: https://jsfiddle.net/qsor9w27/2/ 一个最小的示例在这里: https : //jsfiddle.net/qsor9w27/2/

I think the simplest would be using OrbitControls or TrackballControls 我认为最简单的方法是使用OrbitControlsTrackballControls

See this example which is using OrbitControls. 请参见使用OrbitControls的此示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM