opengl - 如何从模型 View 矩阵中获取相机旋转矩阵

标签 opengl opengl-es matrix rotation

如果我有模型 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/

相关文章:

ios - 将OpenCV的findHomography透视矩阵转换为iOS的CATransform3D

java - 光线转换以避免绘制看不见的面孔

java - 如何在libgdx中制作几何着色器?

c++ - OpenGL 着色器版本编译错误

Android OpenGL ES 2 - 混合似乎总是相加的

iPhone GLSL动态分支问题

python - Pandas 从距离矩阵中按 ID 提取列和行

matlab - 在 matlab 中连接元胞数组的向量

opengl - gl_Position.w 的负值?

android - 从 OpenGL 中的矩阵获取位置、旋转和缩放