Skip to content

Commit

Permalink
Enable input when rest position is reached
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehorvat committed Feb 24, 2024
1 parent 14e3d81 commit 530fb3c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/lib/scene-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export class SceneManager {
this.clock = new THREE.Clock();

this.synthesizer = new Synthesizer();
this.synthesizer.addInputListener(this.renderer, this.camera);
this.scene.add(this.synthesizer);

const ambientLight = new THREE.AmbientLight('#ffffff');
Expand Down Expand Up @@ -49,8 +48,20 @@ export class SceneManager {
* Move the synthesizer until it reaches its resting position.
*/
private animateSynthesizer(delta: number): void {
if (this.synthesizer.rotation.x < THREE.MathUtils.degToRad(45)) {
this.synthesizer.rotation.x += THREE.MathUtils.degToRad(15) * delta;
const restRotation = THREE.MathUtils.degToRad(45);

if (this.synthesizer.rotation.x === restRotation) {
return;
}

this.synthesizer.rotation.x = Math.min(
this.synthesizer.rotation.x + THREE.MathUtils.degToRad(15) * delta,
restRotation
);

// Enable input now if the resting position was just reached.
if (this.synthesizer.rotation.x === restRotation) {
this.synthesizer.addInputListener(this.renderer, this.camera);
}
}

Expand Down

0 comments on commit 530fb3c

Please sign in to comment.