Explorar o código

Objects with their parent object now use their absolute position
This allows moving the parent object and get the transformation but yet using the physics engine with child meshes.

Raanan Weber %!s(int64=7) %!d(string=hai) anos
pai
achega
2d28b76630
Modificáronse 1 ficheiros con 13 adicións e 2 borrados
  1. 13 2
      src/Physics/babylon.physicsImpostor.ts

+ 13 - 2
src/Physics/babylon.physicsImpostor.ts

@@ -380,7 +380,13 @@ module BABYLON {
             if (!this._physicsEngine) {
                 return;
             }
-            this.object.position.subtractToRef(this._deltaPosition, this._tmpPositionWithDelta);
+
+            if (this._options.ignoreParent && this.object.parent) {
+                this._tmpPositionWithDelta.copyFrom(this.object.getAbsolutePosition());
+                //this.object.getAbsolutePosition().subtractToRef(this._deltaPosition, this._tmpPositionWithDelta);
+            } else {
+                this.object.position.subtractToRef(this._deltaPosition, this._tmpPositionWithDelta);
+            }
             //conjugate deltaRotation
             if (this.object.rotationQuaternion) {
                 if (this._deltaRotationConjugated) {
@@ -413,7 +419,12 @@ module BABYLON {
 
             this._physicsEngine.getPhysicsPlugin().setTransformationFromPhysicsBody(this);
 
-            this.object.position.addInPlace(this._deltaPosition)
+            if (this._options.ignoreParent && this.object.parent) {
+                this.object.position.subtractInPlace(this.object.parent.getAbsolutePosition());
+            } else {
+                this.object.position.addInPlace(this._deltaPosition)
+            }
+
             if (this._deltaRotation && this.object.rotationQuaternion) {
                 this.object.rotationQuaternion.multiplyInPlace(this._deltaRotation);
             }