如何切换三/ JS相机控制从第一人称到轨道和回 [英] How to switch Three/js camera controls from First Person to Orbit and back
问题描述
您可以从Three.js轨道控制切换到第一人称控制没有问题。但是,当你从第一人到轨道上的显示卡在一个鼠标按下模式。
You can switch from Three.js Orbit Controls to FirstPerson controls without a problem. But when you go from First Person to Orbit the display gets stuck in a 'mousedown' mode.
你有什么需要做的,来回走第一人称和轨道控制之间无缝?
What do you need to do to go back and forth between First Person and Orbit controls seamlessly?
与演示的jsBin
http://jsbin.com/jekebo/2/edit?html, JS,输出
这两个函数
function setControlsFirstPerson() {
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.set( -150, 20, 0 );
controls = new THREE.FirstPersonControls( camera, renderer.domElement );
controls.lookSpeed = 0.05;
controls.movementSpeed = 50;
}
function setControlsOrbit() {
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.set( 100, 100, 100 );
controls = new THREE.OrbitControls( camera, renderer.domElement );
}
任何帮助AP preciated。
Any help appreciated.
推荐答案
这是行不通的,因为你要发送的第二个参数OrbitControls。这出于某种原因似乎停止end事件被解雇。
It is not working because you are sending the second parameter to the OrbitControls. This for some reason seems to stop the end event being fired.
controls = new THREE.OrbitControls( camera, renderer.domElement );
如果没有了它,它似乎工作按预期的方式:
Without out it it seems to work as expected:
controls = new THREE.OrbitControls( camera );
我已经提前和编辑您的jsbin改变发送到两个控件的构造函数的参数。
I have gone ahead and edited your jsbin changing the parameters sent to the constructors of both controls.
http://jsbin.com/fabalomave/1/edit?js,output
我也改变了相机的创建和更改,这样一个新的相机和控制实例没有所需的摄像头改变时创建的,而是只存储一个参考,并改变它的摄像头和控制,全球相机
和控件
变量表示。
I also changed how the cameras are created and changed so that a new camera and control instance is not created each time the desired camera is changed, instead it just stores a reference and changes which camera and control that the global camera
and controls
variables refer to.
这篇关于如何切换三/ JS相机控制从第一人称到轨道和回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!