Skip to content

Commit a071747

Browse files
committed
OrbitControls: Apply Object's up in runtime
1 parent 4d6fa0d commit a071747

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

examples/jsm/controls/OrbitControls.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ class OrbitControls extends EventDispatcher {
171171
// this method is exposed, but perhaps it would be better if we can make it private...
172172
this.update = function () {
173173

174-
const offset = new Vector3();
174+
let quat = new Quaternion();
175+
let quatInverse = quat.clone().invert();
176+
const yAxisUp = new Vector3( 0, 1, 0 );
175177

176-
// so camera.up is the orbit axis
177-
const quat = new Quaternion().setFromUnitVectors( object.up, new Vector3( 0, 1, 0 ) );
178-
const quatInverse = quat.clone().invert();
178+
const offset = new Vector3();
179179

180180
const lastPosition = new Vector3();
181181
const lastQuaternion = new Quaternion();
@@ -189,12 +189,13 @@ class OrbitControls extends EventDispatcher {
189189

190190
offset.copy( position ).sub( scope.target );
191191

192+
// so camera.up is the orbit axis
193+
quat = new Quaternion().setFromUnitVectors( object.up, yAxisUp );
194+
quatInverse = quat.clone().invert();
195+
192196
// rotate offset to "y-axis-is-up" space
193197
offset.applyQuaternion( quat );
194198

195-
// angle from z-axis around y-axis
196-
spherical.setFromVector3( offset );
197-
198199
if ( scope.autoRotate && state === STATE.NONE ) {
199200

200201
rotateLeft( getAutoRotationAngle( deltaTime ) );

0 commit comments

Comments
 (0)