JohnK Posted November 1, 2016 Share Posted November 1, 2016 It seems that from BJS2.3 to BJS2.4 to BJS2.5 the function toEulerAngles when applied to a quaternion has been reinterpreted and changed. The confusion has probably arisen because there can be many interpretations of Euler Angles and how they are applied. In BJS2.3 the toEulerAngles function was - given an orientation in quaternion form supply the Euler Angles that can be applied using the ZXZ convention to produce the same rotation. In BJS2.5 the function toEulerAngles is - given an orientation in quaternion form supply the Euler Angles in the order x, y, z that can be used as parameters for mesh.rotation In BJS2.4 I can see the reasoning was to add potentially more conventions but work with the same intention as for BJ2.3. In other words I think the intention for BJS2.3 and BJS2.4, in a limited way, was knowing an orientation through a quaternion, then for any given convention quaternion.toEulerAngles(convention) would return the alpha, beta, gamma to be used for that convention to produce the same rotation, ie an inverse function EULER-->QUATERNION, CONVENTION-->EULER. In BJS2.5 knowing an orientation through a quaternion, then quaternion.toEulerAngles() returns three angles to be plugged into mesh.rotation ie EULER-->QUATERNION-->NEW EULER ANGLES FOR CONVENTION ZXY in order x, y, z My questions are - Is the interpetation used in BJS2.5 the one wanted? IMHO the answer is yes it is probably what most people expect, though the original author will, I expect, not agree? Any breaking changes issues that anyone is worried about? Anybody require the inverse type interpretation as of 2.3 and 2.4 (if so new additional functions will be necessary) If 1 and not 2 then I would drop the order parameter entirely and make sure that in the documentation for the classes BJS2.5 toEulerAngles and toEulerAnglesToRef it is clear that the intention is to return three Euler Angles that can be plugged into mesh.rotation. @adam you may like to consider the above as I believe you PRd the changes for BJS2.5 More words for those who wish to read further. In BJS mesh.rotation uses one particular interpretation which is - for three "Euler Angles" alpha, beta and gamma with alpha about axis x, beta about axis y and gamma about axis z then mesh.rotation = new BABYLON.Vector3(alpha, beta, gamma) applies these in the order about z, about x about y using world axes This can be seen by applying mesh.rotate(BABYLON.Axis.Z, gamma, BABYLON.Space.WORLD); mesh.rotate(BABYLON.Axis.X, alpha, BABYLON.Space.WORLD); mesh.rotate(BABYLON.Axis.Y, beta, BABYLON.Space.WORLD); directly after the mesh has been created. Since using rotate produces a rotationQuaternion for the mesh you then do mesh.rotationQuaternion.toEulerAngles() which in BJS 2.5 returns alpha, beta, gamma (in order x, y, z) but didn't in BJS2.3 or BJS2.4 ___________________________________________________________________________________________________________ Now take a different convention with alpha, beta, gamma as Yaw, Pitch, Roll about y (as vertical), x and z all applied around local axes. Applying mesh.rotate(BABYLON.Axis.Y, Yaw, BABYLON.Space.LOCAL); mesh.rotate(BABYLON.Axis.X, Pitch, BABYLON.Space.LOCAL); mesh.rotate(BABYLON.Axis.Z, Roll, BABYLON.Space.LOCAL); directly after mesh creation then mesh.rotationQuaternion.toEulerAngles() returns Pitch, Yaw, Roll which are the angles in the order x, y, z for slotting into mesh.rotation mesh.rotate = new BABYLON.Vector3(Pitch, Yaw, Roll) produces the same rotation. Note BJS2.3 and BJS2.4 do not produce useful values for the convention ZXY. ____________________________________________________________________________________________________________________________________ Finally take a third convention alpha, beta, gamma in the order around z, then x then z as world axes. Apparently this is a fairly standard convention when used with local axes but for reasons that should become apparent I will stick with world axes. Applying mesh.rotate(BABYLON.Axis.Z, alpha, BABYLON.Space.WORLD); mesh.rotate(BABYLON.Axis.X, beta, BABYLON.Space.WORLD); mesh.rotate(BABYLON.Axis.Z, gamma, BABYLON.Space.WORLD); directly after mesh creation then mesh.rotationQuaternion.toEulerAngles() returns alpha, beta, gamma in BJS2.3, nothing useful in BJS2.4 and in BJS2.5 three angles theta, phi, psi in the order x, y, z which can be plugged straight into mesh.rotation to give the same orientation eg mesh.rotation = new BABYLON.Vector3(theta, phi, psi); Summary So in BJS2.3 the function toEulerAngles when given an orientation in quaternion form returns the Euler Angles that can be applied using the ZXZ convention to produce the same rotation. In BJS2.5 the functionf toEulerAngles when given an orientation in quaternion form returns the Euler Angles in the order x, y, z that can be used as parameters for mesh.rotation Quote Link to comment Share on other sites More sharing options...

