Currently, I am working on a demo for a "First Person Controller" where the camera moves forward in response to a TOUCH event being pressed. To achieve this movement, I am using setInterval and addScaledVector for the camera's motion.
In addition to the basic functionality, I decided to incorporate Orbit Controls to allow the user to rotate the camera and look around, without any zooming capability. While most aspects are functioning correctly, I have encountered an issue with the rotation of the target when using Orbit Controls. In the target setting, I have specified camera.position.x + 1 as the value because just using camera.position.x without a value does not work. Furthermore, I have applied this setting to the camera quaternion.
var vector = new THREE.Vector3();
var speed = 8;
var timer;
var iterations = 0;
controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.rotateSpeed = 1.0;
controls.panSpeed = 0.8;
controls.target.set(camera.position.x + 1, camera.position.y,
camera.position.z);
function process_touchstart(evt) {
evt.preventDefault();
evt.stopImmediatePropagation();
iterations = 0;
timer=setInterval(function(){
iterations++;
vector.applyQuaternion( camera.quaternion );
camera.getWorldDirection( vector );
camera.position.addScaledVector( vector, speed );
controls.target.set(camera.position.x + 1,
camera.position.y,
camera.position.z);
}, 70);
}
I welcome any feedback or information from those experienced with three.js as I am relatively new to it. Any details or suggestions would be greatly appreciated. Thank you!