# What is the difference between rotation, rotationQuaternion, rotate(), addRotation()?

What’s the difference or connection?

Hello

• `rotation`: `BABYLON.Vector3` defining the rotation of a mesh in EULER mode
• `rotationQuaternion`: `BABYLON.Quaternion` (see it as a Vector4) defining the rotation of a mesh in QUATERNION mode
• `rotate()`: Method for rotating around a specific axis
• `addRotation()`: Method for adding Euler angles to the current rotation

Now if you wonder why using Quaternion, it’s usefull because it a way to avoid the Gimbal Lock problem of euler angles.

Best way to understand it is to open Blender and :

• Rotate a cube 90° on Y axis
• Now you cannot rotate global X anymore. Both X and Z rotation seems to be influencing the global Z axis and you are basically stuck. Rotating global X is now impossible.

++
Tricotou

3 Likes

oh,my baby,thanks for solving the problem.

1 Like

One more hint:

If you want to use euler rotations on a mesh which has a rotation quaternion set, you must set the quaternion to `null` before you can rotate the mesh using eulers.

2 Likes

Absolutely.
I use to add this on GLB loader, when I don’t need quaternion :

``````meshes.forEach(function(mesh){
if(mesh.rotationQuaternion){
const rotation = mesh.rotationQuaternion.toEulerAngles();
mesh.rotationQuaternion = null;
mesh.rotation = rotation;
}
})
``````

That way you keep as well the initial rotation state even if it was Quaternion

1 Like

Else, I believe you know that setting a ‘new BABYLON.vector3’ for ‘rotation’ actually nulls the rotationQuartenion.

Didn’t know !

Then I guess we can save a few lines of code

``````meshes.forEach(function(mesh){
mesh.rotation = mesh.rotationQuaternion ? mesh.rotationQuaternion.toEulerAngles() : mesh.rotation;
})
``````

Yup, I believe it works. I do hope it still does as I’m using this quite often
It’s kind of written here

So Euler angles and rotationQuartenion are mutually exclusive

It is as in the text. To be honest, my english is not the best so I’m not sure to fully understand ‘mutually exclusive’? If by this you mean you cannot mix (i.e. by parenting) rotationQuartenion and the ‘standard’ rotation with euler angles, yes this is true… you can’t. Reason why you can convert it (or null one and switch to the other).

I translated it using DeepL.
To set rotationQuartenion to null when using rotation.
To set rotation to null when using rotationQuartenion.

Oh, should I understand that english is also not your language? This can become confusing for this kind of subject In short, from my experience (and from the warnings in the doc), it’s best to avoid ‘mixing’ both methods (i.e. in hierarchy with animations). Choose if you want to work your object/hierarchy from either one (quartenion using ‘rotate’ or ‘rotation’ using angles from the ‘fixed’ center point of object (or pivot). To be honest, lazy me sometimes keeps with a mix but to be honest, it can become real messy, so you’d better avoid it.

How do you convert rotation to rotationQuartenion

Same as the other way round. By setting ‘new’.

mesh.rotationQuaternion = new BABYLON.Quaternion.RotationAxis(new BABYLON.Vector3(1, 0, -1), Math.PI / 3);

or by setting ‘new’ on rotate, i.e.:

``````
> mesh.rotate(new BABYLON.Vector3(1, 0 -1), Math.PI / 3, BABYLON.Space.WORLD);

``````

EDIT: Oh, and actually there’s also a PG in the doc showing the conversion to euler angles. May be this will help?

Thank you very much.

To be precise it doesn’t work in this scenario:

1. import a mesh which has a quaternion rotation set
2. `mesh.rotation.x = 0.5` will be ignored
3. `mesh.rotationQuaternion = null; mesh.rotation.x = 0.5` will do the thing