Reputation: 168
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.
Upvotes: 0
Views: 409
Reputation: 104783
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
Upvotes: 1