digEmAll

How to set mesh.rotation correctly after a previous rotation

Recommended Posts

Hi All,

I'm facing a problem with rotations of boxes.

Basically I need to rotate a cube by 90° around the system axes, but I noticed that when a box has a rotation set, say on x axis, if you set a rotation on z, actually you're rotating the mesh around the global system Y axis.

Does rotation property refer to a coordinate system that is "local" to the mesh ?

How can I calculate the correct x,y,z rotation with respect to the global axes ?

Thanks in advance

 

P.S.

I have created a simple playground for this: http://babylonjs-playground.com/#NJJPP#0

If you click once on "rotat.around x" then when you click "rotat.around.z" (more than one time to notice the rotation) you will get a rotation around global Y axis.

But if you only click on the same button multiple times (refreshing the page to reinitialize when you decide to change the button) the rotations are performed around the right axis.

 

Share this post


Link to post
Share on other sites

The example with yaw pitch and roll should work fine, but if you notice it taking strange paths to your final rotation, consider using quarternions. You can actually get something similar to gimbal lock with Euler rotations (yaw pitch roll).

example http://around-the-corner.typepad.com/.a/6a0163057a21c8970d017743e0b713970d-pi 

This is an example of someone using quarternions in lue if euler rotation in BABYLON 

http://www.babylonjs-playground.com/#2JTOXN#1 

It may not be necessary though, some 3d programs only use quarternions and just lie about it by input/output them as euler rotations. BABYLON may be one of those programs, i'm not sure. I also have no idea how the math behind them works, thankfully you don't need to in order to make use of them.

 

Share this post


Link to post
Share on other sites

 

9 hours ago, ChrisR said:

This works because rotations are by 180°, if you change it to 90° the problem remains ;)

 

5 hours ago, Asor said:

The example with yaw pitch and roll should work fine, but if you notice it taking strange paths to your final rotation, consider using quarternions. You can actually get something similar to gimbal lock with Euler rotations (yaw pitch roll).

example http://around-the-corner.typepad.com/.a/6a0163057a21c8970d017743e0b713970d-pi 

This is an example of someone using quarternions in lue if euler rotation in BABYLON 

http://www.babylonjs-playground.com/#2JTOXN#1 

It may not be necessary though, some 3d programs only use quarternions and just lie about it by input/output them as euler rotations. BABYLON may be one of those programs, i'm not sure. I also have no idea how the math behind them works, thankfully you don't need to in order to make use of them.

 

Thanks, I used your suggestion to use quaternion and I copied the necessary code bit from Mesh.rotate, obtaining this (the desired behavior) :

http://babylonjs-playground.com/#NJJPP#7

 

Thanks to all :)

Share this post


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

  • Recently Browsing   0 members

    No registered users viewing this page.