prosperon/scripts/camera2d.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

this.phys = physics.kinematic;
2024-09-26 11:36:09 -05:00
this.dir_view2world = function (dir) {
return dir.scale(this.zoom);
};
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) {
2024-09-26 11:36:09 -05:00
pos = pos.scale([window.rendersize.x / window.size.x, window.rendersize.y / window.size.y]);
2024-04-04 17:28:11 -05:00
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));
2024-09-26 11:36:09 -05:00
pos = pos.scale(this.zoom);
2024-04-04 17:28:11 -05:00
pos = pos.add(this.pos);
}
2024-05-02 13:52:28 -05:00
if (window.mode === window.modetypes.expand) {
2024-09-26 11:36:09 -05:00
pos = pos.sub(window.size.scale(0.5));
pos = pos.scale([window.rendersize.x / window.size.x, window.rendersize.y / window.size.y]);
2024-05-02 13:52:28 -05:00
}
2024-04-03 00:44:08 -05:00
return pos;
};
2024-09-26 11:36:09 -05:00
this.world2view = function (pos) {
2024-04-04 17:28:11 -05:00
if (window.mode === window.modetypes.stretch) {
pos = pos.sub(this.pos);
2024-09-26 11:36:09 -05:00
pos = pos.scale(1.0 / this.zoom);
2024-04-04 17:28:11 -05:00
pos = pos.add(window.rendersize.scale(0.5));
}
if (window.mode === window.modetypes.full) {
pos = pos.sub(this.pos);
2024-09-26 11:36:09 -05:00
pos = pos.scale(1 / this.zoom);
2024-04-04 17:28:11 -05:00
pos = pos.add(window.size.scale(0.5));
2024-05-02 13:52:28 -05:00
}
if (window.mode === window.modetypes.expand) {
2024-04-04 17:28:11 -05:00
}
2024-04-03 00:44:08 -05:00
return pos;
};
2024-09-26 11:36:09 -05:00
this.screenright = function () {
return this.view2world(window.size).x;
};
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;
},
2024-09-26 11:36:09 -05:00
get zoom() {
return zoom;
},
});