旋转相机以查看three.js中的选定对象 [英] Rotate camera to look at Selected object in three.js

查看:41
本文介绍了旋转相机以查看three.js中的选定对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设计地图.因此,当我选择任何几何体时,我希望对象位于视口的中心并且相机正在注视它.我花了很多时间在网上到处找,但没有找到答案.请注意,我不想旋转对象.我只想更新相机.我试图在这个例子中得到类似的东西,当我们点击数字时,它会来到中心: 解决方案

如果您在项目中使用 Orbit 或 Trackball 控件,则仅通过更改相机的外观是行不通的.您还需要更改控件的目标.要进行实验,只需尝试禁用控件,然后更改相机的外观即可.

I am trying to design a map. So, when I select any geometry, I want the object to come at the centre of the viewport and the camera to be looking at it. I have spent quite a lot of time looking everywhere on the web but failed to find the answer. Please note that I don't want to rotate the object. I just want to update the camera. I am trying to get something like in this example where when we click the number, it comes to the centre : https://sketchfab.com/3d-models/jurassic-aquarium-diorama-with-annotations-d82bea156a1c4176b5d09b82b176e84c

Here is what I have tried and has been closest to giving me any output:

       `camera.position.x = select.position.x;
        camera.position.y = select.position.y;
        camera.position.z = select.position.z;
        camera.Translate(0,0,-1);
        camera.updateProjectionMatrix ();`

select has the selected object. Although the above code does rotate the camera but it fails to look at the selected object.

I have also tried lookAT(select.position) and that didn't work either.

Please help me with this.

解决方案

If you are using Orbit or Trackball controls in your project it won't work by just changing lookAt of the camera. You need to change the target of the controls as well. To experiment, just try to disable the controls and then change look at for Camera.

这篇关于旋转相机以查看three.js中的选定对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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