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

查看:26
本文介绍了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.TrackballControlscamera.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 的文档非常稀缺,所以我想我会在这里问.我做错了什么吗?

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

推荐答案

THREE.TrackballControls,我发现我可以通过将 trackballControls.target 设置为 trackballControls.target 来让相机看起来我想要的地方code>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天全站免登陆