Jump to content
  • Advertisement
Sign in to follow this  
scriptr

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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.

(Sorry for my bad english)

Share this post


Link to post
Share on other sites
Quote:
Original post by scriptr
But 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 this post


Link to post
Share on other sites
Quote:
Original post by scriptr
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.


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:
(Sorry for my bad english)

Your English is good enough.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!