ThreeJS camera.lookAt()有没有效果,是不是我做错了什么? [英] ThreeJS camera.lookAt() has no effect, is there something I'm doing wrong?

查看:5434
本文介绍了ThreeJS camera.lookAt()有没有效果,是不是我做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Three.js,我希望有一个摄像头在3D空间中的点指出。

In Three.js, I want a camera to be pointed at a point in 3D space.

为此,我尝试使用像这样的 camera.lookAt 功能:

For this purpose, I tried using the camera.lookAt function like so:

camera.lookAt(new THREE.Vector3(-100,-100,0));

不过,我发现呼叫有任何作用。它少了点什么都没有。我试图改变号码的载体,而我总是得到相同的外观在屏幕上,当它应该被改变。

However, I found out that the call has no effect whatsoever. It just does nothing at all. I tried changing the numbers in the vector, and I always get the same look on screen, when it should be changing.

我刚刚发现,现在,如果我删除 THREE.TrackballControls 我在code时, camera.lookAt()的作品,因为它应该。是不是有什么毛病我怎么使用THREE.TrackballControls?这是我如何初始化它们:

I just found now that if I remove the THREE.TrackballControls I have in my code, the camera.lookAt() works as it should. Is there something wrong with how I use THREE.TrackballControls? This is how I initialize them:

    controls = new THREE.TrackballControls( camera, renderer.domElement );

    controls.rotateSpeed = 10.0;
    controls.zoomSpeed = 1.2;
    controls.panSpeed = 0.2;

    controls.noZoom = false;
    controls.noPan = false;

    controls.staticMoving = true;
    controls.dynamicDampingFactor = 1.0;

    var radius = 5;
    controls.minDistance = radius * 1.1;
    controls.maxDistance = radius * 100;

    controls.keys = [ 65, 83, 68 ]; // [ rotateKey, zoomKey, panKey ]*/

然后在我的渲染功能,我做的:

And then in my render function I do:

function render() {
  controls.update();
  renderer.render(scene, camera);
}

在Three.js文档是pretty的稀少,所以我想我会在这里问。难道我做错了什么?

Documentation on Three.js is pretty scarce, so I thought I'd ask here. Am I doing something wrong?

推荐答案

看的<一个源$ C ​​$ C href="https://github.com/mrdoob/three.js/blob/master/src/extras/controls/TrackballControls.js"><$c$c>THREE.TrackballControls,我想通了,我可以让相机的外观,我想通过设置 trackballControls.target THREE.Vector3 我想要看看,然后再重新描绘的场景。

Looking at the source code of THREE.TrackballControls, I figured out that I can make the camera look where I want by setting trackballControls.target to the THREE.Vector3 I want it to look at, and then rerendering the scene.

这篇关于ThreeJS camera.lookAt()有没有效果,是不是我做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