# How to rotate only in one direction?

hi,

I would like to rotate my object 30 degress about the X-Axis. But the other rotations (Y- and Z-Axis) should not be changed.

Thanks for any help,

Fellkneul

``` object.setlocalRotation(new Quaternion().fromAngleAxis(30 * FastMath.DEG_TO_RAD, new Vector3f(1, 0, 0))); ```

Wouldn't that reset the other axes to 0 degree? But you can for sure use dhdd's code to create a new Node, rotate that 30 degree and attach your original object to it.

ttrocha said:

Wouldn't that reset the other axes to 0 degree?

yes ... as always: brain.use();

``` object.getlocalRotation().multLocal(new Quaternion().fromAngleAxis(30 * FastMath.DEG_TO_RAD, new Vector3f(1, 0, 0))); ```

Wouldn't that reset the other axes to 0 degree?

-> Thats right... otherwise it would be quite simple...

object.getlocalRotation().multLocal(new Quaternion().fromAngleAxis(30 * FastMath.DEG_TO_RAD, new Vector3f(1, 0, 0)));

-> AFAIK, this would only "add" a rotation of 30 degrees. I would like to set it to 30 degrees as there is already a rotation in X-Axis. You know what I mean?

You can always create your rotation from yaw-pitch-roll angles (the roations about y,z axes from the original rotation + whatever the rotation you want to set around the x-axis).

``` object.setLocalRotation(new Quaternion().fromAngleAxis(30 * FastMath.DEG_TO_RAD, object.getLocalRotation().getRotationColumn(0))); ```

Please tell me, if I'm wrong… but…

If you create a new Quaternion and tell it to get its information by the "fromAngleAxis"-function and finally set the LocalRotation to this Quaternion, then there is just no possibility to not change the other rotations. Creating a new Quaternion overwrites all the other rotations set before.

thank for help,

Fellkneul

Well, in the line I posted, the axis you are creating it from is your current X axis which is dictated by your existing rotations.

You are setting a 30 degree rotation about that axis.

Can't really test it right now though. Does it not do what you need?

I'm sorry, but this does not work. It sets the X-Rot to 30 degrees but it changes the Y-Rot to 0.

@Starnick:

You were right, i'm sorry… i should have read your answer more properly… would have saved me some time… well… that will do:

``` float[] angles = obj.getLocalRotation().toAngles(null);                 System.out.println("X-Rot: " + (angles[0] * FastMath.RAD_TO_DEG)); System.out.println("Y-Rot: " + (angles[1] * FastMath.RAD_TO_DEG)); System.out.println("Z-Rot: " + (angles[2] * FastMath.RAD_TO_DEG) + "n");                 angles[0] = 35 * FastMath.DEG_TO_RAD;                 obj.getLocalRotation().fromAngles(angles); ```

Thank you all for helping me,

Fellkneul