UNPKG

convex-pixel

Version:

The library for creating pseudo 3d interactive scenes based on webgl

77 lines 3.41 kB
import { Vector2D } from "../../utils/geom"; var CameraMouseController = /** @class */ (function () { function CameraMouseController(appContext) { var _this = this; this.appContext = appContext; this._cameraTarget = new Vector2D(); this._handlerStageTouchMove = function (event) { _this.calculate(event.data.global.x, event.data.global.y); }; this._handlerStageMouseMove = function (event) { _this.calculate(event.data.global.x, event.data.global.y); }; appContext.pixi.stage.interactive = true; appContext.pixi.stage.on("mousemove", this._handlerStageMouseMove); appContext.pixi.stage.on("touchmove", this._handlerStageTouchMove); } CameraMouseController.prototype.initialize = function () { if (!this.camera) { throw Error("Property \"camera\" is not defined"); } this._handlerStageMouseMove({ data: { global: { x: this.camera.viewport.width * 0.5, y: this.camera.viewport.height * 0.5, }, }, }); }; CameraMouseController.prototype.destroy = function () { this.appContext.pixi.stage.off("mousemove", this._handlerStageMouseMove); this.appContext.pixi.stage.off("touchmove", this._handlerStageTouchMove); this.onMove = this.onPOV = this.onZoom = this.onRotate = undefined; }; CameraMouseController.prototype.calculate = function (x, y) { if (!this.camera) { throw Error("Property \"camera\" is not defined"); } var sceneBounds = this.camera.room.roomBound; var sWidth = sceneBounds.width * this.camera.room.scale.x; var sHeight = sceneBounds.height * this.camera.room.scale.y; var xx = this.camera.viewport.width * 0.5 - x; var yy = this.camera.viewport.height * 0.5 - y; /*if (x > this.camera.viewport.width) xx = this.camera.viewport.width; else if (x < 0) xx = 0; if (y > this.camera.viewport.height) yy = this.camera.viewport.height; else if (y < 0) yy = 0;*/ // const sign = inverse ? -1 : 1; // let sx = // this.camera.viewport.width * 0.5 - // xx /* * // this.camera.maxXOffset * sign*/; // let sy = // this.camera.viewport.height * 0.5 - // yy /* * // this.camera.maxYOffset * sign*/; /*let povX = -sx * 0.0075 * this.camera.povFactor; let povY = sy * 0.0075 * this.camera.povFactor; if (Math.abs(povX) > this.camera.maxXOffset) { povX = this.camera.maxXOffset * Math.sign(povX); } if (Math.abs(povY) > this.camera.maxYOffset) { povY = this.camera.maxYOffset * Math.sign(povY); }*/ if (this.onPOV) { this.onPOV(Vector2D.new(xx, yy)); } var sx = (sWidth - this.camera.viewport.width) * (x / this.camera.viewport.width); var sy = (sHeight - this.camera.viewport.height) * (y / this.camera.viewport.height); if (this.onMove) { this.onMove(Vector2D.new(sx, sy)); } }; return CameraMouseController; }()); export { CameraMouseController }; //# sourceMappingURL=camera-mouse-controller.js.map