# Modify quaternion to a target angle

This topic is 3157 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, When i want to add a 45 degree rotation to a 3d object to its X rotation by quaternion, i do: quaternion.fromAngleAxis( 45 * PI / 180.0f, xAxis ); curRotationQuaternion *= quaternion; curRotationQuaternion.toEuler(euler); node->setRotation(euler * 180.0f / PI); This is ok, and works fine. But what can i do to set the nodes x rotation to 45 degree, not add a 45 degree to the current angle? Thanks,

##### Share on other sites
What do you mean by "the nodes[sic] x rotation"? What exactly are you trying to achieve?

##### Share on other sites
The code above adds a 45 degree rotation to the node's x rotation. What I want is: to rotate the node to 45 degree around global x axis.

For example lets assume we have rotated the node to 135 degree. So its x-rotation is 135. I want to set it to 45.

##### Share on other sites
Quote:
 Original post by scriptrBut what can i do to set the nodes x rotation to 45 degree, not add a 45 degree to the current angle?

quaternion.fromAngleAxis( 45 * PI / 180.0f, xAxis );curRotationQuaternion = quaternion;curRotationQuaternion.toEuler(euler);node->setRotation(euler * 180.0f / PI);

##### Share on other sites
Quote:
 Original post by scriptrThe code above adds a 45 degree rotation to the node's x rotation. What I want is: to rotate the node to 45 degree around global x axis.For example lets assume we have rotated the node to 135 degree. So its x-rotation is 135. I want to set it to 45.

What if we have rotated the node in some arbitrary fashion? How would you determine what its x-rotation is? I don't know how to define such thing. Perhaps you can convert the quaternion to Euler angles, set the x-rotation to 45 and then reconstruct the quaternion.

But I still don't know what you are trying to achieve, so I don't know if that would be reasonable. Chances are what you really want to do can be reworded into something that would make more sense mathematically.

Quote:

• 11
• 18
• 12
• 22
• 9
• ### Forum Statistics

• Total Topics
631397
• Total Posts
2999822
×