|
@@ -9,11 +9,8 @@ module BABYLON {
|
|
|
public angularSensibility = 2000.0;
|
|
|
|
|
|
private _pointerInput: (p: PointerInfo, s: EventState) => void;
|
|
|
- private _onMouseMove: (e: MouseEvent) => any;
|
|
|
private _observer: Observer<PointerInfo>;
|
|
|
|
|
|
- private previousPosition: { x: number, y: number };
|
|
|
-
|
|
|
constructor(public touchEnabled = true) {
|
|
|
}
|
|
|
|
|
@@ -21,6 +18,7 @@ module BABYLON {
|
|
|
var engine = this.camera.getEngine();
|
|
|
|
|
|
if (!this._pointerInput) {
|
|
|
+ var isPointerDown = false;
|
|
|
this._pointerInput = (p, s) => {
|
|
|
var evt = <PointerEvent>p.event;
|
|
|
|
|
@@ -39,10 +37,7 @@ module BABYLON {
|
|
|
//Nothing to do with the error. Execution will continue.
|
|
|
}
|
|
|
|
|
|
- this.previousPosition = {
|
|
|
- x: evt.clientX,
|
|
|
- y: evt.clientY
|
|
|
- };
|
|
|
+ isPointerDown = true;
|
|
|
|
|
|
if (!noPreventDefault) {
|
|
|
evt.preventDefault();
|
|
@@ -56,33 +51,28 @@ module BABYLON {
|
|
|
//Nothing to do with the error.
|
|
|
}
|
|
|
|
|
|
- this.previousPosition = null;
|
|
|
+ isPointerDown = false;
|
|
|
+
|
|
|
if (!noPreventDefault) {
|
|
|
evt.preventDefault();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
else if (p.type === PointerEventTypes.POINTERMOVE) {
|
|
|
- if (!this.previousPosition || engine.isPointerLock) {
|
|
|
+ if (!isPointerDown && !engine.isPointerLock) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- var offsetX = evt.clientX - this.previousPosition.x;
|
|
|
- var offsetY = evt.clientY - this.previousPosition.y;
|
|
|
+ var offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
|
|
|
+ var offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
|
|
|
|
|
|
if (this.camera.getScene().useRightHandedSystem) {
|
|
|
this.camera.cameraRotation.y -= offsetX / this.angularSensibility;
|
|
|
} else {
|
|
|
this.camera.cameraRotation.y += offsetX / this.angularSensibility;
|
|
|
}
|
|
|
-
|
|
|
this.camera.cameraRotation.x += offsetY / this.angularSensibility;
|
|
|
|
|
|
- this.previousPosition = {
|
|
|
- x: evt.clientX,
|
|
|
- y: evt.clientY
|
|
|
- };
|
|
|
-
|
|
|
if (!noPreventDefault) {
|
|
|
evt.preventDefault();
|
|
|
}
|
|
@@ -90,42 +80,13 @@ module BABYLON {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- this._onMouseMove = evt => {
|
|
|
- if (!engine.isPointerLock) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- var offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
|
|
|
- var offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
|
|
|
-
|
|
|
- if (this.camera.getScene().useRightHandedSystem) {
|
|
|
- this.camera.cameraRotation.y -= offsetX / this.angularSensibility;
|
|
|
- } else {
|
|
|
- this.camera.cameraRotation.y += offsetX / this.angularSensibility;
|
|
|
- }
|
|
|
-
|
|
|
- this.camera.cameraRotation.x += offsetY / this.angularSensibility;
|
|
|
-
|
|
|
- this.previousPosition = null;
|
|
|
-
|
|
|
- if (!noPreventDefault) {
|
|
|
- evt.preventDefault();
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
this._observer = this.camera.getScene().onPointerObservable.add(this._pointerInput, PointerEventTypes.POINTERDOWN | PointerEventTypes.POINTERUP | PointerEventTypes.POINTERMOVE);
|
|
|
- element.addEventListener("mousemove", this._onMouseMove, false);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
detachControl(element: HTMLElement) {
|
|
|
if (this._observer && element) {
|
|
|
this.camera.getScene().onPointerObservable.remove(this._observer);
|
|
|
- element.removeEventListener("mousemove", this._onMouseMove);
|
|
|
-
|
|
|
this._observer = null;
|
|
|
- this._onMouseMove = null;
|
|
|
- this.previousPosition = null;
|
|
|
}
|
|
|
}
|
|
|
|