-
Notifications
You must be signed in to change notification settings - Fork 4
/
RotationStrategy.ts
48 lines (31 loc) · 867 Bytes
/
RotationStrategy.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { RotationControls } from "../core/RotationControls.js";
import { PointerBehaviour } from "../input/PointerBehaviour.js";
import { Strategy } from "./Strategy.js";
/**
* A rotation strategy.
*
* @group Strategies
*/
export class RotationStrategy implements Strategy {
/**
* The controls.
*/
private controls: RotationControls;
/**
* Constructs a new rotation strategy.
*
* @param controls - The controls.
*/
constructor(controls: RotationControls) {
this.controls = controls;
}
execute(flag: boolean, event: Event): void {
const behaviour = this.controls.settings.pointer.behaviour;
const isMouse = (event.type === "mousedown" || event.type === "mouseup");
if(isMouse && behaviour !== PointerBehaviour.DEFAULT) {
this.controls.setPointerLocked();
} else {
this.controls.setRotationEnabled(flag);
}
}
}