Jump to content
  • Advertisement
Sign in to follow this  
Farraj

Rotating wiht Quaternion

This topic is 3615 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

So I have this small problem that I don't understand. I have an object that I want to rotate around it's Y-axis (regardless of the direction it's looking at) every frame. With me limited knowledg of quaternion I thought that this idea would work. 1- Get the quaternion for the object (objQuat) 2- Create a quaternion that rotates around the Y-axis with a certain degree/second (rotatQuat). Where x = 0, y = 1, z = 0, angleSpeed = how fast I want the object to rotate, and deltaTime = time diffrence between this frame and the last frame. So rotateQuat = Quaternion(x, y, z, angleSpeed * deltaTime). 3- I multiply both quaternion to get the direction I want (resutlQuat = objQuat * rotateQuat) I tested and it sort of worked. The object only rotates for like 180 degrees. It stops half way. I can rotate it back but it stops at it's first position. Can someone exmplin why is this happing? And how to solve it? Cheers :)

Share this post


Link to post
Share on other sites
Advertisement
A quaternion isn't just a straight axis-angle pair; it's slightly more complicated than that. Given a (normalized) axis (x,y,z) and an angle of rotation, the corresponding quat is:

Q = ( x*sin(angle/2), y*sin(angle/2), z*sin(angle/2), cos(angle/2) )

So in your case you want:

rotateQuat = Quaternion( 0, sin(angleSpeed*deltaTime / 2), 0, cos(angleSpeed * deltaTime / 2) )

Share this post


Link to post
Share on other sites
Yes, actually, I know that. The quaternion I use do that, just didn't want to make a long post :P Sorry if that wasn't clear.

I'm still wondering why this is happing. I used this method for some effects and worked, but I never used it to make a full 360 degree before. I was just surprised that it didn't work.

Any one else?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!