Browse Source

Merge pull request #385 from Palmer-JC/master

Added POV movement & rotation
David Catuhe 10 năm trước cách đây
mục cha
commit
b679942f8f
2 tập tin đã thay đổi với 58 bổ sung3 xóa
  1. 56 1
      Babylon/Mesh/babylon.abstractMesh.ts
  2. 2 2
      Tools/Gulp/gulpfile.js

+ 56 - 1
Babylon/Mesh/babylon.abstractMesh.ts

@@ -28,6 +28,7 @@
         }
 
         // Properties
+        public definedFacingForward = true; // orientation for POV movement & rotation
         public position = new Vector3(0, 0, 0);
         public rotation = new Vector3(0, 0, 0);
         public rotationQuaternion: Quaternion;
@@ -252,7 +253,61 @@
                 this.position.z = absolutePositionZ;
             }
         }
-
+        // ================================== Point of View Movement =================================
+        /**
+         * Perform relative position change from the point of view of behind the front of the mesh.
+         * This is performed taking into account the meshes current rotation, so you do not have to care.
+         * Supports definition of mesh facing forward or backward.
+         * @param {number} amountRight
+         * @param {number} amountUp
+         * @param {number} amountForward
+         */
+        public movePOV(amountRight : number, amountUp : number, amountForward : number) : void {
+            this.position.addInPlace(this.calcMovePOV(amountRight, amountUp, amountForward));
+        }
+        
+        /**
+         * Calculate relative position change from the point of view of behind the front of the mesh.
+         * This is performed taking into account the meshes current rotation, so you do not have to care.
+         * Supports definition of mesh facing forward or backward.
+         * @param {number} amountRight
+         * @param {number} amountUp
+         * @param {number} amountForward
+         */
+        public calcMovePOV(amountRight : number, amountUp : number, amountForward : number) : BABYLON.Vector3 {
+            var rotMatrix = new BABYLON.Matrix();
+            var rotQuaternion = (this.rotationQuaternion) ? this.rotationQuaternion : BABYLON.Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z);
+            rotQuaternion.toRotationMatrix(rotMatrix);
+            
+            var translationDelta = BABYLON.Vector3.Zero();
+            var defForwardMult = this.definedFacingForward ? -1 : 1;
+            BABYLON.Vector3.TransformCoordinatesFromFloatsToRef(amountRight * defForwardMult, amountUp, amountForward * defForwardMult, rotMatrix, translationDelta);
+            return translationDelta;
+        }
+        // ================================== Point of View Rotation =================================
+        /**
+         * Perform relative rotation change from the point of view of behind the front of the mesh.
+         * Supports definition of mesh facing forward or backward.
+         * @param {number} flipBack
+         * @param {number} twirlClockwise
+         * @param {number} tiltRight
+         */
+        public rotatePOV(flipBack : number, twirlClockwise : number, tiltRight : number) : void {
+            this.rotation.addInPlace(this.calcRotatePOV(flipBack, twirlClockwise, tiltRight));
+        }
+        
+        /**
+         * Calculate relative rotation change from the point of view of behind the front of the mesh.
+         * Supports definition of mesh facing forward or backward.
+         * @param {number} flipBack
+         * @param {number} twirlClockwise
+         * @param {number} tiltRight
+         */
+        public calcRotatePOV(flipBack : number, twirlClockwise : number, tiltRight : number) : BABYLON.Vector3 {
+            var defForwardMult = this.definedFacingForward ? 1 : -1;
+            return new BABYLON.Vector3(flipBack * defForwardMult, twirlClockwise, tiltRight * defForwardMult);
+        }
+        
         public setPivotMatrix(matrix: Matrix): void {
             this._pivotMatrix = matrix;
             this._cache.pivotMatrixUpdated = true;

+ 2 - 2
Tools/Gulp/gulpfile.js

@@ -22,7 +22,7 @@ gulp.task('shaders', function() {
  */
 gulp.task('typescript-to-js', function() {
   //Compile all ts file into their respective js file.
-  return gulp.src(['../../References/**/*.ts', '../../Babylon/**/*.ts'])
+  return gulp.src(['../../Babylon/**/*.ts','../../References/**/*.d.ts'])
     .pipe(typescript({ target: 'ES5', sourcemap: true }))
     .pipe(gulp.dest('../../Babylon/'));
 });
@@ -33,7 +33,7 @@ gulp.task('typescript-to-js', function() {
 gulp.task('typescript-declaration', function() {
   var declarationFilter = gulpFilter('**/*.d.ts');
 
-  return gulp.src(['../../References/**/*.ts', '../../Babylon/**/*.ts'])
+  return gulp.src(['../../Babylon/**/*.ts','../../References/**/*.d.ts'])
     .pipe(typescript({ target: 'ES5', declaration: true, out: 'tmp.js' }))
     .pipe(declarationFilter)
     .pipe(rename('babylon.d.ts'))