-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.js
More file actions
35 lines (33 loc) · 991 Bytes
/
camera.js
File metadata and controls
35 lines (33 loc) · 991 Bytes
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
class Cam {
constructor(pos, angle, zoom) {
this.position = pos;
this.angle = angle;
this.zoom = zoom;
}
translatePoint(pos){
let nx = pos.x + this.position.x;
let ny = pos.y + this.position.y;
return createVector(nx, ny);
}
rotatePoint(center, pos) {
let cx = center.x;
let cy = center.y;
let x = pos.x;
let y = pos.y;
var radians = (Math.PI / 180) * this.angle,
cos = Math.cos(radians),
sin = Math.sin(radians),
nx = (cos * (x - cx)) + (sin * (y - cy)) + cx,
ny = (cos * (y - cy)) - (sin * (x - cx)) + cy;
return createVector(nx, ny);
}
zoomPoint(center, pos) {
let offsetx = pos.x - center.x;
let offsety = pos.y - center.y;
offsetx *= this.zoom;
offsety *= this.zoom;
let nx = center.x + offsetx;
let ny = center.y + offsety;
return createVector(nx, ny);
}
}