相机位置在three.js中的THREE.OrbitControls中改变 [英] Camera position changes in `THREE.OrbitControls` in three.js

查看:611
本文介绍了相机位置在three.js中的THREE.OrbitControls中改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

THREE.OrbitControls 在加载了初始摄像头位置后,但通过单击按钮更改了摄像头位置和摄像头旋转时,工作正常.摄像头的位置发生了变化,但是在单击画布以在新视图上旋转摄像头时,摄像头的位置突然发生了变化

The THREE.OrbitControls working fine when loaded with the initial camera position, but when the camera position and camera rotation is changed using a button click. the position of camera changes but on clicking the canvas to rotate the camera on new view the position of camera suddenly changes

相机:

 Camera = new THREE.PerspectiveCamera(45, Width / Height, 0.1, 1000);
 Camera.position.set(170, 120, 400); //intial cam position
 Scene.add(Camera); 


Camera.position.set(30, 167, 81);
Camera.rotation.set(-0.149, 0.3, 0.045); //final cam position

轨道控制:

controlz = new THREE.OrbitControls(Camera, Renderer.domElement);

小提琴

推荐答案

如果使用 THREE.OrbitControls ,并且想要更改摄影机目标或位置,则应执行以下操作:

If you use THREE.OrbitControls and you want to change the camera target or position you should do like this:

camera.position.set(-0.041, 1.9, -1.21);
controls.update();

演示

Demo

controls.target.set(30, 167, 81);
controls.update();

演示

Demo

要将相机重置为初始位置,您可以执行以下操作:

To reset the camera to the initial position you can do:

controls.reset();

这篇关于相机位置在three.js中的THREE.OrbitControls中改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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