|
@@ -1,4 +1,4 @@
|
|
|
-import { Observer, EventState } from "../../Misc/observable";
|
|
|
+import { Observer, EventState, Observable } from "../../Misc/observable";
|
|
|
import { serialize } from "../../Misc/decorators";
|
|
|
import { Nullable } from "../../types";
|
|
|
import { ICameraInput, CameraInputTypes } from "../../Cameras/cameraInputsManager";
|
|
@@ -32,6 +32,15 @@ export class FreeCameraMouseInput implements ICameraInput<FreeCamera> {
|
|
|
private previousPosition: Nullable<{ x: number, y: number }> = null;
|
|
|
|
|
|
/**
|
|
|
+ * Observable for when a pointer move event occurs containing the move offset
|
|
|
+ */
|
|
|
+ public onPointerMovedObservable = new Observable<{ offsetX: number, offsetY: number }>();
|
|
|
+ /**
|
|
|
+ * @hidden
|
|
|
+ * If the camera should be rotated automatically based on pointer movement
|
|
|
+ */
|
|
|
+ public _allowCameraRotation = true;
|
|
|
+ /**
|
|
|
* Manage the mouse inputs to control the movement of a free camera.
|
|
|
* @see http://doc.babylonjs.com/how_to/customizing_camera_inputs
|
|
|
* @param touchEnabled Defines if touch is enabled or not
|
|
@@ -105,12 +114,15 @@ export class FreeCameraMouseInput implements ICameraInput<FreeCamera> {
|
|
|
}
|
|
|
|
|
|
var offsetX = evt.clientX - this.previousPosition.x;
|
|
|
+ var offsetY = evt.clientY - this.previousPosition.y;
|
|
|
if (this.camera.getScene().useRightHandedSystem) { offsetX *= -1; }
|
|
|
if (this.camera.parent && this.camera.parent._getWorldMatrixDeterminant() < 0) { offsetX *= -1; }
|
|
|
- this.camera.cameraRotation.y += offsetX / this.angularSensibility;
|
|
|
|
|
|
- var offsetY = evt.clientY - this.previousPosition.y;
|
|
|
- this.camera.cameraRotation.x += offsetY / this.angularSensibility;
|
|
|
+ if (this._allowCameraRotation) {
|
|
|
+ this.camera.cameraRotation.y += offsetX / this.angularSensibility;
|
|
|
+ this.camera.cameraRotation.x += offsetY / this.angularSensibility;
|
|
|
+ }
|
|
|
+ this.onPointerMovedObservable.notifyObservers({offsetX: offsetX, offsetY: offsetY});
|
|
|
|
|
|
this.previousPosition = {
|
|
|
x: evt.clientX,
|
|
@@ -179,6 +191,10 @@ export class FreeCameraMouseInput implements ICameraInput<FreeCamera> {
|
|
|
element.removeEventListener("contextmenu", <EventListener>this.onContextMenu);
|
|
|
}
|
|
|
|
|
|
+ if (this.onPointerMovedObservable) {
|
|
|
+ this.onPointerMovedObservable.clear();
|
|
|
+ }
|
|
|
+
|
|
|
this._observer = null;
|
|
|
this._onMouseMove = null;
|
|
|
this.previousPosition = null;
|