如果我有模型 View 旋转矩阵(例如,我也可以在 glMultMatrixf(rtMatrix, 0) 中使用),那么我如何计算出围绕虚拟相机的旋转。我认为转换位置 t 只是 camPos=-1*t 但是当我围绕世界中心旋转时如何获得围绕相机的旋转(这是模型 View 矩阵对吗?)
最佳答案
取模型 View 矩阵左上角 3×3 子矩阵的逆:
-1
/ M00 M10 M20 \
O = | M01 M11 M21 |
\ M02 M12 M22 /
完成。
根据 InkBlend 评论中的请求更新代码示例
/* datenwolf's linmath.h, available at
* https://github.com/datenwolf/linmath.h
*/
#include <linmath.h>
void view_orientation(mat4x4 O, mat4x4 MV)
{
mat4x4_dup(O, MV);
O[0][3] = O[1][3] = O[2][3] =
O[3][0] = O[3][1] = O[3][2] = 0.;
O[3][3] = 1;
mat4x4_invert(O, O);
}
关于opengl - 如何从模型 View 矩阵中获取相机旋转矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17325696/