inline glm::mat4 CalcViewMatrix(const PoseData &poseData){
glm::mat4 matrix_t = glm::transpose(glm::mat4{
1.0f, 0.0f, 0.0f, -poseData.head_pose.tx,
0.0f, 1.0f, 0.0f, -poseData.head_pose.ty,
0.0f, 0.0f, 1.0f, -poseData.head_pose.tz,
0.0f, 0.0f, 0.0f, 1.0f,
});
float x = poseData.head_pose.rx;
float y = poseData.head_pose.ry;
float z = poseData.head_pose.rz;
float w = poseData.head_pose.rw;
glm::mat4 matrix_r_q = glm::transpose(glm::mat4{
1.0f - 2.0f*y*y - 2.0f*z*z, 2.0f*x*y + 2.0f*w*z, 2.0f*x*z - 2.0f*w*y, 0.0f,
2.0f*x*y - 2.0f*w*z, 1.0f - 2.0f*x*x - 2.0f*z*z, 2.0f*y*z + 2.0f*w*x, 0.0f,
2.0f*x*z + 2.0f*w*y, 2.0f*y*z -2.0f*w*x, 1.0f - 2.0f*x*x - 2.0f*y*y, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f,
});
glm::mat4 matrix_ltr = glm::transpose(glm::mat4{
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, -1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f,
});
glm::mat4 worldToCamera = matrix_ltr * matrix_r_q * matrix_t;
//PrintMatrix("CalcViewMatrix matrix_t", matrix_t);
//PrintMatrix("CalcViewMatrix matrix_r_q", matrix_r_q);
//PrintMatrix("CalcViewMatrix worldToCamera", worldToCamera);
return worldToCamera;
}
Unity左手坐标系计算View视图矩阵
于 2024-07-25 19:06:42 首次发布