Is there a 'true' first person camera controller, a la PointerLockControls from three?
MNewbigging opened this issue · comments
Hi there,
We need to implement a first person camera controller, typical of FPS games where the user can navigate through the scene via WASD/Arrow keys and use the mouse to look around. Three provides this via its PointerLockControls, which doesn't play nicely with reveal out of the box (seems to fight with the reveal camera).
Just thought to ask here if reveal provides something like this out of the box. If not, what would be the recommended approach to implementing this? Custom CameraManager perhaps?
Edits: I've been trying to implement a custom CameraManager for now. I see we're using reveal v3, but:
- there's no cameraManager option in the 3d viewer constructor options interface - where is it?
- @cognite/reveal does not export CameraManagerHelper - where is it?
I suspect I'm missing something fundamental here, appreciate any help in those areas too!
Thanks for your help,
Matt
Hi @pramodcog, thanks for your reply. The docs were my first port of call!
As mentioned above, for some reason I don't see the cameraManager option in the viewer constructor, nor the exported CameraManagerHelper. We have "@cognite/reveal": "^3.0.0-beta.1",
and "@cognite/sdk": "7.1.1",
in our package.json, is there something else alongside I should install?
In the meantime I was trying to do it more manually, by getting the camera state, rotating it as per my needs, then setting it. This had unexpected results though:
const { rotation } = this.viewer.cameraManager.getCameraState();
const euler = new THREE.Euler().setFromQuaternion(rotation);
euler.x += deltaTime;
const newRot = new THREE.Quaternion().setFromEuler(euler);
this.viewer.cameraManager.setCameraState({ rotation: newRot });
The above was put in the update loop. I would expect the camera to rotate constantly along its own local axis, but it seems to be rotating against the world axes, because the rotation changes based on where the camera points in the scene and rotates on more than one axis. The getter and setter for camera state.rotation both mention local camera rotation though, so I'm not sure why it'd behave as it does.
Any ideas?
The latest version of @cognite/reveal is 3.0.1.
The Cognite3DViewer
constructor has option for cameraManager
in the above mentioned Reveal version. On the camera state changes, let me get back on it
Update: I managed to do it manually by getting the camera's rotation quaternion, cast to euler and set the axis order to 'YXZ' instead of 'XYZ'.