将 PointerLockControl 相机视图加载到另一个相机 [英] Load PointerLockControl camera view to another camera
问题描述
我正在使用 PointerLockControls 来控制我的相机,但是我如何能够将当前视图的旋转加载到另一个除了场景之外没有附加任何东西的相机?我可以获得 yawObject 位置,但 yawObject 旋转没有显示我使用 PointerLockControl 相机的确切视图.例如,如果我输出以下内容:yawObject 位置:183.91,10.00,-204.16yawObject 旋转:0.00,73.89,0.00音高物体位置:0.00,20.00,0.00pitchObject 旋转:-0.10,0.00,0.00
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
如果我尝试使用以下内容设置没有任何控件的第二台相机:camera2.position.set(183.91,10.00,-204.16);camera2.rotation.set(0.00,73.89,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);
生成的 camera2 视图不一样.
The resulting camera2 view is not the same.
推荐答案
如果你想创建第二个与 PointerLockControls
控制的相机具有相同视角方向的相机,关键是看在方法 PointerLockControls.getDirection()
处,它返回一个方向向量.
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 );
哪里
yawObject = controls.getObject();
pitchObject = yawObject.children[ 0 ];
three.js r.67
three.js r.67
这篇关于将 PointerLockControl 相机视图加载到另一个相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!