I working with an app and I need to give to the user the option of switching between these controls.
There is a way to enable or disable controls like device orientation and track ball?
I working with an app and I need to give to the user the option of switching between these controls.
There is a way to enable or disable controls like device orientation and track ball?
*** I extract part of the codes… Hope is clear, thanks**
HTML area
…
In a button element … onclick="switchmode()"
…
*inside init function
vr = true; //variable to switch from vr mode (deviceorientation ctrl to trackBall crtl) to normal mode
eyes = new THREE.Group();
cameral = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.01, 5000);
cameral.position.x = -5;
camerar = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.01, 5000);
camerar.position.x = 5;
eyes.add(cameral);
eyes.add(camerar);
eyes.position.y=200;
scene = new THREE.Scene();
scene.add(eyes);
controlvr= new THREE.DeviceOrientationControls(eyes);
controltrack = new THREE.TrackballControls(cameral); //Creating it, makes cameral looks at -90deg offset to mamerar.
...
function switchmode(){
if(vr){
vr=false; //How could I desable deviceOrientation ctrl and enable trackBall ctrl.???
}
else{vr=true: //How could I desable trackBall ctrl and enabledeviceOrientation ctrl.???
}
}
function animate() {
requestAnimationFrame(animate);
if(vr) controlvr.update();
else controltrack.update();
render();
}
var rot = 0, vel = .01, peyes = {
x: eyes.position.x,
y: eyes.position.y,
z: eyes.position.z
};
function render() {
if (move != "stop") vel += 1;
if (move === "go") {
eyes.position.z = vel * mv.z + peyes.z;
eyes.position.y = vel * mv.y + peyes.y;
eyes.position.x = vel * mv.x + peyes.x;
}
if (vr) {
renderer.setViewport(0, 0, window.innerWidth / 2, window.innerHeight);
renderer.setScissor(0, 0, window.innerWidth / 2, window.innerHeight);
renderer.setScissorTest(true);
cameral.aspect = (window.innerWidth / 2) / window.innerHeight;
cameral.updateProjectionMatrix();
renderer.render(scene, cameral);
renderer.setViewport(window.innerWidth / 2, 0, window.innerWidth / 2, window.innerHeight);
renderer.setScissor(window.innerWidth / 2, 0, window.innerWidth / 2, window.innerHeight);
renderer.setScissorTest(true);
camerar.aspect = (window.innerWidth / 2) / window.innerHeight;
camerar.updateProjectionMatrix();
}
renderer.render(scene, camerar);
world.rotateY(.0004); //Sphere holding Equirectangular panorama
}
Thanks for the further information. DeviceOrientationControls and TrackballControls both have an enabled property. It’s set to true per default. Try to set it to false if you want to stop a certain control instance.
Thanks a lot for your help,
*in the trackball control worked perfect, but in the orientation control once it was disabled and enable again it didn’t respond. I was checking the js file of the device orientation control and I found the methods connect and disconnect, I use them instead and worked perfect.
That’s bad. If you have time, you might want to file a bug at github. Adding a simple test case would be fantastic.
This exact bug still exists.
DeviceOrientationControls has been removed with r134 so there is no official support for it anymore.