|
@@ -10,25 +10,34 @@ module BABYLON {
|
|
private _onPointerUp: (e: PointerEvent) => any;
|
|
private _onPointerUp: (e: PointerEvent) => any;
|
|
private _onPointerMove: (e: PointerEvent) => any;
|
|
private _onPointerMove: (e: PointerEvent) => any;
|
|
|
|
|
|
- public angularSensibility: number = 200000.0;
|
|
|
|
- public moveSensibility: number = 500.0;
|
|
|
|
|
|
+ public touchAngularSensibility: number = 200000.0;
|
|
|
|
+ public touchMoveSensibility: number = 500.0;
|
|
|
|
|
|
constructor(name: string, position: Vector3, scene: Scene) {
|
|
constructor(name: string, position: Vector3, scene: Scene) {
|
|
super(name, position, scene);
|
|
super(name, position, scene);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public _onLostFocus(e: FocusEvent): void {
|
|
|
|
+ this._offsetX = null;
|
|
|
|
+ this._offsetY = null;
|
|
|
|
+ super._onLostFocus(e);
|
|
|
|
+ }
|
|
|
|
+
|
|
public attachControl(canvas: HTMLCanvasElement, noPreventDefault: boolean): void {
|
|
public attachControl(canvas: HTMLCanvasElement, noPreventDefault: boolean): void {
|
|
var previousPosition;
|
|
var previousPosition;
|
|
|
|
|
|
if (this._attachedCanvas) {
|
|
if (this._attachedCanvas) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- this._attachedCanvas = canvas;
|
|
|
|
|
|
|
|
if (this._onPointerDown === undefined) {
|
|
if (this._onPointerDown === undefined) {
|
|
|
|
|
|
this._onPointerDown = (evt) => {
|
|
this._onPointerDown = (evt) => {
|
|
|
|
|
|
|
|
+ if (evt.pointerType === "mouse") {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
if (!noPreventDefault) {
|
|
if (!noPreventDefault) {
|
|
evt.preventDefault();
|
|
evt.preventDefault();
|
|
}
|
|
}
|
|
@@ -46,6 +55,11 @@ module BABYLON {
|
|
};
|
|
};
|
|
|
|
|
|
this._onPointerUp = (evt) => {
|
|
this._onPointerUp = (evt) => {
|
|
|
|
+
|
|
|
|
+ if (evt.pointerType === "mouse") {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
if (!noPreventDefault) {
|
|
if (!noPreventDefault) {
|
|
evt.preventDefault();
|
|
evt.preventDefault();
|
|
}
|
|
}
|
|
@@ -66,6 +80,11 @@ module BABYLON {
|
|
};
|
|
};
|
|
|
|
|
|
this._onPointerMove = (evt) => {
|
|
this._onPointerMove = (evt) => {
|
|
|
|
+
|
|
|
|
+ if (evt.pointerType === "mouse") {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
if (!noPreventDefault) {
|
|
if (!noPreventDefault) {
|
|
evt.preventDefault();
|
|
evt.preventDefault();
|
|
}
|
|
}
|
|
@@ -84,10 +103,7 @@ module BABYLON {
|
|
this._offsetY = -(evt.clientY - previousPosition.y);
|
|
this._offsetY = -(evt.clientY - previousPosition.y);
|
|
};
|
|
};
|
|
|
|
|
|
- this._onLostFocus = () => {
|
|
|
|
- this._offsetX = null;
|
|
|
|
- this._offsetY = null;
|
|
|
|
- };
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
canvas.addEventListener("pointerdown", this._onPointerDown);
|
|
canvas.addEventListener("pointerdown", this._onPointerDown);
|
|
@@ -95,9 +111,7 @@ module BABYLON {
|
|
canvas.addEventListener("pointerout", this._onPointerUp);
|
|
canvas.addEventListener("pointerout", this._onPointerUp);
|
|
canvas.addEventListener("pointermove", this._onPointerMove);
|
|
canvas.addEventListener("pointermove", this._onPointerMove);
|
|
|
|
|
|
- Tools.RegisterTopRootEvents([
|
|
|
|
- { name: "blur", handler: this._onLostFocus }
|
|
|
|
- ]);
|
|
|
|
|
|
+ super.attachControl(canvas);
|
|
}
|
|
}
|
|
|
|
|
|
public detachControl(canvas: HTMLCanvasElement): void {
|
|
public detachControl(canvas: HTMLCanvasElement): void {
|
|
@@ -109,24 +123,20 @@ module BABYLON {
|
|
canvas.removeEventListener("pointerup", this._onPointerUp);
|
|
canvas.removeEventListener("pointerup", this._onPointerUp);
|
|
canvas.removeEventListener("pointerout", this._onPointerUp);
|
|
canvas.removeEventListener("pointerout", this._onPointerUp);
|
|
canvas.removeEventListener("pointermove", this._onPointerMove);
|
|
canvas.removeEventListener("pointermove", this._onPointerMove);
|
|
-
|
|
|
|
- Tools.UnregisterTopRootEvents([
|
|
|
|
- { name: "blur", handler: this._onLostFocus }
|
|
|
|
- ]);
|
|
|
|
-
|
|
|
|
- this._attachedCanvas = null;
|
|
|
|
|
|
+
|
|
|
|
+ super.detachControl(canvas);
|
|
}
|
|
}
|
|
|
|
|
|
public _checkInputs(): void {
|
|
public _checkInputs(): void {
|
|
if (this._offsetX) {
|
|
if (this._offsetX) {
|
|
|
|
|
|
- this.cameraRotation.y += this._offsetX / this.angularSensibility;
|
|
|
|
|
|
+ this.cameraRotation.y += this._offsetX / this.touchAngularSensibility;
|
|
|
|
|
|
if (this._pointerPressed.length > 1) {
|
|
if (this._pointerPressed.length > 1) {
|
|
- this.cameraRotation.x += -this._offsetY / this.angularSensibility;
|
|
|
|
|
|
+ this.cameraRotation.x += -this._offsetY / this.touchAngularSensibility;
|
|
} else {
|
|
} else {
|
|
var speed = this._computeLocalCameraSpeed();
|
|
var speed = this._computeLocalCameraSpeed();
|
|
- var direction = new Vector3(0, 0, speed * this._offsetY / this.moveSensibility);
|
|
|
|
|
|
+ var direction = new Vector3(0, 0, speed * this._offsetY / this.touchMoveSensibility);
|
|
|
|
|
|
Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, 0, this._cameraRotationMatrix);
|
|
Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, 0, this._cameraRotationMatrix);
|
|
this.cameraDirection.addInPlace(Vector3.TransformCoordinates(direction, this._cameraRotationMatrix));
|
|
this.cameraDirection.addInPlace(Vector3.TransformCoordinates(direction, this._cameraRotationMatrix));
|