Load PointerLockControl camera view to another camera

萝らか妹 提交于 2019-12-25 04:27:31

问题


I'm using the PointerLockControls to control my camera but how would I be able to load the rotation of the current view to another camera that is not attached to anything but the scene? I can get the yawObject position but the yawObject rotation does not show the exact view I had with the PointerLockControl camera. For example, if I output the following: yawObject position: 183.91,10.00,-204.16 yawObject rotation: 0.00,73.89,0.00 pitchObject position: 0.00,20.00,0.00 pitchObject rotation: -0.10,0.00,0.00

If I try to set the 2nd camera that does not have any controls with the following: camera2.position.set(183.91,10.00,-204.16); camera2.rotation.set(0.00,73.89,0.00);

The resulting camera2 view is not the same.


回答1:


If you want to create a second camera that has the same view direction as the camera controled by PointerLockControls, the key is to look at the method PointerLockControls.getDirection(), which returns a direction vector.

If you want to be able to set the 2nd camera's rotation directly, you do this:

camera2.rotation.order = 'YXZ'; // important!

. . .

camera2.rotation.set( pitchObject.rotation.x, yawObject.rotation.y, 0 );

where

yawObject = controls.getObject();

pitchObject = yawObject.children[ 0 ];

three.js r.67



来源:https://stackoverflow.com/questions/23788325/load-pointerlockcontrol-camera-view-to-another-camera

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!