浏览代码

Merge pull request #7779 from Pheater/UpwardsDownwards-input-for-FreeCamera

upwards and downwards keyboard input to FreeCamera
mergify[bot] 5 年之前
父节点
当前提交
d8cd4e6506
共有 3 个文件被更改,包括 61 次插入2 次删除
  1. 1 0
      dist/preview release/what's new.md
  2. 22 2
      src/Cameras/Inputs/freeCameraKeyboardMoveInput.ts
  3. 38 0
      src/Cameras/freeCamera.ts

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

@@ -23,6 +23,7 @@
 ### Cameras
 
 - Added flag to TargetCamera to invert rotation direction and multiplier to adjust speed ([Exolun](https://github.com/Exolun))
+- Added upwards and downwards keyboard input to `FreeCamera` ([Pheater](https://github.com/pheater))
 
 ### Physics
 

+ 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.
      */