blob: 1d2fb5c4fc92a67af645851c565d4d824f66933c (
plain)
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
|
import Vec2 from './vec2.js';
class View {
center = Vec2.zero();
zoom = 1.0;
// Convert game coordinate to canvas coordinate
project(vec2) {
return new Vec2(
(gameCanvas.width / 2) + ((vec2.x - this.center.x) * this.zoom),
(gameCanvas.height / 2) - ((vec2.y - this.center.y) * this.zoom));
}
// Covert canvas coordinate to game coordinate
unproject(vec2) {
return new Vec2(
this.center.x + (vec2.x - (gameCanvas.width / 2)) / this.zoom,
this.center.y - (vec2.y - (gameCanvas.height/2)) / this.zoom);
}
}
function globalView() {
return gView;
}
var gView = new View();
window.view = gView;
export {
View,
globalView,
}
|