Sfoglia il codice sorgente

Merge pull request #3498 from RaananW/physics-with-scaling

Scaling was missing from deltaPosition calculation
David Catuhe 7 anni fa
parent
commit
ce74dc4579

+ 25 - 0
src/Math/babylon.math.ts

@@ -762,6 +762,15 @@
             result.y = this.y / otherVector.y;
             return this;
         }
+
+        /**
+         * Divides the current Vector3 coordinates by the passed ones.  
+         * Returns the updated Vector3.  
+         */
+        public divideInPlace(otherVector: Vector2): Vector2 {
+            return this.divideToRef(otherVector, this);
+        }
+
         /**
          * Returns a new Vector2 with current Vector2 negated coordinates.  
          */
@@ -1290,6 +1299,14 @@
         }
 
         /**
+         * Divides the current Vector3 coordinates by the passed ones.  
+         * Returns the updated Vector3.  
+         */
+        public divideInPlace(otherVector: Vector3): Vector3 {
+            return this.divideToRef(otherVector, this);
+        }
+
+        /**
          * Updates the current Vector3 with the minimal coordinate values between its and the passed vector ones.  
          * Returns the updated Vector3.  
          */
@@ -2104,6 +2121,14 @@
         }
 
         /**
+         * Divides the current Vector3 coordinates by the passed ones.  
+         * Returns the updated Vector3.  
+         */
+        public divideInPlace(otherVector: Vector4): Vector4 {
+            return this.divideToRef(otherVector, this);
+        }
+
+        /**
          * Updates the Vector4 coordinates with the minimum values between its own and the passed vector ones.  
          */
         public MinimizeInPlace(other: Vector4): Vector4 {

+ 1 - 0
src/Physics/Plugins/babylon.cannonJSPlugin.ts

@@ -402,6 +402,7 @@
             var center = impostor.getObjectCenter();
             //m.getAbsolutePosition().subtract(m.getBoundingInfo().boundingBox.centerWorld)
             this._tmpDeltaPosition.copyFrom(object.getAbsolutePivotPoint().subtract(center));
+            this._tmpDeltaPosition.divideInPlace(impostor.object.scaling);
             this._tmpPosition.copyFrom(center);
             var quaternion = object.rotationQuaternion;
 

+ 2 - 1
src/Physics/Plugins/babylon.oimoJSPlugin.ts

@@ -138,7 +138,8 @@ module BABYLON {
                     if (i === impostor) {
                         var center = impostor.getObjectCenter();
 
-                        impostor.object.position.subtractToRef(center, this._tmpPositionVector);
+                        impostor.object.getAbsolutePivotPoint().subtractToRef(center, this._tmpPositionVector);
+                        this._tmpPositionVector.divideInPlace(impostor.object.scaling);
 
                         //Can also use Array.prototype.push.apply
                         bodyConfig.pos.push(center.x);