Pārlūkot izejas kodu

Merge pull request #5744 from mrdunk/FollowCamera_limit_offset_ranges

Added maximum and minimum limits for FollowCamera parameters.
David Catuhe 6 gadi atpakaļ
vecāks
revīzija
6440cc64af
2 mainītis faili ar 73 papildinājumiem un 0 dzēšanām
  1. 1 0
      dist/preview release/what's new.md
  2. 72 0
      src/Cameras/followCamera.ts

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

@@ -90,6 +90,7 @@
 - Added InputsManager and keyboard bindings for FollowCamera. ([mrdunk](https://github.com))
 - Fix typo in FollowCamera InputsManager when limiting rotation to 360 degrees. ([mrdunk](https://github.com))
 - Added MouseWheel bindings for FollowCamera. ([mrdunk](https://github.com))
+- Added maximum and minimum limits for FollowCamera parameters. ([mrdunk](https://github.com))
 - Added per solid particle culling possibility : `solidParticle.isInFrustum()`  ([jerome](https://github.com/jbousquie))
 - Added transparency support to `GlowLayer` ([Sebavan](https://github.com/Sebavan))
 - Added option `forceDisposeChildren` to multiMaterial.dispose ([danjpar](https://github.com/danjpar))

+ 72 - 0
src/Cameras/followCamera.ts

@@ -28,12 +28,42 @@ export class FollowCamera extends TargetCamera {
     public radius: number = 12;
 
     /**
+     * Minimum allowed distance of the camera to the axis of rotation
+     * (The camera can not get closer).
+     * This can help limiting how the Camera is able to move in the scene.
+     */
+    @serialize()
+    public lowerRadiusLimit: Nullable<number> = null;
+
+    /**
+     * Maximum allowed distance of the camera to the axis of rotation
+     * (The camera can not get further).
+     * This can help limiting how the Camera is able to move in the scene.
+     */
+    @serialize()
+    public upperRadiusLimit: Nullable<number> = null;
+
+    /**
      * Define a rotation offset between the camera and the object it follows
      */
     @serialize()
     public rotationOffset: number = 0;
 
     /**
+     * Minimum allowed angle to camera position relative to target object.
+     * This can help limiting how the Camera is able to move in the scene.
+     */
+    @serialize()
+    public lowerRotationOffsetLimit: Nullable<number> = null;
+
+    /**
+     * Maximum allowed angle to camera position relative to target object.
+     * This can help limiting how the Camera is able to move in the scene.
+     */
+    @serialize()
+    public upperRotationOffsetLimit: Nullable<number> = null;
+
+    /**
      * Define a height offset between the camera and the object it follows.
      * It can help following an object from the top (like a car chaing a plane)
      */
@@ -41,6 +71,20 @@ export class FollowCamera extends TargetCamera {
     public heightOffset: number = 4;
 
     /**
+     * Minimum allowed height of camera position relative to target object.
+     * This can help limiting how the Camera is able to move in the scene.
+     */
+    @serialize()
+    public lowerHeightOffsetLimit: Nullable<number> = null;
+
+    /**
+     * Maximum allowed height of camera position relative to target object.
+     * This can help limiting how the Camera is able to move in the scene.
+     */
+    @serialize()
+    public upperHeightOffsetLimit: Nullable<number> = null;
+
+    /**
      * Define how fast the camera can accelerate to follow it s target.
      */
     @serialize()
@@ -150,12 +194,40 @@ export class FollowCamera extends TargetCamera {
     /** @hidden */
     public _checkInputs(): void {
         this.inputs.checkInputs();
+        this._checkLimits();
         super._checkInputs();
         if (this.lockedTarget) {
             this._follow(this.lockedTarget);
         }
     }
 
+    private _checkLimits() {
+        if (this.lowerRadiusLimit !== null && this.radius < this.lowerRadiusLimit) {
+            this.radius = this.lowerRadiusLimit;
+        }
+        if (this.upperRadiusLimit !== null && this.radius > this.upperRadiusLimit) {
+            this.radius = this.upperRadiusLimit;
+        }
+
+        if (this.lowerHeightOffsetLimit !== null &&
+            this.heightOffset < this.lowerHeightOffsetLimit) {
+            this.heightOffset = this.lowerHeightOffsetLimit;
+        }
+        if (this.upperHeightOffsetLimit !== null &&
+            this.heightOffset > this.upperHeightOffsetLimit) {
+            this.heightOffset = this.upperHeightOffsetLimit;
+        }
+
+        if (this.lowerRotationOffsetLimit !== null &&
+            this.rotationOffset < this.lowerRotationOffsetLimit) {
+            this.rotationOffset = this.lowerRotationOffsetLimit;
+        }
+        if (this.upperRotationOffsetLimit !== null &&
+            this.rotationOffset > this.upperRotationOffsetLimit) {
+            this.rotationOffset = this.upperRotationOffsetLimit;
+        }
+    }
+
     /**
      * Gets the camera class name.
      * @returns the class name