123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- var BABYLON;
- (function (BABYLON) {
- var FreeCameraTouchInput = (function () {
- function FreeCameraTouchInput() {
- this._offsetX = null;
- this._offsetY = null;
- this._pointerCount = 0;
- this._pointerPressed = [];
- this.touchAngularSensibility = 200000.0;
- this.touchMoveSensibility = 250.0;
- }
- FreeCameraTouchInput.prototype.attachControl = function (element, noPreventDefault) {
- var _this = this;
- var previousPosition;
- if (this._pointerInput === undefined) {
- this._onLostFocus = function (evt) {
- _this._offsetX = null;
- _this._offsetY = null;
- };
- this._pointerInput = function (p, s) {
- var evt = p.event;
- if (evt.pointerType === "mouse") {
- return;
- }
- if (p.type === BABYLON.PointerEventTypes.POINTERDOWN) {
- if (!noPreventDefault) {
- evt.preventDefault();
- }
- _this._pointerPressed.push(evt.pointerId);
- if (_this._pointerPressed.length !== 1) {
- return;
- }
- previousPosition = {
- x: evt.clientX,
- y: evt.clientY
- };
- }
- else if (p.type === BABYLON.PointerEventTypes.POINTERUP) {
- if (!noPreventDefault) {
- evt.preventDefault();
- }
- var index = _this._pointerPressed.indexOf(evt.pointerId);
- if (index === -1) {
- return;
- }
- _this._pointerPressed.splice(index, 1);
- if (index != 0) {
- return;
- }
- previousPosition = null;
- _this._offsetX = null;
- _this._offsetY = null;
- }
- else if (p.type === BABYLON.PointerEventTypes.POINTERMOVE) {
- if (!noPreventDefault) {
- evt.preventDefault();
- }
- if (!previousPosition) {
- return;
- }
- var index = _this._pointerPressed.indexOf(evt.pointerId);
- if (index != 0) {
- return;
- }
- _this._offsetX = evt.clientX - previousPosition.x;
- _this._offsetY = -(evt.clientY - previousPosition.y);
- }
- };
- }
- this._observer = this.camera.getScene().onPointerObservable.add(this._pointerInput, BABYLON.PointerEventTypes.POINTERDOWN | BABYLON.PointerEventTypes.POINTERUP | BABYLON.PointerEventTypes.POINTERMOVE);
- element.addEventListener("blur", this._onLostFocus);
- };
- FreeCameraTouchInput.prototype.detachControl = function (element) {
- if (this._pointerInput && element) {
- this.camera.getScene().onPointerObservable.remove(this._observer);
- this._observer = null;
- element.removeEventListener("blur", this._onLostFocus);
- this._onLostFocus = null;
- this._pointerPressed = [];
- this._offsetX = null;
- this._offsetY = null;
- this._pointerCount = 0;
- }
- };
- FreeCameraTouchInput.prototype.checkInputs = function () {
- if (this._offsetX) {
- var camera = this.camera;
- camera.cameraRotation.y += this._offsetX / this.touchAngularSensibility;
- if (this._pointerPressed.length > 1) {
- camera.cameraRotation.x += -this._offsetY / this.touchAngularSensibility;
- }
- else {
- var speed = camera._computeLocalCameraSpeed();
- var direction = new BABYLON.Vector3(0, 0, speed * this._offsetY / this.touchMoveSensibility);
- BABYLON.Matrix.RotationYawPitchRollToRef(camera.rotation.y, camera.rotation.x, 0, camera._cameraRotationMatrix);
- camera.cameraDirection.addInPlace(BABYLON.Vector3.TransformCoordinates(direction, camera._cameraRotationMatrix));
- }
- }
- };
- FreeCameraTouchInput.prototype.getTypeName = function () {
- return "FreeCameraTouchInput";
- };
- FreeCameraTouchInput.prototype.getSimpleName = function () {
- return "touch";
- };
- __decorate([
- BABYLON.serialize()
- ], FreeCameraTouchInput.prototype, "touchAngularSensibility", void 0);
- __decorate([
- BABYLON.serialize()
- ], FreeCameraTouchInput.prototype, "touchMoveSensibility", void 0);
- return FreeCameraTouchInput;
- })();
- BABYLON.FreeCameraTouchInput = FreeCameraTouchInput;
- BABYLON.CameraInputTypes["FreeCameraTouchInput"] = FreeCameraTouchInput;
- })(BABYLON || (BABYLON = {}));
|