Browse Source

upwards and downwards keyboard input to FreeCamera

Petter 5 years ago
parent
commit
5915cb6a63
3 changed files with 61 additions and 2 deletions
  1. 1 0
      dist/what's new.md
  2. 22 2
      src/Cameras/Inputs/freeCameraKeyboardMoveInput.ts
  3. 38 0
      src/Cameras/freeCamera.ts

+ 1 - 0
dist/what's new.md

@@ -61,6 +61,7 @@
 - Supports clip planes with shadows ([sebavan](http://www.github.com/sebavan))
 - Added Workbench color scheme for VSCode ([drigax](https://github.com/drigax) & [Patrick Ryan](https://github.com/PatrickRyanMS))
 - Playground switch buttons are more intuitive ([#7601](https://github.com/BabylonJS/Babylon.js/issues/7601)) ([RaananW](https://github.com/RaananW/))
+- Added upwards and downwards keyboard input to `FreeCamera` ([Pheater](https://github.com/pheater))
 
 ### Engine
 

+ 22 - 2
src/Cameras/Inputs/freeCameraKeyboardMoveInput.ts

@@ -24,12 +24,24 @@ export class FreeCameraKeyboardMoveInput implements ICameraInput<FreeCamera> {
     public keysUp = [38];
 
     /**
+     * Gets or Set the list of keyboard keys used to control the upward move of the camera.
+     */
+    @serialize()
+    public keysUpward = [33];
+
+    /**
      * Gets or Set the list of keyboard keys used to control the backward move of the camera.
      */
     @serialize()
     public keysDown = [40];
 
     /**
+     * Gets or Set the list of keyboard keys used to control the downward move of the camera.
+     */
+    @serialize()
+    public keysDownward = [34];
+
+    /**
      * Gets or Set the list of keyboard keys used to control the left strafe move of the camera.
      */
     @serialize()
@@ -71,7 +83,9 @@ export class FreeCameraKeyboardMoveInput implements ICameraInput<FreeCamera> {
                     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) {
+                        this.keysRight.indexOf(evt.keyCode) !== -1 ||
+                        this.keysUpward.indexOf(evt.keyCode) !== -1 ||
+                        this.keysDownward.indexOf(evt.keyCode) !== -1) {
                         var index = this._keys.indexOf(evt.keyCode);
 
                         if (index === -1) {
@@ -85,7 +99,9 @@ export class FreeCameraKeyboardMoveInput implements ICameraInput<FreeCamera> {
                     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) {
+                        this.keysRight.indexOf(evt.keyCode) !== -1 ||
+                        this.keysUpward.indexOf(evt.keyCode) !== -1 ||
+                        this.keysDownward.indexOf(evt.keyCode) !== -1) {
                         var index = this._keys.indexOf(evt.keyCode);
 
                         if (index >= 0) {
@@ -139,6 +155,10 @@ export class FreeCameraKeyboardMoveInput implements ICameraInput<FreeCamera> {
                     camera._localDirection.copyFromFloats(speed, 0, 0);
                 } else if (this.keysDown.indexOf(keyCode) !== -1) {
                     camera._localDirection.copyFromFloats(0, 0, -speed);
+                } else if (this.keysUpward.indexOf(keyCode) !== -1) {
+                    camera._localDirection.copyFromFloats(0, speed, 0);
+                } else if (this.keysDownward.indexOf(keyCode) !== -1) {
+                    camera._localDirection.copyFromFloats(0, -speed, 0);
                 }
 
                 if (camera.getScene().useRightHandedSystem) {

+ 38 - 0
src/Cameras/freeCamera.ts

@@ -94,6 +94,25 @@ export class FreeCamera extends TargetCamera {
     }
 
     /**
+     * Gets or Set the list of keyboard keys used to control the upward move of the camera.
+     */
+    public get keysUpward(): number[] {
+        var keyboard = <FreeCameraKeyboardMoveInput>this.inputs.attached["keyboard"];
+        if (keyboard) {
+            return keyboard.keysUpward;
+        }
+
+        return [];
+    }
+
+    public set keysUpward(value: number[]) {
+        var keyboard = <FreeCameraKeyboardMoveInput>this.inputs.attached["keyboard"];
+        if (keyboard) {
+            keyboard.keysUpward = value;
+        }
+    }
+
+    /**
      * Gets or Set the list of keyboard keys used to control the backward move of the camera.
      */
     public get keysDown(): number[] {
@@ -112,6 +131,25 @@ export class FreeCamera extends TargetCamera {
         }
     }
 
+     /**
+     * Gets or Set the list of keyboard keys used to control the downward move of the camera.
+     */
+    public get keysDownward(): number[] {
+        var keyboard = <FreeCameraKeyboardMoveInput>this.inputs.attached["keyboard"];
+        if (keyboard) {
+            return keyboard.keysDownward;
+        }
+
+        return [];
+    }
+
+    public set keysDownward(value: number[]) {
+        var keyboard = <FreeCameraKeyboardMoveInput>this.inputs.attached["keyboard"];
+        if (keyboard) {
+            keyboard.keysDownward = value;
+        }
+    }
+
     /**
      * Gets or Set the list of keyboard keys used to control the left strafe move of the camera.
      */