Selaa lähdekoodia

Fixing extendSize problem

Resetting the rotation and calculating the extendSizeWorld allows the
physics engine to have the right size, and then apply the rotation
afterwards.
Raanan Weber 8 vuotta sitten
vanhempi
commit
3e4c6dddb2
1 muutettua tiedostoa jossa 14 lisäystä ja 1 poistoa
  1. 14 1
      src/Physics/babylon.physicsImpostor.ts

+ 14 - 1
src/Physics/babylon.physicsImpostor.ts

@@ -15,6 +15,7 @@ module BABYLON {
         parent?: any;
         parent?: any;
         getBoundingInfo?(): BoundingInfo;
         getBoundingInfo?(): BoundingInfo;
         computeWorldMatrix?(force: boolean): void;
         computeWorldMatrix?(force: boolean): void;
+        getWorldMatrix?(): Matrix;
         getChildMeshes?(): Array<AbstractMesh>;
         getChildMeshes?(): Array<AbstractMesh>;
         getVerticesData?(kind: string): Array<number> | Float32Array;
         getVerticesData?(kind: string): Array<number> | Float32Array;
         getIndices?(): IndicesArray;
         getIndices?(): IndicesArray;
@@ -25,6 +26,8 @@ module BABYLON {
 
 
         public static DEFAULT_OBJECT_SIZE: Vector3 = new BABYLON.Vector3(1, 1, 1);
         public static DEFAULT_OBJECT_SIZE: Vector3 = new BABYLON.Vector3(1, 1, 1);
 
 
+        public static IDENTITY_QUATERNION = Quaternion.Identity();
+
         private _physicsEngine: PhysicsEngine;
         private _physicsEngine: PhysicsEngine;
         //The native cannon/oimo/energy physics body object.
         //The native cannon/oimo/energy physics body object.
         private _physicsBody: any;
         private _physicsBody: any;
@@ -168,8 +171,18 @@ module BABYLON {
 
 
         public getObjectExtendSize(): Vector3 {
         public getObjectExtendSize(): Vector3 {
             if (this.object.getBoundingInfo) {
             if (this.object.getBoundingInfo) {
+                let q = this.object.rotationQuaternion;
+                //reset rotation
+                this.object.rotationQuaternion = PhysicsImpostor.IDENTITY_QUATERNION;
+                //calculate the world matrix with no rotation
+                this.object.computeWorldMatrix && this.object.computeWorldMatrix(true);
+                let size = this.object.getBoundingInfo().boundingBox.extendSizeWorld.scale(2)
+                //bring back the rotation
+                this.object.rotationQuaternion = q;
+                //calculate the world matrix with the new rotation
                 this.object.computeWorldMatrix && this.object.computeWorldMatrix(true);
                 this.object.computeWorldMatrix && this.object.computeWorldMatrix(true);
-                return this.object.getBoundingInfo().boundingBox.extendSizeWorld.scale(2);
+
+                return size;
             } else {
             } else {
                 return PhysicsImpostor.DEFAULT_OBJECT_SIZE;
                 return PhysicsImpostor.DEFAULT_OBJECT_SIZE;
             }
             }