@moderrkowo/jsgl
Version:
Client-side JavaScript library for creating web 2D games. Focusing at objective game.
89 lines (88 loc) • 2.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Rotation = exports.RotationType = void 0;
var RotationType;
(function (RotationType) {
RotationType["DEGREES"] = "DEGREES";
RotationType["RADIANS"] = "RADIANS";
})(RotationType = exports.RotationType || (exports.RotationType = {}));
var Rotation = /** @class */ (function () {
function Rotation(rotation) {
if (rotation === void 0) { rotation = { type: RotationType.DEGREES, value: 0 }; }
if (rotation.type === RotationType.DEGREES) {
this._value = rotation.value;
}
else if (rotation.type === RotationType.RADIANS) {
this._value = Rotation.ToDegrees(rotation.value);
}
else {
throw new Error('Cannot recognize rotation type!');
}
}
Object.defineProperty(Rotation, "right", {
get: function () {
return new Rotation({ type: RotationType.DEGREES, value: 0 });
},
enumerable: false,
configurable: true
});
Object.defineProperty(Rotation, "down", {
get: function () {
return new Rotation({ type: RotationType.DEGREES, value: 90 });
},
enumerable: false,
configurable: true
});
Object.defineProperty(Rotation, "left", {
get: function () {
return new Rotation({ type: RotationType.DEGREES, value: -180 });
},
enumerable: false,
configurable: true
});
Object.defineProperty(Rotation, "up", {
get: function () {
return new Rotation({ type: RotationType.DEGREES, value: -90 });
},
enumerable: false,
configurable: true
});
Object.defineProperty(Rotation.prototype, "angles", {
get: function () {
return Rotation.ToRadians(this._value);
},
set: function (radians) {
this._value = Rotation.ToDegrees(radians);
},
enumerable: false,
configurable: true
});
Object.defineProperty(Rotation.prototype, "eulerAngles", {
get: function () {
return this._value;
},
set: function (degrees) {
this._value = degrees;
},
enumerable: false,
configurable: true
});
/**
* Converts degrees to radians.
* @param degrees The degrees
* @returns The radians
*/
Rotation.ToRadians = function (degrees) {
return ((degrees % 360) * Math.PI) / 180;
};
/**
* Converts radians to degrees.
* @param radians The radians
* @returns The degrees
*/
Rotation.ToDegrees = function (radians) {
return (radians / Math.PI) * 180;
};
return Rotation;
}());
exports.Rotation = Rotation;