How to set camera rotation ?
ericn0ra opened this issue · comments
Hello,
I would like to be able to manipulate the rotation of the camera (from my own scenes).
I first started by completing the onKeyDown
function in Viewer.js
, adding a key to reset the camera rotation to (0,0,0,1):
case 'KeyR':
if (this.camera)
{
this.camera.quaternion.set(0, 0, 0, 1);
}
break;
But it doesn't work (I modified the code to display the rotation on InfoPanel, but the rotation coordinates do not change at all).
I don’t know how to proceed, as I am not very familiar with Three.js.
Is there a way for the user to access to these coordinates ?
Thank you in advance.
Setting the camera's orientation can be tricky because the camera is controlled by an instance of OrbitControls
. You can't just directly modify the camera's quaternion
property because that will get overwritten by the controls. What you can do is change the camera's lookAt
on the camera and in the controls:
this.camera.lookAt(newTarget);
this.controls.target.copy(newTarget);
Where newTarget
is a three.js Vector3
representing the 3D point you want the camera to face. If you want, you can change the camera's up
vector to alter the camera's orbital plane:
this.camera.up.set(0, 0, 1);
this.camera.lookAt(newTarget);
this.controls.target.copy(newTarget);
I was able to solve my problem thanks to the .copy method, thank you very much for your response !
And thank you for your great work with this project!
Glad that fixed it for you!