@koreez/phaser3-isometric-plugin
Version:
Phaser3 isometirc plugin
60 lines • 2.5 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Point3_1 = require("./Point3");
var Projector = (function () {
function Projector(scene) {
this.__scene = scene;
this.projectionAngle = scene.isoProjectionAngle || Projector.CLASSIC;
this.__origin = scene.isoOrigin || new Phaser.Geom.Point(0.5, 0.5);
}
Object.defineProperty(Projector.prototype, "projectionAngle", {
get: function () {
return this.__projectionAngle;
},
set: function (angle) {
if (angle === this.__projectionAngle) {
return;
}
this.__projectionAngle = angle;
this.__transform = [
Math.cos(this.__projectionAngle),
Math.sin(this.__projectionAngle),
];
},
enumerable: true,
configurable: true
});
Projector.prototype.project = function (point3, out) {
if (out === void 0) { out = new Phaser.Geom.Point(); }
out.x = (point3.x - point3.y) * this.__transform[0];
out.y = (point3.x + point3.y) * this.__transform[1] - point3.z;
var _a = this.__scene.sys.game.config, width = _a.width, height = _a.height;
out.x += +width * this.__origin.x;
out.y += +height * this.__origin.y;
return out;
};
Projector.prototype.projectXY = function (point3, out) {
if (out === void 0) { out = new Phaser.Geom.Point(); }
out.x = (point3.x - point3.y) * this.__transform[0];
out.y = (point3.x + point3.y) * this.__transform[1];
out.x += +this.__scene.game.config.width * this.__origin.x;
out.y += +this.__scene.game.config.height * this.__origin.y;
return out;
};
Projector.prototype.unproject = function (point, out, z) {
if (out === void 0) { out = new Point3_1.Point3(); }
if (z === void 0) { z = 0; }
var x = point.x - +this.__scene.game.config.width * this.__origin.x;
var y = point.y - +this.__scene.game.config.height * this.__origin.y + z;
out.x = x / (2 * this.__transform[0]) + y / (2 * this.__transform[1]);
out.y = -(x / (2 * this.__transform[0])) + y / (2 * this.__transform[1]);
out.z = z;
return out;
};
Projector.CLASSIC = Math.atan(0.5);
Projector.ISOMETRIC = Math.PI / 6;
Projector.MILITARY = Math.PI / 4;
return Projector;
}());
exports.Projector = Projector;
//# sourceMappingURL=Projector.js.map