# Direction of rotation along x-axis

Hello! I’m having some trouble applying quaternions to a human model in JME. This is the model in the initial position (the camera is oriented looking from a vector 1,1,1 towards the origin):

Now, if apply a 90 degrees rotation around the x-axis using this code (where bones[5] is the bone corresponding to the left upper arm):

``````    bones[5].setUserControl(true);
Quaternion rot = new Quaternion(new float[]{(float) Math.toRadians(90), 0f, 0f});
bones[5].setUserTransforms(Vector3f.ZERO,
rot,
Vector3f.UNIT_XYZ);``````

I have this results:

But if JME uses the same right-hand coordinates system of OpenGL, why a positive rotation around the x-axis make the arm to lift towards the front instead the back?? Shouldn’t the positive rotation be counter-clockwise??
Also because applying the same positive rotation of 90 degrees to the y-axis the model rotate as expected in the counter-clockwise direction.

Thank you.

If you position the camera at (0,0,0) and look at the guy, the arm actually does rotate counter clockwise.

The rotation of the arm doesn’t depends from the point of view of the user or from where the camera is placed. The direction of the rotation should be referred to the reference system, that in my model I highlighted with the coloured axis. Given that the x-axis is the green one, the rotation of the arm around this axis is clockwise, instead to be counter-clock wise as it should be.

The direction does not depend on the camera, that is correct.
But whether you see it as clockwise or counter clockwise does.

If you flip a (transparent) clock over and look at it from behind, its hands move counter clockwise, even though the direction of the actual rotation did not change.

The way JME defines rotation is “counter clockwise when being viewed from the axis’s point of origin”

Ok, I understand your point. But the right-hand rule tells that looking from the point 1,0,0 towards the origin, the rotation should be counter clockwise. Like this:

Initially, as you said, I thought that could be JME that actually use the counter clockwise direction from the point of view of the origin. But if so, why does this code:

``````bones[0].setUserControl(true);
Quaternion rot = new Quaternion(new float[]{0f, (float) Math.toRadians(90), 0f});
bones[0].setUserTransforms(Vector3f.ZERO,
rot,
Vector3f.UNIT_XYZ);``````

that rotate the torso by 90 degrees, generate this rotation in the model?

For the y-axis a positive rotation is applied counter clockwise, watching from the up towards the origin. For the x-axis the same positive rotation is applied clockwise, watching from the East towards the origin. As you said, whether I see a rotation as clockwise or counter clockwise depends on the camera or on the point of view of the user, but it should be anyway coherent.

Well, I don’t know if this affects what you expect but remember when looking down the positive Z axis, the X axis is backwards. We usually think of Y up and X right… but in JME that’s only when looking down the negative Z axis.

Anyway, bones are weird because they may have transforms applied higher up that move them in odd orientations. Of course, the models I was using were defined by someone else so maybe a proper hierarchy doesn’t have that issue. For me, when I wanted rotations to be sensible in world space I always had to change the basis.

And in world space, when looking down positive Z, I’d expect a positive rotation around the X-axis to be backwards… like you expect. But honestly, I always find out through trial and error.

In JME, looking from the positive Z towards the origin, the Y is up and the X is right, as reported in: http://davidb.github.io/sandbox_wiki_jme/jme3/math.html#coordinate-system

Anyway, with a little more tests I’ve seen that only the arms of my model have been affected by this problem. Is I apply the rotation to the torso or the the legs, the body part is rotated correctly. Can anyone explain this behavior? How can the direction of the rotation depend on the part of the model??

Because it’s a hierarchy?