Procházet zdrojové kódy

Adding Contact Data to physics collisions

When the physics engines find collision they create a contact object
that includes information that might be useful for the game developers.
This small change sends the contact objects ob both engines to the
onPhysicsCollide function.
Raanan Weber před 10 roky
rodič
revize
44189c6e71

+ 1 - 1
src/Mesh/babylon.abstractMesh.ts

@@ -74,7 +74,7 @@
         public _physicsMass: number;
         public _physicsMass: number;
         public _physicsFriction: number;
         public _physicsFriction: number;
         public _physicRestitution: number;
         public _physicRestitution: number;
-        public onPhysicsCollide: (collidedMesh: AbstractMesh) => void; 
+        public onPhysicsCollide: (collidedMesh: AbstractMesh, contact: any) => void; 
 
 
         // Collisions
         // Collisions
         private _checkCollisions = false;
         private _checkCollisions = false;

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

@@ -57,7 +57,7 @@
                             //find the mesh that collided with the registered mesh
                             //find the mesh that collided with the registered mesh
                             for (var idx = 0; idx < this._registeredMeshes.length; idx++) {
                             for (var idx = 0; idx < this._registeredMeshes.length; idx++) {
                                 if (this._registeredMeshes[idx].body == e.body) {
                                 if (this._registeredMeshes[idx].body == e.body) {
-                                    registeredMesh.mesh.onPhysicsCollide(this._registeredMeshes[idx].mesh);
+                                    registeredMesh.mesh.onPhysicsCollide(this._registeredMeshes[idx].mesh, e.contact);
                                 }
                                 }
                             }
                             }
                         }
                         }

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

@@ -402,7 +402,7 @@ module BABYLON {
                             //get the mesh and execute the callback
                             //get the mesh and execute the callback
                             var otherMesh = mesh.getScene().getMeshByUniqueID(otherUniqueId);
                             var otherMesh = mesh.getScene().getMeshByUniqueID(otherUniqueId);
                             if (otherMesh)
                             if (otherMesh)
-                                mesh.onPhysicsCollide(otherMesh);
+                                mesh.onPhysicsCollide(otherMesh, contact);
                         }
                         }
                         contact = contact.next;
                         contact = contact.next;
                     }
                     }