Explorar o código

Merge pull request #7906 from CedricGuillemet/ammojsRelImpulse

impulse and force applied relative to center of mass
David Catuhe %!s(int64=5) %!d(string=hai) anos
pai
achega
9f658ac698
Modificáronse 2 ficheiros con 5 adicións e 9 borrados
  1. 1 0
      dist/preview release/what's new.md
  2. 4 9
      src/Physics/Plugins/ammoJSPlugin.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -89,6 +89,7 @@
 - Fix bug in `Plane.transform` when matrix passed in is not a pure rotation ([Popov72](https://github.com/Popov72)
 - Fix bug in PBR when anisotropy is enabled and no bump texture is provided ([Popov72](https://github.com/Popov72)
 - Fix horizon occlusion in PBR materials ([Popov72](https://github.com/Popov72)
+- Fix wrong relative position in applyImpulse/applyForce for ammojs plugin ([cedricguillemet](https://github.com/cedricguillemet))
 - Fixed delay calculation in Animatable.goToFrame when speedRatio != 1 ([Reimund Järnfors](https://github.com/reimund)
 - Fix bug in PBR when translucency is enabled and an irradiance texture is provided ([Popov72](https://github.com/Popov72)
 - Fix bug in PBR with translucency when irradiance texture is 2D ([Popov72](https://github.com/Popov72)

+ 4 - 9
src/Physics/Plugins/ammoJSPlugin.ts

@@ -328,7 +328,6 @@ export class AmmoJSPlugin implements IPhysicsEnginePlugin {
         vertex_data.applyToMesh(<Mesh>object);
     }
 
-    private _tmpVector = new Vector3();
     private _tmpMatrix = new Matrix();
     /**
      * Applies an impulse on the imposter
@@ -342,11 +341,9 @@ export class AmmoJSPlugin implements IPhysicsEnginePlugin {
             var worldPoint = this._tmpAmmoVectorA;
             var impulse = this._tmpAmmoVectorB;
 
-            // Convert contactPoint into world space
+            // Convert contactPoint relative to center of mass
             if (impostor.object && impostor.object.getWorldMatrix) {
-                impostor.object.getWorldMatrix().invertToRef(this._tmpMatrix);
-                Vector3.TransformCoordinatesToRef(contactPoint, this._tmpMatrix, this._tmpVector);
-                contactPoint = this._tmpVector;
+                contactPoint.subtractInPlace(impostor.object.getWorldMatrix().getTranslation());
             }
 
             worldPoint.setValue(contactPoint.x, contactPoint.y, contactPoint.z);
@@ -371,11 +368,9 @@ export class AmmoJSPlugin implements IPhysicsEnginePlugin {
             var worldPoint = this._tmpAmmoVectorA;
             var impulse = this._tmpAmmoVectorB;
 
-            // Convert contactPoint into world space
+            // Convert contactPoint relative to center of mass
             if (impostor.object && impostor.object.getWorldMatrix) {
-                impostor.object.getWorldMatrix().invertToRef(this._tmpMatrix);
-                Vector3.TransformCoordinatesToRef(contactPoint, this._tmpMatrix, this._tmpVector);
-                contactPoint = this._tmpVector;
+                contactPoint.subtractInPlace(impostor.object.getWorldMatrix().getTranslation());
             }
 
             worldPoint.setValue(contactPoint.x, contactPoint.y, contactPoint.z);