简体   繁体   English

threejs摄像头绕原点旋转

[英]threejs camera rotate around origin

g'day - I'm trying to do something that seems easy, but it's not working for me - I have a bunch of objects at the origin, and I want to rotate a camera around them, always pointing at the origin. g'day-我正在尝试做一些看似简单的事情,但对我却不起作用-我在原点有很多物体,我想围绕它们旋转相机,始终指向原点。 As far as I could tell from reading the documentation, this should work: 据我从阅读文档中得知,这应该有效:

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();

but the boxes at the origin quickly fly off screen, and then come back again occasionally - so I'm obviously completely not understanding something - I'd have thought, given I have a box at 0,0,0 and I'm looking at 0,0,0, then it would be impossible to put the camera anywhere that I can't see the box? 但是原点的盒子很快就飞出了屏幕,然后偶尔又回来了-所以我显然完全不了解某些东西-我本以为,考虑到我有一个0,0,0的盒子,我正在寻找在0,0,0,那么将不可能将相机放置在我看不见盒子的任何地方?

Maybe what you are looking for is the Orbit Control. 也许您正在寻找的是轨道控制。

Here you can find a demo: OrbitControl Demo 在这里您可以找到一个演示: OrbitControl演示

With the OrbitControl comes a bunch of property very useful to manage camera to orbit around a THREE.Vector3 (in your case 0,0,0) 随着OrbitControl的到来,一堆属性对于管理摄像头绕THREE.Vector3(在您的情况下为0,0,0)非常有用

EDIT: 编辑:

Here is an example of orbit camera around the origin using Orbit Control: 这是使用Orbit Control在原点周围的轨道摄像机的示例:

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

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

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