浏览代码

Merge pull request #4722 from RaananW/oimo-rotation

Oimo.js - forcing quaternion and not euler when creating body
David Catuhe 7 年之前
父节点
当前提交
e784913f42
共有 2 个文件被更改,包括 11 次插入3 次删除
  1. 1 0
      dist/preview release/what's new.md
  2. 10 3
      src/Physics/Plugins/babylon.oimoJSPlugin.ts

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

@@ -127,6 +127,7 @@
 - Fixed `updatable` parameter setting in the SPS ([jerome](https://github.com/jbousquie))
 - Angular and linear velocity were using the wrong method to copy values to the physics engine ([RaananW](https://github.com/RaananW))
 - Fixed env texture generation in Byte Mode ([sebavan](http://www.github.com/sebavan))
+- Oimo.js now receives quaternion and not euler when a body is being constructed ([RaananW](https://github.com/RaananW))
 
 ### Viewer
 

+ 10 - 3
src/Physics/Plugins/babylon.oimoJSPlugin.ts

@@ -122,12 +122,15 @@ module BABYLON {
                     return Math.max(value, PhysicsEngine.Epsilon);
                 }
 
+                let globalQuaternion: Quaternion = new Quaternion();
+
                 impostors.forEach((i) => {
                     if (!i.object.rotationQuaternion) {
                         return;
                     }
                     //get the correct bounding box
                     var oldQuaternion = i.object.rotationQuaternion;
+                    globalQuaternion = oldQuaternion.clone();
 
                     var rot = oldQuaternion.toEulerAngles();
                     var extendSize = i.getObjectExtendSize();
@@ -147,9 +150,9 @@ module BABYLON {
                         bodyConfig.posShape.push(0, 0, 0);
 
                         //tmp solution
-                        bodyConfig.rot.push(rot.x * radToDeg);
-                        bodyConfig.rot.push(rot.y * radToDeg);
-                        bodyConfig.rot.push(rot.z * radToDeg);
+                        bodyConfig.rot.push(0);
+                        bodyConfig.rot.push(0);
+                        bodyConfig.rot.push(0);
                         bodyConfig.rotShape.push(0, 0, 0);
                     } else {
                         let localPosition = i.object.getAbsolutePosition().subtract(impostor.object.getAbsolutePosition());
@@ -222,6 +225,10 @@ module BABYLON {
                 });
 
                 impostor.physicsBody = this.world.add(bodyConfig);
+                // set the quaternion, ignoring the previously defined (euler) rotation
+                impostor.physicsBody.resetQuaternion(globalQuaternion);
+                // update with delta 0, so the body will reveive the new rotation.
+                impostor.physicsBody.updatePosition(0);
 
             } else {
                 this._tmpPositionVector.copyFromFloats(0, 0, 0);