export default class RotationEvent { constructor(e) { E(this, "touchStartX"); E(this, "touchStartY"); E(this, "handelResize"); E(this, "_room"); E(this, "_canvas"); E(this, "handleTouchStart", e=>{ const t = e.touches[0]; this.touchStartX = t.pageX, this.touchStartY = t.pageY, this._room.emit("touchStart", { event: e }) } ); E(this, "handleMouseDown", e=>{ this.touchStartX = e.pageX, this.touchStartY = e.pageY } ); E(this, "handleMouseMove", e=>{ if (!this.touchStartX || !this.touchStartY) return; const t = e.pageX , r = e.pageY , n = t - this.touchStartX , o = r - this.touchStartY , a = this._room.options.canvas.offsetHeight , s = this._room.options.canvas.offsetWidth; let l = 2 * o / a , u = 2 * n / s; l > 1 && (l = 1), u > 1 && (u = 1), this._room.actionsHandler.rotate({ pitch: l, yaw: u }), this.touchStartX = t, this.touchStartY = r } ); E(this, "handleMouseUp", ()=>{ this.touchStartX = void 0, this.touchStartY = void 0 } ); E(this, "handleTouchMove", e=>{ if (!this.touchStartX || !this.touchStartY) return; const t = e.touches[0] // , r = t.pageX // , n = t.pageY // , o = r - this.touchStartX // , a = n - this.touchStartY // , s = this._room.options.canvas.offsetHeight // , l = this._room.options.canvas.offsetWidth; const pageX = t.pageX const pageY = t.pageY const offsetX = pageX - this.touchStartX const offsetY = pageY - this.touchStartY const offsetHeight = this._room.options.canvas.offsetHeight const offsetWidth = this._room.options.canvas.offsetWidth let pitch = 2 * offsetY / offsetHeight; let yaw = 2 * offsetX / offsetWidth; pitch > 1 && (pitch = 1); yaw > 1 && (yaw = 1); this._room.actionsHandler.rotate({ pitch: pitch, yaw: yaw }); /***********************************************************************xst****************************************************************/ // let angle = offsetX / offsetWidth * 2 * Math.PI // this._room.actionsHandler.rotate({ // type: 'rotate', // angle: angle // }); /********************************************************************************************************************************************/ this.touchStartX = pageX; this.touchStartY = pageY; /***********************************************************************xst****************************************************************/ // this._room.emit("touchMove", { // pitch: pitch, // yaw: yaw, // event: e // }) /********************************************************************************************************************************************/ } ); E(this, "handleTouchEnd", e=>{ this._room.emit("touchEnd", { event: e }) } ); this._room = e, this._canvas = e.canvas, this.handelResize = this.reiszeChange() } init() { this._canvas.addEventListener("touchstart", this.handleTouchStart), this._canvas.addEventListener("touchmove", this.handleTouchMove), this._canvas.addEventListener("touchend", this.handleTouchEnd), this._room.scene.preventDefaultOnPointerDown = !1, this._room.scene.preventDefaultOnPointerUp = !1, this._canvas.addEventListener("mousedown", this.handleMouseDown), this._canvas.addEventListener("mousemove", this.handleMouseMove), this._canvas.addEventListener("mouseup", this.handleMouseUp) } clear() { this._canvas.removeEventListener("touchstart", this.handleTouchStart), this._canvas.removeEventListener("touchmove", this.handleTouchMove), this._canvas.removeEventListener("touchend", this.handleTouchEnd), this._canvas.removeEventListener("mousedown", this.handleMouseDown), this._canvas.removeEventListener("mousemove", this.handleMouseMove), this._canvas.removeEventListener("mouseup", this.handleMouseUp) } reiszeChange() { window.addEventListener("resize", ()=>{} ) } }