-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyAnimatedCamera.js
42 lines (34 loc) · 1.11 KB
/
MyAnimatedCamera.js
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
class MyAnimatedCamera extends CGFcamera {
constructor(gameOrchestrator, fov, near, far, position, target) {
super(fov, near, far, position, target);
this.gameOrchestrator = gameOrchestrator;
this.animationTime = 2;
this.elapsedTime = 0;
this.angle = 0;
this.active = false;
}
activate(){
this.elapsedTime = 0;
this.angle = 0;
this.active = true;
}
disable(){
this.orbit(CGFcameraAxis.Y, Math.PI-this.angle);
this.gameOrchestrator.state.cameraEnd();
this.active = false;
}
update(deltaTime){
if(this.active){
this.elapsedTime += deltaTime;
if(this.elapsedTime >= this.animationTime) {
this.disable();
return;
}
let percentage = Math.min(this.elapsedTime / this.animationTime, 1);
let animFactor = EasingFunctions.easeInOutCubic(percentage);
let increment = Math.PI * animFactor - this.angle
this.orbit(CGFcameraAxis.Y, increment);
this.angle += increment;
}
}
}