threejs 相机围绕原点旋转

threejs camera rotate around origin

g'day - 我正在尝试做一些看似简单的事情,但它对我不起作用 - 我在原点有一堆物体,我想围绕它们旋转相机,始终指向起源。据我阅读文档可以看出,这应该有效:

camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 10000);
camera.position.z = 500;camera.position.x = 0;camera.position.y = 0;
scene.add(camera);

var spin = Tween.create().time(5000).from( {angle:0}).to({angle:2 * Math.PI})
  .apply( function (v) {
    camera.position.x = 500 * Math.cos(v.angle);
    camera.position.z = 500 * Math.sin(v.angle);
    camera.lookAt(0, 0, 0);
});
spin.chain(spin);
spin.start();

但是原点处的方框很快飞出屏幕,然后偶尔会再次出现 - 所以我显然完全不理解某些东西 - 我会想,因为我在 0,0,0 处有一个方框我正在看 0,0,0,那么就不可能将相机放在我看不到盒子的任何地方?

也许您正在寻找的是 Orbit Control。

在这里你可以找到一个演示:OrbitControl Demo

随着 OrbitControl 的出现,属性 对管理相机围绕 THREE.Vector3(在你的情况下为 0,0,0)

非常有用

编辑:

下面是一个使用轨道控制围绕原点的轨道相机示例:

orbit = new THREE.OrbitControls(camera, renderer.domElement);
orbit.target = new THREE.Vector3(0,0,0); // set the center
orbit.maxPolarAngle =  Math.PI/2; // prevent the camera from going under the ground
orbit.minDistance = 140; // the minimum distance the camera must have from center
orbit.maxDistance = 250; // the maximum distance the camera must have from center
orbit.zoomSpeed = 0.3; // control the zoomIn and zoomOut speed
orbit.rotateSpeed = 0.3; // control the rotate speed