Rotation physicsImpostor physicsBody bug

Recommended Posts

I have 2 objects:
1) with physics
2) without physics

I rotate both objects on:
mesh_impostor.rotate (new BABYLON.Vector3 (0, 1, 0), Math.PI + Math.PI / 2);
mesh_impostor.rotate (new BABYLON.Vector3 (1, 0, 0), Math.PI / 3);

and I get a different result:

rotationQuaternion:                                        {x: -0.3535533905932737, y: 0.6123724356957946,  z: -0.35355339059327373, w: -0.6123724356957945}
physicsImpostor.physicsBody.orientation {x: 0.3535533905932736,  y: -0.6123724356957946, z: -0.3535533905932737,   w: 0.6123724356957945}

Share this post

Link to post
Share on other sites

Hi again.  A bit more help for Raanan and the pros... perhaps.


There... is the same playground again...  Oimo active, and I have inserted a "bootleg" Oimo plugin into the playground.

The Oimo plugin code you are seeing... is ALMOST the same as what is installed in core... but it adds/honors the "belongsTo" and "collidesWith" parameters... two parameters not normally addressed by our current Oimo plugin.  Not important (except for making human leg joints).

In that #3 playground above... look at the aligned shapes.  Look at the MATCHING numbers at console.  How was this done?

(Okay, okay, the SIGN of the 'w' or 's' value doesn't always match in the 2 console reports.  I'm not sure if that matters.  The x/y/z values and signs are perfect, though.)

Within line 64's generatePhysicsBody() function... check out lines 115 and 116.  Line 115 is the original, line 116 is modified.  I added .negate()

I just bet... some work/mods (sort-of-) recently happened... on the Quaternion.toEulerAngles() function.  .toEulerAngles() is one of those "slippery" functions... where every 45 days, somebody re-designs it.  :D  

Ok, I don't know if anything useful got done here, but this might "heat-up the trail" to the actual problem. 

Share this post

Link to post
Share on other sites

Forgive me, but it's quite difficult for me, I can not solve this task myself. Oimo.js and babylon.js (v3.2.0 and v3.3.0-alpha.9) have this problem. I found the old version v3.2.0-alpha7 (null engine) on which everything worked correctly for my project  and I will use it.

Share this post

Link to post
Share on other sites

Yeah, no problems, v100... we'll figure this out.  Thanks again for the report/find. 

My previous post was for helping other troubleshooters find the issue quicker.

For fun, it might be interesting to compare Quaternion.toEulerAngles() code... across all 3 of those BJS versions.  See if you see differences.

Okay, that might NOT be fun.  heh.

Try to be patient.... we'll get this updated soon.  I'm glad you found a work-around... good job on that.

Share this post

Link to post
Share on other sites

Hi.  Does anyone have any (change-of) status reports, on this?   Get the BJSOIMO issue first?  Work-in-progress?  (thx)

Update:  Not sure if helpful, but I assembled a playground with ALL THREE applicable physics classes... into the playground code, gathered from the latest BJS distribution.  All three are active in this PG.


PhysicsEngine, physicsImpostor, and OimoJSPlugin classes... all on-board, ready for experimenting.  All are VERY fresh and default.

Some reports are going to console, reporting the problem.  An unwanted difference in signs... for some of the values in the last two reported lines.

The problem:  After physicsImpostor is added to mesh (lines 1201+ area)...

...physics_mesh.rotationQuaternion (a BJS Quat class) does NOT match physics_mesh.physicsImpostor.physicsBody.orientation (an OimoJS Quat class, likely)

It should, I suspect.  The act-of adding the physics impostor.... rotated the mesh.  It should not do that.  :) 

Not only boxImpostor.  Same problem if/when sphereImpostor is chosen.  Wingnut-tested.

I think issue might be in lines 126-130 area, or nearby.  Line 126 is not MY comment.  Another coder, likely rahhhh-nin  :)

Lines 187 and 189 are points of interest, too.

All assistance welcome, all ideas welcome, all play welcome.  :)

Share this post

Link to post
Share on other sites

Thanks Raanan!   From the PR...

// set the quaternion, ignoring the previously defined (euler) rotation
// update with delta 0, so the body will receive the new rotation

That's cool!  Last line... sync the shape with the impostor... with a 0 timeStep (do it now). 

Perhaps the Oimo author SHOULD have made two update functions, one for position and one for orientation [rotation].

Instead, the Oimo updatePosition() func syncs/updates both position AND orientation.

Sweet fix and good learning opportunity for all of us.  Well done!  Raanan gets free drinks for the next 24 hours!  :)

Share this post

Link to post
Share on other sites

Oimo is not that quick in accepting fixes (see - https://github.com/lo-th/Oimo.js/pull/70 from March). So, this is the best way to do it :)

updatePosition with 0 delta means 0 ms passed, but - please update the body's position and rotation. It is not needed if the body has a mass, but a mass - 0 means the body is technically sleeping and doesn't have its position updated.

What drinks do I get?

Share this post

Link to post
Share on other sites

*nod*  Your choice on drinks, but... no gold malts or diamond soup, eh?  Just send bill to BJS Forum Comptroller.  :)

I'm wondering if the new build was done or if the PG "latest" was updated.


I still see the issue.   (after I cleared history and did unconditional reloads).


@RaananW/others... do you have any information about @adam's debug error? 


I show... this.BJSOIMO is undefined

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.