prosperon/scripts/camera2d.jso

45 lines
1.2 KiB
Plaintext
Raw Normal View History

this.phys = physics.kinematic;
2024-04-03 17:17:32 -05:00
this.dir_view2world = function(dir) { return dir.scale(this.zoom); };
2024-04-03 00:44:08 -05:00
this.view2world = function(pos) {
2024-04-04 17:28:11 -05:00
var useren = window.rendersize.scale(this.zoom);
if (window.mode === window.modetypes.stretch) {
pos = pos.scale([window.rendersize.x/window.size.x, window.rendersize.y/window.size.y]);
pos = pos.sub(window.rendersize.scale(0.5));
pos = pos.scale(this.zoom);
pos = pos.add(this.pos);
}
if (window.mode === window.modetypes.full) {
pos = pos.sub(window.size.scale(0.5));
pos = pos.scale(this.zoom);
pos = pos.add(this.pos);
}
2024-04-03 00:44:08 -05:00
return pos;
};
this.world2view = function(pos) {
2024-04-04 17:28:11 -05:00
if (window.mode === window.modetypes.stretch) {
pos = pos.sub(this.pos);
pos = pos.scale(1.0/this.zoom);
pos = pos.add(window.rendersize.scale(0.5));
}
if (window.mode === window.modetypes.full) {
pos = pos.sub(this.pos);
pos = pos.scale(1/this.zoom);
pos = pos.add(window.size.scale(0.5));
}
2024-04-03 00:44:08 -05:00
return pos;
};
2024-04-03 17:17:32 -05:00
this.screenright = function() { return this.view2world(window.size).x; }
2024-04-04 17:28:11 -05:00
this.screenleft = function() { return this.view2world([0,0]).x; }
2024-03-01 11:45:06 -06:00
var zoom = 1;
Object.mixin(self, {
set zoom(x) {
zoom = x;
if (zoom <= 0.1) zoom = 0.1;
},
get zoom() { return zoom; }
}
);