Hi.
I have a strange problema by switching between a perspective Camera and an Orthographic camera.
I am also using a orbitControls.
I don’t know why, but when I try to switch the view doesn’t change and my orbitControl gets unresponsive.
Here my global variable section:
Here my init function:
function init() {
perspectiveCamera = new THREE.PerspectiveCamera( 45, canvas_w / canvas_h, 10, 20000 );
perspectiveCamera.up = new THREE.Vector3(0,0,1);
orthographicCamera = new THREE.OrthographicCamera( canvas_w / - 2, canvas_w / 2, canvas_h / 2, canvas_h / - 2, -1000000, 1000000 );
orthographicCamera.up = new THREE.Vector3(0,0,1);
activeCamera = perspectiveCamera;
oControls = new THREE.OrbitControls( activeCamera, webGl2Renderer.domElement );
}
Here the switchCamera function:
function callSwtich2Camera(val) {
var cameraPosition = activeCamera.position.clone();
var cameraMatrix = activeCamera.matrix.clone();
var oControlsTarget = oControls.target.clone();
var oControlsPosition = oControls.position0.clone();
//webGl2Renderer.setRenderTarget( null );
//webGl2Renderer.clear();
//gl.clear( gl.COLOR_BUFFER_BIT );
if (val == false) {
console.log("Swtiching to Perspective");
isOrtographic = false;
console.log("cameraPosition", cameraPosition);
activeCamera = perspectiveCamera;
activeCamera.position.copy(cameraPosition);
activeCamera.matrix.copy(cameraMatrix);
console.log("activeCamera", activeCamera);
} else {
console.log("Swtiching to Ortographic");
isOrtographic = true;
console.log("cameraPosition", cameraPosition);
activeCamera = orthographicCamera;
activeCamera.position.copy(cameraPosition);
activeCamera.matrix.copy(cameraMatrix);
console.log("activeCamera", activeCamera);
}
activeCamera.updateProjectionMatrix();
oControls.object = activeCamera;
oControls.update();
console.log("oControls", oControls);
render();
}
And finally the render function:
function render() {
webGl2Renderer.render( glScene, activeCamera );
}
In my switchCamera function I have tried many thing but always the switch only Works for the original camera type selected. I mean, if I select like in the example a perspective camera, the switch to orthographic doesn’t work but if I switch again to perspective it Works.