Jump to content

Rotation physicsImpostor physicsBody bug


V_1.0.0
 Share

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}
 
demo:
https://playground.babylonjs.com/indexStable.html#MARWS6#1
 
 
Link to comment
Share on other sites

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

https://playground.babylonjs.com/#MARWS6#3

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. 

Link to comment
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.

Link to comment
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.

Link to comment
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.

https://playground.babylonjs.com/#MARWS6#7

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.  :)

Link to comment
Share on other sites

Thanks Raanan!   From the PR...

// set the quaternion, ignoring the previously defined (euler) rotation
impostor.physicsBody.resetQuaternion(globalQuaternion);
// update with delta 0, so the body will receive the new rotation
impostor.physicsBody.updatePosition(0);

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!  :)

Link to comment
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?

Link to comment
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.

https://playground.babylonjs.com/#MARWS6#7

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? 

https://playground.babylonjs.com/debug.html#MARWS6#4

I show... this.BJSOIMO is undefined

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...