1

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. z axis used as camera.up

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 );
};
Community
  • 1
  • 1
Jonas
  • 1,315
  • 1
  • 18
  • 31
  • The image on the right is not an illustration of Z-up -- it is an illustration of a left-handed coordinate system. three.js assumes a right-handed coordinate system. – WestLangley Aug 15 '14 at 14:15
  • I would suggest rotating the scene instead. – mrdoob Aug 15 '14 at 16:50
  • @WestLangley thank you for pointing this out. It was not clear to me that this is a different coordinate system type. mrdoob this is a good idea, but am I right, that a rotation will not result in the left picture from above, because y-coordinates are in the false direction? Under this circumstances I have to overthink my changes. So the real answer should be, that it is not possible, right? Maybe you want to write that as accepted answer? – Jonas Aug 15 '14 at 19:52
  • Yes, you cannot achieve what you want via a rotation. You can post your own answer and accept it if you want. – WestLangley Aug 15 '14 at 23:29

1 Answers1

1

Changing the coordinate system as described in the picture is not just a matter of changing an up-vector. The right picture would require three.js to be based on a left-handed coordinate system. But its based on a right-handed coordinate system, and you can not switch from one type to another by a certain rotation.

Jonas
  • 1,315
  • 1
  • 18
  • 31