简体   繁体   English

Pivot 摄像头 object 左右拖动

[英]Pivot camera around object on drag

In my three.js scene I have an object with the {x: 0, y:0 z:-150} .在我的 three.js 场景中,我有一个 object 和{x: 0, y:0 z:-150} My camera has a position of {x:0, y:0, z:75);我的相机有一个 position {x:0, y:0, z:75); . . What I want is that the user can drag the camera around the object, so that the user keeps looking at the object.我想要的是用户可以在object周围拖动相机,让用户一直看着object。

在此处输入图像描述

The camera needs to follow the given circle stroke on a drag to the left or to the right.相机需要在向左或向右拖动时跟随给定的圆圈笔划。

I tried to use OrbitControls and a pivotPoint to get this result:我尝试使用OrbitControls和一个pivotPoint来获得这个结果:

const controls = new OrbitControls( camera, renderer.domElement );
controls.update();
         
object.position.set(0, 0, -150);
pivotPoint = new THREE.Object3D();
object.add(pivotPoint);

camera.position.set(0, 0, 75);
camera.lookAt(object.position);

The problem I have now is that the camera rotates around itself and not around the object.我现在遇到的问题是相机绕着自己旋转,而不是绕着 object 旋转。

Try it like so:像这样尝试:

camera.position.set(0, 0, 75);

object.position.set(0, 0, -150);

const controls = new OrbitControls(camera, renderer.domElement);
controls.target.copy(object.position);
controls.update();

The idea of the above code is to make use of the target property of OrbitControls which represents the focus point.上面代码的想法是利用表示焦点的OrbitControls目标属性。 There is no need to manually call lookAt() on the camera object.无需在摄像头object上手动调用lookAt()

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

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