digEmAll Posted January 16, 2016 Share Posted January 16, 2016 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. Quote Link to comment Share on other sites More sharing options...
ChrisR Posted January 16, 2016 Share Posted January 16, 2016 Use the Rotate function, it allows you to rotate around a space. Take a look: http://babylonjs-playground.com/#NJJPP#1 Quote Link to comment Share on other sites More sharing options...
digEmAll Posted January 17, 2016 Author Share Posted January 17, 2016 1 hour ago, ChrisR said: Use the Rotate function, it allows you to rotate around a space. Take a look: http://babylonjs-playground.com/#NJJPP#1 That's great! But... is it possible to use it in animations ? Quote Link to comment Share on other sites More sharing options...
ChrisR Posted January 17, 2016 Share Posted January 17, 2016 Like this? http://babylonjs-playground.com/#NJJPP#6 Quote Link to comment Share on other sites More sharing options...
Asor Posted January 17, 2016 Share Posted January 17, 2016 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. Quote Link to comment Share on other sites More sharing options...
jerome Posted January 17, 2016 Share Posted January 17, 2016 All the BJS rotations are converted into Quaternions under the hood. Quote Link to comment Share on other sites More sharing options...
digEmAll Posted January 17, 2016 Author Share Posted January 17, 2016 9 hours ago, ChrisR said: Like this? http://babylonjs-playground.com/#NJJPP#6 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 GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.