2015-12-09 109 views
1

g'day - 我试图做一些看起来很简单的事情,但它不适用于我 - 我在原点有一堆物体,我想旋转它们周围的相机,始终指向原点。就从阅读文档,我看得出来,这应该工作:threejs相机围绕原点旋转

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,那么将相机放在任何我看不到盒子的地方都是不可能的?

+0

什么是“起源”?创建一个jsfiddle来帮助我们来帮助你。 – 2pha

+0

你能确认相机不在盒子里吗?尽量减少盒子的尺寸,或增加相机的距离。 –

回答

0

也许你正在寻找的是轨道控制。

在这里你可以找到一个演示: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