Currently, I am working on a ThreeJS Demo where I have implemented the functionality to use the arrow keys for rotating the camera. Initially, everything seems to be functioning fine as I can rotate the camera up, down, left, and right successfully. However, I encountered an issue when I turn to the left and then attempt to rotate up or down - the rotation does not happen relative to my current position but instead acts as if I had not rotated left at all.
Below is the code snippet of my current rendering logic:
function render() {
plane.rotation.y += 0.005;
cube.rotation.z += 0.01;
cube.rotation.y += 0.01;
if (window.isLeftDown) {
camera.rotation.y += 0.01;
}
if (window.isRightDown) {
camera.rotation.y -= 0.01;
}
if (window.isUpDown) {
camera.rotation.x -= 0.01;
}
if (window.isDownDown) {
camera.rotation.x += 0.01;
}
requestAnimationFrame(render);
renderer.render(scene, camera2, renderTarget, true);
renderer.render(scene, camera);
}
Do you have any suggestions or ideas on how to resolve this issue?