adam Posted November 1, 2016 Share Posted November 1, 2016 21 minutes ago, JohnK said: In BJS2.5 the function toEulerAngles is - given an orientation in quaternion form supply the Euler Angles in the order x, y, z that can be used as parameters for mesh.rotation Isn't the order y, x, z ? I can add the old YZX code back to the toEulerAngles function. I don't think it should be the default though since the framework doesn't use that order by default. Quote Link to comment Share on other sites More sharing options...

JohnK Posted November 1, 2016 Author Share Posted November 1, 2016 @adam I think that the toEulerAngles function returns in the correct order, eg when E = mesh.rotationQuaternion().toEulerAngles() then mesh1.rotation(E.x, E.y, E.z) matches the orientation of mesh1. Will add PG soon. Quote Link to comment Share on other sites More sharing options...

adam Posted November 1, 2016 Share Posted November 1, 2016 http://www.babylonjs-playground.com/#1FZQZH#10 toEulerAngles and BJS use the order y, x, z not x, y, z. I might have misunderstood your statement above though. Quote Link to comment Share on other sites More sharing options...

GameMonetize Posted November 1, 2016 Share Posted November 1, 2016 I agree with Adam (and I'm the original author :)) We may experience breaking changes but this is because the initial one was wrong. I like the idea of stating in the doc that the ToEulerAngle is stated to return values plugable in the mesh.rotation vector JohnK 1 Quote Link to comment Share on other sites More sharing options...

JohnK Posted November 1, 2016 Author Share Posted November 1, 2016 Somewhere along the lines we have crossed wires about the meaning of order x, y, z. I want @adam's PG to stay. In the following PG angles are chosen at random, axes are chosen at random and whether they are world or local is chosen at random. The box is rotated according to these results. From the rotationQuaternion Euler Angles are obtained and used in the order x, y, z within box1.rotation and the orientation of the two boxes match. This is what I mean by the order x, y, z. http://www.babylonjs-playground.com/#1ST43U#7 Quote Link to comment Share on other sites More sharing options...

JohnK Posted November 1, 2016 Author Share Posted November 1, 2016 Still trying to be clear what you mean by 1 hour ago, adam said: BJS use the order y, x, z because if you take mesh.rotation = new BABYLON.Vector3(x, y, z) then the rotations are done in the order z, x, y as seen in the match between box and box1 in this http://www.babylonjs-playground.com/#1ST43U#2 Swapping the individual rotations to order y, x, z gives a mismatch http://www.babylonjs-playground.com/#1ST43U#8 Mind you I have been playing around with this most of the afternoon ,so as well as the meshes my head is spinning and as you did all the work on sorting toEulerAngles and that works excellently then I think it is only a communication problem as you are happy and I am happy that in practice it all now works as expected. Light Dawns (perhaps) if you do y, x, z in local axes then this matches with mesh.rotation = new BABYLON.Vector3(x, y, z) http://www.babylonjs-playground.com/#1ST43U#4 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.