English 中文(简体)
• 转换成轮换矩阵?
原标题:Convert Quaternion rotation to rotation matrix?
  • 时间:2009-10-12 18:50:37
  •  标签:

基本上,考虑到四舍五入(qx、qy、qz、qw)。 怎样才能将这一信息转换成开放的GL轮值? I m还有兴趣了解矩阵浏览是“上”、“权利”、“上”等。 我在病媒中需要摄像机轮换......

最佳回答

下面的法典以 qua(qw, qx, qy, qz)为基础。

boost::math::quaternion<float> quaternion;
float qw = quaternion.R_component_1();
float qx = quaternion.R_component_2();
float qy = quaternion.R_component_3();
float qz = quaternion.R_component_4();

首先,你们必须实现父爱的正常化:

const float n = 1.0f/sqrt(qx*qx+qy*qy+qz*qz+qw*qw);
qx *= n;
qy *= n;
qz *= n;
qw *= n;

接着,你可以制作以下表格:

Matrix<float, 4>(
    1.0f - 2.0f*qy*qy - 2.0f*qz*qz, 2.0f*qx*qy - 2.0f*qz*qw, 2.0f*qx*qz + 2.0f*qy*qw, 0.0f,
    2.0f*qx*qy + 2.0f*qz*qw, 1.0f - 2.0f*qx*qx - 2.0f*qz*qz, 2.0f*qy*qz - 2.0f*qx*qw, 0.0f,
    2.0f*qx*qz - 2.0f*qy*qw, 2.0f*qy*qz + 2.0f*qx*qw, 1.0f - 2.0f*qx*qx - 2.0f*qy*qy, 0.0f,
    0.0f, 0.0f, 0.0f, 1.0f);

视您的矩阵类别,您在将其转至开放式利比里亚市场之前可能不得不进行转换。

问题回答

One way to do it, which is pretty easy to visualize, is to apply the rotation specified by your quaternion to the basis vectors (1,0,0), (0,1,0), and (0,0,1). The rotated values give the basis vectors in the rotated system relative to the original system. Use these vectors to form the rows of the rotation matrix. The resulting matrix, and its transpose, represent the forward and inverse transformations between the original system and the rotated system.

I m not familiar with the conventions used by OpenGL, so maybe someone else can answer that part of your question...

您可能根本不需要处理轮换矩阵。 这种方法似乎比转换成矩阵和将矢量成倍:

  // 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);

http://mollyrocket.com/forums/viewtopic.php?t=833&sid=3a84e00a70ccb046cfc87ac39881a3d0”rel=“nofollow”http://mollyrocket.com/forums/viewtopic.php?t=833&sid=3a84e00a70ccb046cfc87ac39881a3d0

using glm, you can simply use a casting operator. so to convert from a matrix4 to quaternion, simply write

gl:mat4_cast(等称)





相关问题
热门标签