前の質問に対する答えを見つけた後、その原因はある種の数学的な奇妙さであることがわかりました。
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);
この向きから行列を作成すると、列優先ではなく行優先になります
glm::mat4 view = glm::gtx::quaternion::toMat4(orientation);
つまり、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
つまり、回転部分の転置。
マトリックスの変換部分は、最終的なビュー マトリックスが意図したとおりに機能するために、列優先を使用して設定する必要があります。
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
向きを使用すると、回転行列が列優先から行優先に反転する (転置される) のはなぜですか?
編集:
// 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
}