瀏覽代碼

New ```mesh.moveWithCollisions``` function. Used with ```mesh.ellipsoid``` this function can be used to move a mesh and use an ellipsoid around it to check collisions

David Catuhe 11 年之前
父節點
當前提交
b81fdcf8ad
共有 4 個文件被更改,包括 47 次插入4 次删除
  1. 21 0
      Babylon/Mesh/babylon.abstractMesh.js
  2. 22 0
      Babylon/Mesh/babylon.abstractMesh.ts
  3. 1 1
      babylon.1.13-beta-debug.js
  4. 3 3
      babylon.1.13-beta.js

+ 21 - 0
Babylon/Mesh/babylon.abstractMesh.js

@@ -31,6 +31,12 @@ var BABYLON;
             this.layerMask = 0xFFFFFFFF;
             // Physics
             this._physicImpostor = BABYLON.PhysicsEngine.NoImpostor;
+            // Collisions
+            this.ellipsoid = new BABYLON.Vector3(0.5, 1, 0.5);
+            this._collider = new BABYLON.Collider();
+            this._oldPositionForCollisions = new BABYLON.Vector3(0, 0, 0);
+            this._diffPositionForCollisions = new BABYLON.Vector3(0, 0, 0);
+            this._newPositionForCollisions = new BABYLON.Vector3(0, 0, 0);
             // Cache
             this._localScaling = BABYLON.Matrix.Zero();
             this._localRotation = BABYLON.Matrix.Zero();
@@ -523,6 +529,21 @@ var BABYLON;
             this.getScene().getPhysicsEngine()._createLink(this, otherMesh, pivot1, pivot2);
         };
 
+        // Collisions
+        AbstractMesh.prototype.moveWithCollisions = function (velocity) {
+            var globalPosition = this.getAbsolutePosition();
+
+            globalPosition.subtractFromFloatsToRef(0, this.ellipsoid.y, 0, this._oldPositionForCollisions);
+            this._collider.radius = this.ellipsoid;
+
+            this.getScene()._getNewPosition(this._oldPositionForCollisions, velocity, this._collider, 3, this._newPositionForCollisions);
+            this._newPositionForCollisions.subtractToRef(this._oldPositionForCollisions, this._diffPositionForCollisions);
+
+            if (this._diffPositionForCollisions.length() > BABYLON.Engine.CollisionsEpsilon) {
+                this.position.addInPlace(this._diffPositionForCollisions);
+            }
+        };
+
         // Submeshes octree
         /**
         * This function will create an octree to help select the right submeshes for rendering, picking and collisions

+ 22 - 0
Babylon/Mesh/babylon.abstractMesh.ts

@@ -59,6 +59,13 @@
         public _physicsFriction: number;
         public _physicRestitution: number;
 
+        // Collisions
+        public ellipsoid = new BABYLON.Vector3(0.5, 1, 0.5);
+        private _collider = new Collider();
+        private _oldPositionForCollisions = new BABYLON.Vector3(0, 0, 0);
+        private _diffPositionForCollisions = new BABYLON.Vector3(0, 0, 0);
+        private _newPositionForCollisions = new BABYLON.Vector3(0, 0, 0);
+
         // Cache
         private _localScaling = BABYLON.Matrix.Zero();
         private _localRotation = BABYLON.Matrix.Zero();
@@ -518,6 +525,21 @@
             this.getScene().getPhysicsEngine()._createLink(this, otherMesh, pivot1, pivot2);
         }
 
+        // Collisions
+        public moveWithCollisions(velocity: Vector3): void {
+            var globalPosition = this.getAbsolutePosition();
+
+            globalPosition.subtractFromFloatsToRef(0, this.ellipsoid.y, 0, this._oldPositionForCollisions);
+            this._collider.radius = this.ellipsoid;
+
+            this.getScene()._getNewPosition(this._oldPositionForCollisions, velocity, this._collider, 3, this._newPositionForCollisions);
+            this._newPositionForCollisions.subtractToRef(this._oldPositionForCollisions, this._diffPositionForCollisions);
+
+            if (this._diffPositionForCollisions.length() > Engine.CollisionsEpsilon) {
+                this.position.addInPlace(this._diffPositionForCollisions);
+            }
+        }
+
         // Submeshes octree
 
         /**

文件差異過大導致無法顯示
+ 1 - 1
babylon.1.13-beta-debug.js


文件差異過大導致無法顯示
+ 3 - 3
babylon.1.13-beta.js