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