Jump to content

consecutive rotations issues


ramsestom
 Share

Recommended Posts

I need to apply a rotation around a given axis on a mesh and then another rotation around another axis (order and number of axis rotations can change depending on the user so I can't precompute it as a single transformation).

The problem is that using mesh.rotation or the mesh.rotate() function is messed up as long as you apply more than one rotation.

I made an example to show the issue:

http://babylonjs-playground.com/#A8AR6#1

If you slide mouse vertically then horizontally, you will see that the second quarter rotation is actually performed arround the z axis (that point toward the user) instead of the y one.

I guess the reason for this is that babylonjs do not actually change position of all nodes of a mesh when rotation is called but simply store a single rotation vector that would be applied at rendering. Problem is that when applying more than one rotation, these rotations are stored in the same vector and the order of these rotations is lost. But the order is important as, if you perform, on a cube for example, a rotation around X axis and then Y, you would not have the same result as if you rotate around Y first and then X...

So is there a solution to actually really apply a rotation on a mesh (changing each mech nodes positions according to this rotation) so that when applying next rotation, it would be performed correctly?

Link to comment
Share on other sites

Hi @ramsestom, welcome to the forum.  I am not competent enough to help with this, but I wanted to point to this tutorial@JohnK is a superhero helper (and darned nice guy) here on the forum, and that tutorial... was the result of JohnK having the same issue as you.  In the forum thread where he first mentioned his issues with accumulative rotation, he talked, and grappled, and debated with himself... it was gruesome.  I thought he was going to have a nervous breakdown.  But, he survived... and wrote that cool tutorial.

Now, whether or not that tutorial teaches anything... that's still in question.  But it IS a gorgeous tutorial and great care was taken to cover all the issues... as best I can tell.  The "spaces" part is quite important.  mesh.rotate() can use world space or local space.  Have you done comparisons of the two?

Another interesting thing... our mesh rotations begin as pure Euler vector3's.  But certain operations such as physics, using yawpitchroll rotations, and using mesh.rotate()... cause a .rotationQuaternion to be created for the mesh.

Take a look at this version of your playground.  In line 31, I log the mesh.rotationQuaternion.  It's undefined.

In line 51, after your rotate(), I do it again.  There it is.  Do you know about Quaternion rotation orders, or ANYTHING about Quaternions?  If you do, you are rare and probably a genius.  :D  They scare me.  But maybe for you... it will help you understand what the heck is happening.  :)  Generally speaking, users rarely need to be concerned about the Quaternion that activates behind the scenes.  In spacecraft (and mesh) operations, they are used to avoid a rotational issue called "gimbal lock" which happens when rotations are done near mesh poles.  (bad description from me, sorry.  check web)

A quick note:  Most people call them "verts" instead of "nodes", around here.  It is probably because BJS uses a "node" as the base class for scene items.  Nodes/Verts, both work for me, but if you use verts / vertices / vertex... then more readers will understand. 

Vertex transformations.  Matricies.  blech.  :)  Want to see something strange that might help you?  I knew ya did.

mesh.rotation.y = Math.PI/4;  // spin the mesh a bit
mesh.bakeCurrentTransformIntoVertices();  // vertices transform!  yay!
mesh.rotation.y = -Math.PI/4;  // return mesh to original rot... with verts transformed.

Strange, huh?  But it might be a helpful tool for you.

Ok, let's leave it there, because I have nothing more to say (rare for me).  I think others will comment, too.  I wish I could be more helpful, but I am a forever-noob.  It is because my brain is full (it has only tiny capacity), and every time I learn something new, I forget something old.  :)  Be well, talk soon.
 

Link to comment
Share on other sites

The solution is just to switch from Space.LOCAL to Space.WORLD

The Haxe babylon port I use (babylonHX) was actually having an error when using the rotate function with WORLD Space, so this is why I did not obtained the expected result (I forgot to test with Space.WORD in babylonjs playground before posting the issue here). Testing it with babylonjs allowed me to detect this bug though and this should now be fixed in babylonHx :).

Thanks for your help.

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