TrackballControls don't work if camera.position is on the y-axis
See original GitHub issueIn the example below, if camera.position is set to (0,distance,0)  where distance is some positive number, the trackball controls don’t work properly anymore. Instead there is only zooming if the left mouse button is pressed and the mouse is moved around. Just press the “ALIGN Y” button to see this. The behavior is not observed pressing the “ALIGN X” or “ALIGN Z” button.
`<!DOCTYPE html>
<html lang="en"> <head> <title>TrackballControls test</title> <meta charset="utf-8"> </head><body>
	<script src='js/libs/inflate.min.js'></script>
	<script src="js/three.js"></script>
	<script src="js/controls/TrackballControls.js"></script>
	<div>
	<button onclick="alignX()" >ALIGN X</button>
	<button onclick="alignY()" >ALIGN Y</button>
	<button onclick="alignZ()" >ALIGN Z</button>
	</div>
	<script>
		var container, camera, controls, scene, renderer, distance;
		init();
		animate();
		function alignX() {controls.reset(); camera.position.set(distance,0,0);}
		function alignY() {controls.reset(); camera.position.set(0,distance,0);}
		function alignZ() {controls.reset(); camera.position.set(0,0,distance);}
		function init() {
			camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.01, 1000 );
			distance = 2.2;
			camera.position.set(0,0,distance);
			controls = new THREE.TrackballControls( camera );
			controls.rotateSpeed = 5.0;
			controls.zoomSpeed = 5;
			controls.panSpeed = 2;
			controls.noZoom = false;
			controls.noPan = false;
			controls.staticMoving = true;
			controls.dynamicDampingFactor = 0.3;
			scene = new THREE.Scene();
			// light
			var ambientLight = new THREE.AmbientLight(0x222222);
			camera.add( ambientLight );
			var light = new THREE.PointLight();
                            light.position.set( 2, 2, 2 );
                            camera.add( light );
			scene.add( camera );
			// objects
			var material = new THREE.MeshLambertMaterial({ vertexColors: THREE.FaceColors });
			var ico = new THREE.IcosahedronGeometry( 0.8, 0 );
			for ( var i = 0; i < ico.faces.length; i ++ ) {
				var face = ico.faces[ i ];
				face.color.setHex( Math.random() * 0xffffff );
			}
			var bert = new THREE.Mesh( ico, material );
			scene.add( bert )
			// renderer
			renderer = new THREE.WebGLRenderer( { antialias: false } );
			renderer.setPixelRatio( window.devicePixelRatio );
			renderer.setSize( window.innerWidth, window.innerHeight );
			container = document.createElement( 'div' );
			document.body.appendChild( container );
			container.appendChild( renderer.domElement );
			window.addEventListener( 'resize', onWindowResize, false );
		}
		function onWindowResize() {
			camera.aspect = window.innerWidth / window.innerHeight;
			camera.updateProjectionMatrix();
			renderer.setSize( window.innerWidth, window.innerHeight );
			controls.handleResize();
		}
		function animate() {
			requestAnimationFrame( animate );
			controls.update();
			renderer.render( scene, camera );
		}
	</script>
</body>
</html>`
Three.js version
- Dev
 - r82
 - …
 
Browser
- All of them
 - Chrome
 - Firefox
 - Internet Explorer
 
OS
- All of them
 - Windows
 - Linux
 - Android
 - IOS
 
Issue Analytics
- State:
 - Created 7 years ago
 - Reactions:2
 - Comments:9 (2 by maintainers)
 
Top Results From Across the Web
THREE.js TrackballControls don't work if camera.position is on ...
Instead there is only zooming if the left mouse button is pressed and the mouse is moved around. Just press the "ALIGN Y"...
Read more >TrackballControls – three.js docs
TrackballControls is similar to OrbitControls. However, it does not maintain a constant camera up vector. That means if the camera orbits over the...
Read more >Introduction to Computer Graphics, Section 5.3 -- Other Features
The OrbitControls object is used to rotate the camera around the scene. ... clientX - r.left; // convert mouse location to canvas pixel...
Read more >Getting Started With Your First three.js Project: Part One
We now have our environment completely set up, including a scene, a camera and a renderer to draw everything for us. Don't panic...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yes, the problem is that camera.up defaults to the y-axis. I fixed it by adding
at line 170 in TrackballControls.js If somebody could add this to the actual file that would be great.
@h-a-n-n-e-s this helped me greatly, and for anyone else, changing my camera’s up after construction also works
this.camera.up.set(0, 0, 1);