Skip to content

Commit 24ba60e

Browse files
authored
Set the proper up-direction (#31054)
1 parent f21c287 commit 24ba60e

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/audio/AudioListener.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import { AudioContext } from './AudioContext.js';
77
const _position = /*@__PURE__*/ new Vector3();
88
const _quaternion = /*@__PURE__*/ new Quaternion();
99
const _scale = /*@__PURE__*/ new Vector3();
10-
const _orientation = /*@__PURE__*/ new Vector3();
10+
11+
const _forward = /*@__PURE__*/ new Vector3();
12+
const _up = /*@__PURE__*/ new Vector3();
1113

1214
/**
1315
* The class represents a virtual listener of the all positional and non-positional audio effects
@@ -175,13 +177,14 @@ class AudioListener extends Object3D {
175177
super.updateMatrixWorld( force );
176178

177179
const listener = this.context.listener;
178-
const up = this.up;
179180

180181
this.timeDelta = this._clock.getDelta();
181182

182183
this.matrixWorld.decompose( _position, _quaternion, _scale );
183184

184-
_orientation.set( 0, 0, - 1 ).applyQuaternion( _quaternion );
185+
// the initial forward and up directions must be orthogonal
186+
_forward.set( 0, 0, - 1 ).applyQuaternion( _quaternion );
187+
_up.set( 0, 1, 0 ).applyQuaternion( _quaternion );
185188

186189
if ( listener.positionX ) {
187190

@@ -192,17 +195,17 @@ class AudioListener extends Object3D {
192195
listener.positionX.linearRampToValueAtTime( _position.x, endTime );
193196
listener.positionY.linearRampToValueAtTime( _position.y, endTime );
194197
listener.positionZ.linearRampToValueAtTime( _position.z, endTime );
195-
listener.forwardX.linearRampToValueAtTime( _orientation.x, endTime );
196-
listener.forwardY.linearRampToValueAtTime( _orientation.y, endTime );
197-
listener.forwardZ.linearRampToValueAtTime( _orientation.z, endTime );
198-
listener.upX.linearRampToValueAtTime( up.x, endTime );
199-
listener.upY.linearRampToValueAtTime( up.y, endTime );
200-
listener.upZ.linearRampToValueAtTime( up.z, endTime );
198+
listener.forwardX.linearRampToValueAtTime( _forward.x, endTime );
199+
listener.forwardY.linearRampToValueAtTime( _forward.y, endTime );
200+
listener.forwardZ.linearRampToValueAtTime( _forward.z, endTime );
201+
listener.upX.linearRampToValueAtTime( _up.x, endTime );
202+
listener.upY.linearRampToValueAtTime( _up.y, endTime );
203+
listener.upZ.linearRampToValueAtTime( _up.z, endTime );
201204

202205
} else {
203206

204207
listener.setPosition( _position.x, _position.y, _position.z );
205-
listener.setOrientation( _orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z );
208+
listener.setOrientation( _forward.x, _forward.y, _forward.z, _up.x, _up.y, _up.z );
206209

207210
}
208211

0 commit comments

Comments
 (0)