Sign in to follow this  
Farraj

Rotating wiht Quaternion

Recommended Posts

Farraj    152
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
FluxCapacitor    200
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
Farraj    152
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this