Jump to content

issues with toEulerAngles


pichou
 Share

Recommended Posts

Hello everybody! Hope everyone is going well in the Babylon community ! ;)

My issue is simple :
I use the mesh.rotate() function in order to rotate a mesh in the BABYLON.Space.WORLD.
The function works great and my mesh rotate exactly how I want.

The mesh.rotate() function use quaternion and so the rotation attribute is set to Vector0.
But when the rotation is hover I would like to have the euler rotation back!
To do so I use the mesh.rotationQuaternion.toEulerAngles() function
But if I set the mesh.rotation = mesh.rotationQuaternion.toEulerAngles();
Then the mesh is rotating again on my screen like if the euler angles I get from the quaternion wasn't right.

There is a lot of topics in this forum concerning this toEulerAngles function but after hours of reading and testing (even changing ZYX, YXZ orders), nothing is working!

Is there an other way to get the euler rotation vector back from the quaternion? Or maybe a simplier way to rotate mesh around a world axis?

Thanks for your help! ;)

Link to comment
Share on other sites

Whenever the rotationQuaternion is set for a mesh then rotation values are ignored and  setting a value for mesh.rotation will have unpredictable results. So set a variable to mesh. rotationQuaternion.toEulerAngles() , null the rotationQuaternion and then set the rotation to the stored value.

See the difference when you comment out line 48 is http://www.babylonjs-playground.com/#1ST43U#77

Link to comment
Share on other sites

I speculate that mesh's rotation state is held in either mesh.rotation or mesh.rotationQuaternion.

mesh.rotate source

Apparently the first use of mesh.rotate() creates mesh.rotationQuaternion to hold the rotation state. Then mesh.rotation is no longer valid.

So now ALL rotations must be done with mesh.rotate() and reading rotation must be done with mesh.rotationQuaternion.toEulerAngles().

If this is true, why doesn't the rendering engine now ignore mesh.rotation?

So when you mesh.rotate(a,b,c) and then mesh.rotation =  mesh.rotationQuaternion.toEulerAngles(), maybe you are getting a double rotation effect. (?)

Possible work-a-round: mesh.rotate(a/2, b/2, c/2) and then mesh.rotation =  mesh.rotationQuaternion.toEulerAngles(). (?)

Good luck! ☘️

Edit: Oops! JohnK posted as I was writing this.

Edited by coolroar
JohnK might have made my post mute!
Link to comment
Share on other sites

I have a program that makes several quaternion function calls per engine.runRenderLoop().

See it here:

 

It runs smoothly (60 fps) on my machine (an older e-machines (AMD Athlon II X2 235e 2.7GHz, Radeon RX460 card).

How about googling "babylonjs profiling"?

Good luck with your app!  ?

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