Jump to content
  • Advertisement
Sign in to follow this  

quaternion multiplication problem

This topic is 4691 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, I want to rotate a vector v with a quaternion q. I create a quaternion qv from v. Then I use my overloaded operator to rotate v: vrot = q*qv*qinv (all unit quaternions, qinv = q*) But the rotation doesn't work like expected. However if I write the equation like this it works: vrot = qinv*qv*q So my overloaded operator has to be wrong, right ? But I just can't find my mistake, maybe you could have a look:
[source lang='cpp']
quat quat::operator *( const quat &iq ) const
	return quat(	q[1]*iq[2] - q[2]*iq[1] + iq[3]*q[0] + q[3]*iq[0],
			q[2]*iq[0] - q[0]*iq[2] + iq[3]*q[1] + q[3]*iq[1],
			q[0]*iq[1] - q[1]*iq[0] + iq[3]*q[2] + q[3]*iq[2],
			q[3]*iq[3] - q[0]*iq[0] - q[1]*iq[1] - q[2]*iq[2]	);

Thanks for your help! quak

Share this post

Link to post
Share on other sites
At work atm so can't look at the code, but is the rotation going the opposite direction from what you expect? Quaternion multiplication can be defined one of two different ways (practically speaking), and if you got the function from a reference it may be that it doesn't match your prefered convention.

[Edit: Based on your description of the problem, it sounds like this is probably the cause. Again I'd have to look at the code more carefully to be sure, but try swapping the first two terms in the first three expressions and see if that fixes the problem.]

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!