To fix the initial jump, you get when you click on the mouse. Introduce a new dist variable for the distance to the object you are looking at, and use atan2 as a more reliable way to get longitude.
dist = Math.hypot(blue1.position.x,blue1.position.y,blue1.position.z); phi = Math.acos(blue1.position.y/dist); theta = Math.atan2(blue1.position.z,blue1.position.x); lon = THREE.Math.radToDeg(theta); lat = 90-THREE.Math.radToDeg(phi);
In onDocumentMouseMove use
camera.target.x = dist * Math.sin( phi ) * Math.cos( theta ); camera.target.y = dist * Math.cos( phi ); camera.target.z = dist * Math.sin( phi ) * Math.sin( theta );
Thus, if you take the starting position, calculate lat, long and dist, and then calculate the search for the vector, you get what you started from. Using a fixed multiple of 500 actually led to a sudden shift to a position farther than you started. (Note: Math.Hypot is not supported in IE, so you may need to calculate this yourself if you want to configure IE).
source share