Convert Quaternion rotation to rotation matrix?

前端 未结 4 944
死守一世寂寞
死守一世寂寞 2020-12-01 08:08

Basically, given a quaterion (qx, qy, qz, qw)... How can i convert that to an OpenGL rotation matrix? I\'m also interested in which matrix row is \"Up\", \"Right\", \"Forwa

4条回答
  •  半阙折子戏
    2020-12-01 09:04

    You might not have to deal with a rotation matrix at all. Here is a way that appears to be faster than converting to a matrix and multiplying a vector with it:

      // move vector to camera position co (before or after rotation depending on the goal)
      v -= co;
    
      // rotate vector v by quaternion q; see info [1]
      vec3 t = 2 * cross(q.xyz, v);
      v = v + q.w * t + cross(q.xyz, t);
    

    [1] http://mollyrocket.com/forums/viewtopic.php?t=833&sid=3a84e00a70ccb046cfc87ac39881a3d0

提交回复
热议问题