# Quaternion rotation on GUI object

I’ve created a 3d object on the GUI node and trying to rotate each axis of this object exact amount camera has rotated. (Trying to create something like 3D Orientation model which points where camera is looking at). I’m doing following code:

Quaternion rotation = camera.getRotation().clone();

float[] angles = rotation.toAngles(null);

float xRotation = angles[0];

float yRotation = angles[1];

float zRotation = angles[2];

Quaternion x = new Quaternion();

x = x.fromAngleAxis(xRotation, Vector3f.UNIT_X);

Quaternion y = new Quaternion();

y = y.fromAngleAxis(yRotation, Vector3f.UNIT_Y);

x = x.multLocal(y);

Quaternion z = new Quaternion();

z = z.fromAngleAxis(zRotation, Vector3f.UNIT_Z);

x = x.multLocal(z);

node.setLocalRotation(x);

And works fine… to a point. I get a angle value jump on Z axis around 0 and PI. I did some digging and it looks like toAngles method calls asin method which to my understanding has a different pi range from atan2.

I was thinking what are my options? Was trying to come up with some sort of normalization function but it just won’t click in my mind.

Any help is appreciated

Curious… why not just set the rotation rather than manually recreating what should effectively be the exact same rotation you started with?

node.setLocalRotation( camera.getRotation() )

…what does that fail to do that you need?

I need to rotate an object around axis similarly to what blender does for orientation. I believe set local rotation would rotate it around node center (will make it look up down left and right) not quite behavior I expect

Well, it looks to me like the code above does:

1. get camera rotation
2. deconstruct camera rotation into euler angles
3. reconstruct the original rotation by recombining the euler angles.
4. set this to the local rotation of the node.

The rotation has nothing to do with the point about which it rotated. That is all up to the way a rotation is applied during transformation (ie: before or after translation) Steps 2 and 3 are in theory completely unnecessary… like the equivalent of adding five only to subtract it again.

If you just wanted it rotated around one axis (which would still be through the center of the node, by the way) then I could understand it… but rotating around all three should be an error-prone version of the original rotation.

Have you tried just using the camera rotation? If so, what was the behavior that was undesirable?

Just to reiterate: an axis vector has no position… but neither does a rotation.