-
Notifications
You must be signed in to change notification settings - Fork 12
/
GameplayCamera.ts
65 lines (58 loc) · 1.59 KB
/
GameplayCamera.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { Vector3 } from './utils';
/**
* The current rendering gameplay camera
*/
export abstract class GameplayCamera {
/**
* Get the world position of gameplay camera.
*/
public static get Position(): Vector3 {
const coords = GetGameplayCamCoords();
return new Vector3(coords[0], coords[1], coords[2]);
}
/**
* Get the rotation of gameplay camera.
*/
public static get Rotation(): Vector3 {
const rot = GetGameplayCamRot(2);
return new Vector3(rot[0], rot[1], rot[2]);
}
/**
* Get the forward vector of gameplay camera.
*/
public static get ForwardVector(): Vector3 {
const rotation = Vector3.multiply(this.Rotation, Math.PI / 180);
const normalized = Vector3.normalize(
new Vector3(
-Math.sin(rotation.z) * Math.abs(Math.cos(rotation.x)),
Math.cos(rotation.z) * Math.abs(Math.cos(rotation.x)),
Math.sin(rotation.x),
),
);
return new Vector3(normalized.x, normalized.y, normalized.z);
}
/**
* Get the pitch of the gameplay camera relative to player.
*/
public static get RelativePitch(): number {
return GetGameplayCamRelativePitch();
}
/**
* Set gameplay camera pitch relative to player.
*/
public static set RelativePitch(pitch: number) {
SetGameplayCamRelativePitch(pitch, 1);
}
/**
* Get heading of gameplay camera.
*/
public static get RelativeHeading(): number {
return GetGameplayCamRelativeHeading();
}
/**
* Get heading of gameplay camera.
*/
public static set RelativeHeading(heading: number) {
SetGameplayCamRelativeHeading(heading);
}
}