Jump to content
  • Advertisement
Sign in to follow this  
polar01

quaternion/point rotation - wrong direction !

This topic is 3000 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 have a quaternion and a point, I would like to rotate the point, so I have 2 methods : 1) r = q * P * q' 2) r = q.RotationMatrix * P In my code, the version 2 work fine, no problem. But the version 1, rotate in the inverse direction ! I have to negate the W to rotate in the correct direction. I would like to understand why I must do this and if it is correct, or maybe there is a problem somewhere else. NB: Is it possible that it is a left-hand / right-hand problem ? Thanks Some code --------- // method 1 public Vector3 Rotate(ref Vector3 point) { Quaternion conj = This.Clone(); conj.Normalize(); conj = conj.UnitInverse; Quaternion qNode = new Quaternion(0, point.x, point.y, point.z); qNode = This * qNode * conj; return new Vector3(qNode.x, qNode.y, qNode.z); } // Method 2 public Matrix3 ToRotationMatrix() { Matrix3 rotation = Matrix3.Identity.Clone(); float length = (x * x) + (y * y) + (z * z) + (w * w); float s = (length > 0f) ? 2f / length : 0f; float xx = x * x; float yy = y * y; float zz = z * z; float xw = x * w; float yw = y * w; float zw = z * w; float xz = x * z; float xy = x * y; float yz = y * z; rotation.M00 = 1f - (s * yy + s * zz); rotation.M10 = s * xy - s * zw; rotation.M20 = s * xz + s * yw; rotation.M01 = s * xy + s * zw; rotation.M11 = 1f - (s * xx + s * zz); rotation.M21 = s * yz - s * xw; rotation.M02 = s * xz - s * yw; rotation.M12 = s * yz + s * xw; rotation.M22 = 1f - (s * xx + s * yy); return rotation; }

Share this post


Link to post
Share on other sites
Advertisement
Did you read the replies to your other thread?

Anyway, it looks to me like you're using column vectors, but your quaternion rotation matrix is set up for row vectors (that is, it should be the transpose of what it is currently). Assuming that you're using 'standard' quaternion multiplication order, that would mean that it's actually version 1 that's correct, and version 2 that's rotating in the 'wrong' direction.

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!