|
@@ -8,7 +8,7 @@ import { KeyboardInfo, KeyboardEventTypes } from "../../Events/keyboardEvents";
|
|
import { Scene } from "../../scene";
|
|
import { Scene } from "../../scene";
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Manage the keyboard inputs to control the movement of an arc rotate camera.
|
|
|
|
|
|
+ * Manage the keyboard inputs to control the movement of a follow camera.
|
|
* @see http://doc.babylonjs.com/how_to/customizing_camera_inputs
|
|
* @see http://doc.babylonjs.com/how_to/customizing_camera_inputs
|
|
*/
|
|
*/
|
|
export class FollowCameraKeyboardMoveInput implements ICameraInput<FollowCamera> {
|
|
export class FollowCameraKeyboardMoveInput implements ICameraInput<FollowCamera> {
|
|
@@ -21,59 +21,114 @@ export class FollowCameraKeyboardMoveInput implements ICameraInput<FollowCamera>
|
|
* Defines the list of key codes associated with the up action (increase heightOffset)
|
|
* Defines the list of key codes associated with the up action (increase heightOffset)
|
|
*/
|
|
*/
|
|
@serialize()
|
|
@serialize()
|
|
- public keysUp = [38];
|
|
|
|
|
|
+ public keysHeightOffsetIncr = [38];
|
|
|
|
|
|
/**
|
|
/**
|
|
* Defines the list of key codes associated with the down action (decrease heightOffset)
|
|
* Defines the list of key codes associated with the down action (decrease heightOffset)
|
|
*/
|
|
*/
|
|
@serialize()
|
|
@serialize()
|
|
- public keysDown = [40];
|
|
|
|
|
|
+ public keysHeightOffsetDecr = [40];
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Defines the list of key codes associated with the left action (increase rotation)
|
|
|
|
|
|
+ * Defines whether the Alt modifier key is required to move up/down (alter heightOffset)
|
|
*/
|
|
*/
|
|
@serialize()
|
|
@serialize()
|
|
- public keysLeft = [37];
|
|
|
|
|
|
+ public keysHeightOffsetModifierAlt: boolean = false;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Defines the list of key codes associated with the right action (decrease rotation)
|
|
|
|
|
|
+ * Defines whether the Ctrl modifier key is required to move up/down (alter heightOffset)
|
|
*/
|
|
*/
|
|
@serialize()
|
|
@serialize()
|
|
- public keysRight = [39];
|
|
|
|
|
|
+ public keysHeightOffsetModifierCtrl: boolean = false;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Defines the rate of change of heightOffset.
|
|
|
|
|
|
+ * Defines whether the Shift modifier key is required to move up/down (alter heightOffset)
|
|
*/
|
|
*/
|
|
@serialize()
|
|
@serialize()
|
|
- public heightSensibility: number = 1;
|
|
|
|
|
|
+ public keysHeightOffsetModifierShift: boolean = false;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Defines the rate of change of rotationOffset.
|
|
|
|
|
|
+ * Defines the list of key codes associated with the left action (increase rotationOffset)
|
|
*/
|
|
*/
|
|
@serialize()
|
|
@serialize()
|
|
- public rotationSensibility: number = 1;
|
|
|
|
|
|
+ public keysRotationOffsetIncr = [37];
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Defines the rate of change of radius.
|
|
|
|
|
|
+ * Defines the list of key codes associated with the right action (decrease rotationOffset)
|
|
*/
|
|
*/
|
|
@serialize()
|
|
@serialize()
|
|
- public radiusSensibility: number = 1;
|
|
|
|
|
|
+ public keysRotationOffsetDecr = [39];
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Defines whether the Alt modifier key is required to move left/right (alter rotationOffset)
|
|
|
|
+ */
|
|
|
|
+ @serialize()
|
|
|
|
+ public keysRotationOffsetModifierAlt: boolean = false;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Defines whether the Ctrl modifier key is required to move left/right (alter rotationOffset)
|
|
|
|
+ */
|
|
|
|
+ @serialize()
|
|
|
|
+ public keysRotationOffsetModifierCtrl: boolean = false;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Defines whether the Shift modifier key is required to move left/right (alter rotationOffset)
|
|
|
|
+ */
|
|
|
|
+ @serialize()
|
|
|
|
+ public keysRotationOffsetModifierShift: boolean = false;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Defines the list of key codes associated with the zoom-in action (decrease radius)
|
|
|
|
+ */
|
|
|
|
+ @serialize()
|
|
|
|
+ public keysRadiusIncr = [40];
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Defines the list of key codes associated with the zoom-out action (increase radius)
|
|
|
|
+ */
|
|
|
|
+ @serialize()
|
|
|
|
+ public keysRadiusDecr = [38];
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Defines whether the Alt modifier key is required to zoom in/out (alter radius value)
|
|
|
|
+ */
|
|
|
|
+ @serialize()
|
|
|
|
+ public keysRadiusModifierAlt: boolean = true;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Defines whether the Ctrl modifier key is required to zoom in/out (alter radius value)
|
|
|
|
+ */
|
|
|
|
+ @serialize()
|
|
|
|
+ public keysRadiusModifierCtrl: boolean = false;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Defines whether the Shift modifier key is required to zoom in/out (alter radius value)
|
|
|
|
+ */
|
|
|
|
+ @serialize()
|
|
|
|
+ public keysRadiusModifierShift: boolean = false;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Defines the rate of change of heightOffset.
|
|
|
|
+ */
|
|
|
|
+ @serialize()
|
|
|
|
+ public heightSensibility: number = 1;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Defines the minimum heightOffset value.
|
|
|
|
|
|
+ * Defines the rate of change of rotationOffset.
|
|
*/
|
|
*/
|
|
@serialize()
|
|
@serialize()
|
|
- public minHeightOffset: number = 0;
|
|
|
|
|
|
+ public rotationSensibility: number = 1;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Defines the minimum radius value.
|
|
|
|
|
|
+ * Defines the rate of change of radius.
|
|
*/
|
|
*/
|
|
@serialize()
|
|
@serialize()
|
|
- public minRadius: number = 0;
|
|
|
|
|
|
+ public radiusSensibility: number = 1;
|
|
|
|
|
|
private _keys = new Array<number>();
|
|
private _keys = new Array<number>();
|
|
- // private _ctrlPressed: boolean;
|
|
|
|
|
|
+ private _ctrlPressed: boolean;
|
|
private _altPressed: boolean;
|
|
private _altPressed: boolean;
|
|
|
|
+ private _shiftPressed: boolean;
|
|
private _onCanvasBlurObserver: Nullable<Observer<Engine>>;
|
|
private _onCanvasBlurObserver: Nullable<Observer<Engine>>;
|
|
private _onKeyboardObserver: Nullable<Observer<KeyboardInfo>>;
|
|
private _onKeyboardObserver: Nullable<Observer<KeyboardInfo>>;
|
|
private _engine: Engine;
|
|
private _engine: Engine;
|
|
@@ -100,13 +155,16 @@ export class FollowCameraKeyboardMoveInput implements ICameraInput<FollowCamera>
|
|
let evt = info.event;
|
|
let evt = info.event;
|
|
if (!evt.metaKey) {
|
|
if (!evt.metaKey) {
|
|
if (info.type === KeyboardEventTypes.KEYDOWN) {
|
|
if (info.type === KeyboardEventTypes.KEYDOWN) {
|
|
- // this._ctrlPressed = evt.ctrlKey;
|
|
|
|
|
|
+ this._ctrlPressed = evt.ctrlKey;
|
|
this._altPressed = evt.altKey;
|
|
this._altPressed = evt.altKey;
|
|
|
|
+ this._shiftPressed = evt.shiftKey;
|
|
|
|
|
|
- if (this.keysUp.indexOf(evt.keyCode) !== -1 ||
|
|
|
|
- this.keysDown.indexOf(evt.keyCode) !== -1 ||
|
|
|
|
- this.keysLeft.indexOf(evt.keyCode) !== -1 ||
|
|
|
|
- this.keysRight.indexOf(evt.keyCode) !== -1) {
|
|
|
|
|
|
+ if (this.keysHeightOffsetIncr.indexOf(evt.keyCode) !== -1 ||
|
|
|
|
+ this.keysHeightOffsetDecr.indexOf(evt.keyCode) !== -1 ||
|
|
|
|
+ this.keysRotationOffsetIncr.indexOf(evt.keyCode) !== -1 ||
|
|
|
|
+ this.keysRotationOffsetDecr.indexOf(evt.keyCode) !== -1 ||
|
|
|
|
+ this.keysRadiusIncr.indexOf(evt.keyCode) !== -1 ||
|
|
|
|
+ this.keysRadiusDecr.indexOf(evt.keyCode) !== -1) {
|
|
var index = this._keys.indexOf(evt.keyCode);
|
|
var index = this._keys.indexOf(evt.keyCode);
|
|
|
|
|
|
if (index === -1) {
|
|
if (index === -1) {
|
|
@@ -119,12 +177,13 @@ export class FollowCameraKeyboardMoveInput implements ICameraInput<FollowCamera>
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- else {
|
|
|
|
- if (this.keysUp.indexOf(evt.keyCode) !== -1 ||
|
|
|
|
- this.keysDown.indexOf(evt.keyCode) !== -1 ||
|
|
|
|
- this.keysLeft.indexOf(evt.keyCode) !== -1 ||
|
|
|
|
- this.keysRight.indexOf(evt.keyCode) !== -1) {
|
|
|
|
|
|
+ } else {
|
|
|
|
+ if (this.keysHeightOffsetIncr.indexOf(evt.keyCode) !== -1 ||
|
|
|
|
+ this.keysHeightOffsetDecr.indexOf(evt.keyCode) !== -1 ||
|
|
|
|
+ this.keysRotationOffsetIncr.indexOf(evt.keyCode) !== -1 ||
|
|
|
|
+ this.keysRotationOffsetDecr.indexOf(evt.keyCode) !== -1 ||
|
|
|
|
+ this.keysRadiusIncr.indexOf(evt.keyCode) !== -1 ||
|
|
|
|
+ this.keysRadiusDecr.indexOf(evt.keyCode) !== -1) {
|
|
var index = this._keys.indexOf(evt.keyCode);
|
|
var index = this._keys.indexOf(evt.keyCode);
|
|
|
|
|
|
if (index >= 0) {
|
|
if (index >= 0) {
|
|
@@ -167,37 +226,34 @@ export class FollowCameraKeyboardMoveInput implements ICameraInput<FollowCamera>
|
|
*/
|
|
*/
|
|
public checkInputs(): void {
|
|
public checkInputs(): void {
|
|
if (this._onKeyboardObserver) {
|
|
if (this._onKeyboardObserver) {
|
|
- for (var index = 0; index < this._keys.length; index++) {
|
|
|
|
- var keyCode = this._keys[index];
|
|
|
|
- if (this.keysLeft.indexOf(keyCode) !== -1) {
|
|
|
|
|
|
+ this._keys.forEach((keyCode) => {
|
|
|
|
+ if (this.keysHeightOffsetIncr.indexOf(keyCode) !== -1 &&
|
|
|
|
+ this._modifierHeightOffset()) {
|
|
|
|
+ this.camera.heightOffset += this.heightSensibility;
|
|
|
|
+ } else if (this.keysHeightOffsetDecr.indexOf(keyCode) !== -1 &&
|
|
|
|
+ this._modifierHeightOffset()) {
|
|
|
|
+ this.camera.heightOffset -= this.heightSensibility;
|
|
|
|
+ } else if (this.keysRotationOffsetIncr.indexOf(keyCode) !== -1 &&
|
|
|
|
+ this._modifierRotationOffset()) {
|
|
this.camera.rotationOffset += this.rotationSensibility;
|
|
this.camera.rotationOffset += this.rotationSensibility;
|
|
this.camera.rotationOffset %= 360;
|
|
this.camera.rotationOffset %= 360;
|
|
- } else if (this.keysUp.indexOf(keyCode) !== -1) {
|
|
|
|
- if (this._altPressed) {
|
|
|
|
- this.camera.radius += this.radiusSensibility;
|
|
|
|
- } else {
|
|
|
|
- this.camera.heightOffset += this.heightSensibility;
|
|
|
|
- }
|
|
|
|
- } else if (this.keysRight.indexOf(keyCode) !== -1) {
|
|
|
|
|
|
+ } else if (this.keysRotationOffsetDecr.indexOf(keyCode) !== -1 &&
|
|
|
|
+ this._modifierRotationOffset()) {
|
|
this.camera.rotationOffset -= this.rotationSensibility;
|
|
this.camera.rotationOffset -= this.rotationSensibility;
|
|
this.camera.rotationOffset %= 360;
|
|
this.camera.rotationOffset %= 360;
|
|
- } else if (this.keysDown.indexOf(keyCode) !== -1) {
|
|
|
|
- if (this._altPressed) {
|
|
|
|
- this.camera.radius -= this.radiusSensibility;
|
|
|
|
- this.camera.radius =
|
|
|
|
- Math.max(this.minRadius, this.camera.radius);
|
|
|
|
- } else {
|
|
|
|
- this.camera.heightOffset -= this.heightSensibility;
|
|
|
|
- this.camera.heightOffset =
|
|
|
|
- Math.max(this.minHeightOffset, this.camera.heightOffset);
|
|
|
|
- }
|
|
|
|
|
|
+ } else if (this.keysRadiusIncr.indexOf(keyCode) !== -1 &&
|
|
|
|
+ this._modifierRadius()) {
|
|
|
|
+ this.camera.radius += this.radiusSensibility;
|
|
|
|
+ } else if (this.keysRadiusDecr.indexOf(keyCode) !== -1 &&
|
|
|
|
+ this._modifierRadius()) {
|
|
|
|
+ this.camera.radius -= this.radiusSensibility;
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Gets the class name of the current intput.
|
|
|
|
|
|
+ * Gets the class name of the current input.
|
|
* @returns the class name
|
|
* @returns the class name
|
|
*/
|
|
*/
|
|
public getClassName(): string {
|
|
public getClassName(): string {
|
|
@@ -211,6 +267,36 @@ export class FollowCameraKeyboardMoveInput implements ICameraInput<FollowCamera>
|
|
public getSimpleName(): string {
|
|
public getSimpleName(): string {
|
|
return "keyboard";
|
|
return "keyboard";
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Check if the pressed modifier keys (Alt/Ctrl/Shift) match those configured to
|
|
|
|
+ * allow modification of the heightOffset value.
|
|
|
|
+ */
|
|
|
|
+ private _modifierHeightOffset(): boolean {
|
|
|
|
+ return (this.keysHeightOffsetModifierAlt === this._altPressed &&
|
|
|
|
+ this.keysHeightOffsetModifierCtrl === this._ctrlPressed &&
|
|
|
|
+ this.keysHeightOffsetModifierShift === this._shiftPressed);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Check if the pressed modifier keys (Alt/Ctrl/Shift) match those configured to
|
|
|
|
+ * allow modification of the rotationOffset value.
|
|
|
|
+ */
|
|
|
|
+ private _modifierRotationOffset(): boolean {
|
|
|
|
+ return (this.keysRotationOffsetModifierAlt === this._altPressed &&
|
|
|
|
+ this.keysRotationOffsetModifierCtrl === this._ctrlPressed &&
|
|
|
|
+ this.keysRotationOffsetModifierShift === this._shiftPressed);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Check if the pressed modifier keys (Alt/Ctrl/Shift) match those configured to
|
|
|
|
+ * allow modification of the radius value.
|
|
|
|
+ */
|
|
|
|
+ private _modifierRadius(): boolean {
|
|
|
|
+ return (this.keysRadiusModifierAlt === this._altPressed &&
|
|
|
|
+ this.keysRadiusModifierCtrl === this._ctrlPressed &&
|
|
|
|
+ this.keysRadiusModifierShift === this._shiftPressed);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
(<any>CameraInputTypes)["FollowCameraKeyboardMoveInput"] = FollowCameraKeyboardMoveInput;
|
|
(<any>CameraInputTypes)["FollowCameraKeyboardMoveInput"] = FollowCameraKeyboardMoveInput;
|