Skip to content

Commit c666427

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

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

examples/jsm/controls/OrbitControls.js

Lines changed: 8 additions & 4 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,6 +189,10 @@ class OrbitControls extends EventDispatcher {
189189

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

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

0 commit comments

Comments
 (0)