GLM - 来自方向的矩阵是创建行主要而不是列主要矩阵?

use*_*893 3 c++ math matrix

在弄清楚我之前的问题的答案后,我发现原因是某种数学怪异.

使用GLM(OpenGL)库我创建如下方向

glm::gtx::quaternion::orientation = 
    glm::gtx::quaternion::angleAxis(pitchAccum, 1.0f, 0.0f, 0.0f) * 
    glm::gtx::quaternion::angleAxis(yawAccum, 0.0f, 1.0f, 0.0f);
Run Code Online (Sandbox Code Playgroud)

现在,如果我从这个方向创建一个矩阵,它不再是列专业,但不知何故成为行主要

    glm::mat4 view = glm::gtx::quaternion::toMat4(orientation); 
Run Code Online (Sandbox Code Playgroud)

换句话说,通过使用行主索引访问矩阵来找到3个坐标轴

view[0][0], view[1][0], view[2][0]  // X axis
view[0][1], view[1][1], view[2][1]  // Y axis
view[0][2], view[1][2], view[2][2]  // Z axis
Run Code Online (Sandbox Code Playgroud)

换句话说,旋转部件的转置.

仍应使用列major设置矩阵的平移部分,以使最终视图矩阵按预期工作.

view[3][0] = -glm::dot(glm::vec3(view[0][0], view[1][0], view[2][0]), position);    // Right
view[3][1] = -glm::dot(glm::vec3(view[0][1], view[1][1], view[2][1]), position);    // Up
view[3][2] = -glm::dot(glm::vec3(view[0][2], view[1][2], view[2][2]), position);    // Forward
Run Code Online (Sandbox Code Playgroud)

当使用方向时,为什么旋转矩阵从主要主要部分翻转到行主要部分(转置?)?

编辑:

// Move forward
if (glfwGetKey('W') == GLFW_PRESS)
{
    //movement += glm::vec3(view[2][0], view[2][1], view[2][2]);  // incorrect
    movement += -glm::vec3(view[0][2], view[1][2], view[2][2]);   // correct
}
// Move backward
if (glfwGetKey('S') == GLFW_PRESS)
{
    //movement += -glm::vec3(view[2][0], view[2][1], view[2][2]); // incorrect
    movement += glm::vec3(view[0][2], view[1][2], view[2][2]);    // correct
}
// Strafe left
if (glfwGetKey('A') == GLFW_PRESS)
{
    //movement += -glm::vec3(view[0][0], view[0][1], view[0][2]);  // incorrect
    movement += -glm::vec3(view[0][0], view[1][0], view[2][0]);    // correct
}
// Strafe right
if (glfwGetKey('D') == GLFW_PRESS)
{
    //movement += glm::vec3(view[0][0], view[0][1], view[0][2]);  // incorrect
    movement += glm::vec3(view[0][0], view[1][0], view[2][0]);    // correct
}
Run Code Online (Sandbox Code Playgroud)

Nic*_*las 7

从空间A变换到空间B的矩阵M具有空间A的基矢量,但是相对于空间B表示.

相机矩阵从世界空间转换到相机空间.因此,从相机空间看,相机矩阵的基矢量是世界空间的基矢量.不是相机空间的基础向量.

相对于世界空间的摄像机方向与此变换相反.而且由于旋转矩阵的反转是它的转置,你有问题.

问题不在于矩阵; 问题在于您认为矩阵所说的与实际所说的内容之间存在差异.