Skip to content

Commit

Permalink
fix(OrbitControls): update camera up direction (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjinp authored Jul 30, 2023
1 parent 048da9a commit 6616a6e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/controls/OrbitControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,10 @@ class OrbitControls extends EventDispatcher {
// this method is exposed, but perhaps it would be better if we can make it private...
this.update = ((): (() => void) => {
const offset = new Vector3()
const up = new Vector3(0, 1, 0)

// so camera.up is the orbit axis
const quat = new Quaternion().setFromUnitVectors(object.up, new Vector3(0, 1, 0))
const quat = new Quaternion().setFromUnitVectors(object.up, up)
const quatInverse = quat.clone().invert()

const lastPosition = new Vector3()
Expand All @@ -199,6 +200,10 @@ class OrbitControls extends EventDispatcher {
return function update(): boolean {
const position = scope.object.position

// update new up direction
quat.setFromUnitVectors(object.up, up)
quatInverse.copy(quat).invert()

offset.copy(position).sub(scope.target)

// rotate offset to "y-axis-is-up" space
Expand Down

0 comments on commit 6616a6e

Please sign in to comment.