Prechádzať zdrojové kódy

Merge pull request #305 from daner/camera_target_offset

Added a property to ArcRotateCamera that moves the screen position of the target.
David Catuhe 10 rokov pred
rodič
commit
051e78d449

+ 25 - 0
Babylon/Animations/babylon.animation.ts

@@ -35,6 +35,10 @@
         public vector3InterpolateFunction(startValue: Vector3, endValue: Vector3, gradient: number): Vector3 {
             return BABYLON.Vector3.Lerp(startValue, endValue, gradient);
         }
+		
+		 public vector2InterpolateFunction(startValue: Vector2, endValue: Vector2, gradient: number): Vector2 {
+            return BABYLON.Vector2.Lerp(startValue, endValue, gradient);
+        }
 
         public color3InterpolateFunction(startValue: Color3, endValue: Color3, gradient: number): Color3 {
             return BABYLON.Color3.Lerp(startValue, endValue, gradient);
@@ -101,6 +105,15 @@
                                 case Animation.ANIMATIONLOOPMODE_RELATIVE:
                                     return this.vector3InterpolateFunction(startValue, endValue, gradient).add(offsetValue.scale(repeatCount));
                             }
+						// Vector2
+                        case Animation.ANIMATIONTYPE_VECTOR2:
+                            switch (loopMode) {
+                                case Animation.ANIMATIONLOOPMODE_CYCLE:
+                                case Animation.ANIMATIONLOOPMODE_CONSTANT:
+                                    return this.vector2InterpolateFunction(startValue, endValue, gradient);
+                                case Animation.ANIMATIONLOOPMODE_RELATIVE:
+                                    return this.vector2InterpolateFunction(startValue, endValue, gradient).add(offsetValue.scale(repeatCount));
+                            }
                         // Color3
                         case Animation.ANIMATIONTYPE_COLOR3:
                             switch (loopMode) {
@@ -180,6 +193,9 @@
                             // Vector3
                             case Animation.ANIMATIONTYPE_VECTOR3:
                                 this._offsetsCache[keyOffset] = toValue.subtract(fromValue);
+							// Vector2
+                            case Animation.ANIMATIONTYPE_VECTOR2:
+                                this._offsetsCache[keyOffset] = toValue.subtract(fromValue);
                             // Color3
                             case Animation.ANIMATIONTYPE_COLOR3:
                                 this._offsetsCache[keyOffset] = toValue.subtract(fromValue);
@@ -209,6 +225,10 @@
                     case Animation.ANIMATIONTYPE_VECTOR3:
                         offsetValue = Vector3.Zero();
                         break;
+					// Vector2
+                    case Animation.ANIMATIONTYPE_VECTOR2:
+                        offsetValue = Vector2.Zero();
+                        break;
                     // Color3
                     case Animation.ANIMATIONTYPE_COLOR3:
                         offsetValue = Color3.Black();
@@ -250,6 +270,7 @@
         private static _ANIMATIONTYPE_QUATERNION = 2;
         private static _ANIMATIONTYPE_MATRIX = 3;
         private static _ANIMATIONTYPE_COLOR3 = 4;
+		private static _ANIMATIONTYPE_VECTOR2 = 5;
         private static _ANIMATIONLOOPMODE_RELATIVE = 0;
         private static _ANIMATIONLOOPMODE_CYCLE = 1;
         private static _ANIMATIONLOOPMODE_CONSTANT = 2;
@@ -262,6 +283,10 @@
             return Animation._ANIMATIONTYPE_VECTOR3;
         }
 
+		public static get ANIMATIONTYPE_VECTOR2(): number {
+            return Animation._ANIMATIONTYPE_VECTOR2;
+        }
+		
         public static get ANIMATIONTYPE_QUATERNION(): number {
             return Animation._ANIMATIONTYPE_QUATERNION;
         }

+ 10 - 2
Babylon/Cameras/babylon.arcRotateCamera.ts

@@ -18,7 +18,9 @@
         public keysLeft = [37];
         public keysRight = [39];
         public zoomOnFactor = 1;
-
+		public targetScreenOffset = Vector2.Zero();
+		
+		
         private _keys = [];
         private _viewMatrix = new BABYLON.Matrix();
         private _attachedElement: HTMLElement;
@@ -78,6 +80,7 @@
             this._cache.alpha = undefined;
             this._cache.beta = undefined;
             this._cache.radius = undefined;
+			this._cache.targetScreenOffset = undefined;
         }
 
         public _updateCache(ignoreParentClass?: boolean): void {
@@ -89,6 +92,7 @@
             this._cache.alpha = this.alpha;
             this._cache.beta = this.beta;
             this._cache.radius = this.radius;
+			this._cache.targetScreenOffset = this.targetScreenOffset.clone();
         }
 
         // Synchronized
@@ -99,7 +103,8 @@
             return this._cache.target.equals(this._getTargetPosition())
                 && this._cache.alpha === this.alpha
                 && this._cache.beta === this.beta
-                && this._cache.radius === this.radius;
+                && this._cache.radius === this.radius
+				&& this._cache.targetScreenOffset.equals(this.targetScreenOffset);
         }
 
         // Methods
@@ -516,6 +521,9 @@
             this._previousRadius = this.radius;
             this._previousPosition.copyFrom(this.position);
 
+			this._viewMatrix.m[12] += this.targetScreenOffset.x;
+			this._viewMatrix.m[13] += this.targetScreenOffset.y;
+						
             return this._viewMatrix;
         }