I'm using parts of the Three.js Editor in my project.
Now I have set z-axis as camera.up as described here and in the picture below.
Problem
My EditorControls behaves strangely now when performing rotations and I think it is because it does not take camera.up
into account. How can I modify the class to take camera.up
into account, when rotating?
Here is the rotate function:
this.rotate = function ( delta ) {
vector.copy( object.position ).sub( center );
var theta = Math.atan2( vector.x, vector.z );
var phi = Math.atan2( Math.sqrt( vector.x * vector.x + vector.z * vector.z ), vector.y );
theta += delta.x;
phi += delta.y;
var EPS = 0.000001;
phi = Math.max( EPS, Math.min( Math.PI - EPS, phi ) );
var radius = vector.length();
vector.x = radius * Math.sin( phi ) * Math.sin( theta );
vector.y = radius * Math.cos( phi );
vector.z = radius * Math.sin( phi ) * Math.cos( theta );
object.position.copy( center ).add( vector );
object.lookAt( center );
scope.dispatchEvent( changeEvent );
};