-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.js
91 lines (54 loc) · 1.34 KB
/
camera.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
FOV = distanceFromMonitor & screenSize
FOVX & FOVY
*/
class Camera {
/*
Units:
~ Distance: Inches
~ Angle: Radians
*/
constructor(x = 0, y = -25.8, z = 0) {
// Camera position
this.x = x;
this.y = y;
this.z = z;
// Viewport
this.vp = new Viewport();
this.far = 1000;
// print(SCREEN_WIDTH + "\" x " + SCREEN_HEIGHT + "\"");
// Calculate angles to viewport
this.calcViewportAngles();
}
calcViewportAngles() {
this.vpBL = vectorToXYZ(this, this.vp.vert[0]);
this.vpBR = vectorToXYZ(this, this.vp.vert[1]);
this.vpTR = vectorToXYZ(this, this.vp.vert[2]);
this.vpTL = vectorToXYZ(this, this.vp.vert[3]);
this.fov = vAngleBetween(this.vpTR, this.vpTL);
}
move(x = this.x, y = this.y, z = this.z) {
this.x = x;
this.y = y;
this.z = z;
// Updates
this.calcViewportAngles();
}
}
class Viewport {
constructor() {
this.x = 0;
this.y = 0;
this.z = 0;
this.w = SCREEN_WIDTH;
this.h = SCREEN_HEIGHT;
this.vert = [
{ x: this.x - this.w / 2, y: this.y, z: this.z - this.h / 2 },
{ x: this.x + this.w / 2, y: this.y, z: this.z - this.h / 2 },
{ x: this.x + this.w / 2, y: this.y, z: this.z + this.h / 2 },
{ x: this.x - this.w / 2, y: this.y, z: this.z + this.h / 2 },
];
}
}
/*
*/