Switch between orthographic and perspective Camera


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 );
		//gl.clear( gl.COLOR_BUFFER_BIT );
		if (val == false) {
			console.log("Swtiching to Perspective");
			isOrtographic = false;
			console.log("cameraPosition", cameraPosition);
			activeCamera = perspectiveCamera;
			console.log("activeCamera", activeCamera);
		} else {
			console.log("Swtiching to Ortographic");
			isOrtographic = true;
			console.log("cameraPosition", cameraPosition);
			activeCamera = orthographicCamera;
			console.log("activeCamera", activeCamera);
		oControls.object = activeCamera;
		console.log("oControls", oControls);

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.

Hi again.

The most strange thing is that on a simple Scene the function is working for me:

You can see it on this fliddle:

Best regards

It’s not, at least for me. I’ve got this error message:
ReferenceError: switchCamera is not defined
in the console, when I try to use that checkbox in dat.GUI


Please, try the last fidlle I pubished and you will see that in a simple scene it Works.
In the other hand, using WEBG2 and Shaders it seems that it doesn’t.

Here my fiddle showing the issue:

Best regards


I think that the problem is linked to in the fiddle it doesn’t work I am using a RawShaderMaterial with vertex and fragment shaders.

Or maybe I am missing something, I don’t know.

Any clues?

Best regards.


The problem still remains.

I was opening the good simple scene fiddle.

It continues not working.

You can see the issue at


Best regards