math - 如何从 OpenGL ModelView 矩阵获取 View 方向?

标签 math opengl rotation volume-rendering

我正在编写一个体积渲染程序,它不断调整一些平面几何形状,使其始终面向相机。每当相机旋转时,平面几何体就会旋转,以便看起来好像它相对于场景中的其他所有东西都没有移动。 (我使用相机的观看方向作为这些平面几何形状的法线向量。)

目前,我正在手动存储自定义旋转向量(“旋转”)并在渲染函数中应用其影响,如下所示:

gl2.glRotated(rotations.y, 1.0, 0.0, 0.0);
gl2.glRotated(rotations.x, 0.0, 1.0, 0.0);

然后,我通过使用旋转值围绕 x 和 y 轴旋转初始 View 方向 (0,0,-1) 来获得 View 方向。这是通过以下方式完成的。最终的观看方向存储在'view'中:

     public Vec3f getViewingAngle(){
        //first rotate the viewing POINT
        //then find the vector from there to the center
        Vec3f view=new Vec3f(0,0,-1);
        float newZ=0;
        float ratio=(float) (Math.PI/180);
        float vA=(float) (-1f*rotations.y*(ratio));
        float hA=(float) (-1f*rotations.x)*ratio;

        //rotate about the x axis first
        float newY=(float) (view.y*Math.cos(vA)-view.z*Math.sin(vA));
        newZ=(float) (view.y*Math.sin(vA)+view.z*Math.cos(vA));
        view=new Vec3f(view.x,newY,newZ);

        //rotate about Y axis
        float newX=(float) (view.z*Math.sin(hA)+view.x*Math.cos(hA));
        newZ=(float) (view.z*Math.cos(hA)-view.x*Math.sin(hA));
        view=new Vec3f(newX,view.y,newZ);
        view=new Vec3f(view.x*-1f,view.y*-1f,view.z*-1f);

        //return the finalized normal viewing direction
        view=Vec3f.normalized(view);
        return view;
}

现在我正在将此程序移动到一个更大的项目,其中相机旋转由第三方图形库处理。我没有旋转向量。有什么方法可以获取我的 View 方向向量:

GLfloat matrix[16]; 
glGetFloatv (GL_MODELVIEW_MATRIX, matrix);

我正在看这个作为引用http://3dengine.org/Modelview_matrix但我仍然不知道如何提出 View 方向。有人可以向我解释一下这是否可能以及它是如何工作的吗?

最佳答案

您会想看看这张照片@ http://db-in.com/images/local_vectors.jpg http://db-in.com/images/local_vectors.jpg

飞行方向 (DOF) 是第三行。

GLfloat matrix[16]; 
glGetFloatv( GL_MODELVIEW_MATRIX, matrix );

float DOF[3];
DOF[0] = matrix[  2 ]; // x
DOF[1] = matrix[  6 ]; // y
DOF[2] = matrix[ 10 ]; // z

引用:

关于math - 如何从 OpenGL ModelView 矩阵获取 View 方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15697273/

相关文章:

javascript - 确定更大的数字并划分

algorithm - 最小化到加权网格的距离

c++ - 透视投影 OPENGL 和计算着色器

javascript - 根据 jQuery 中的旋转播放音乐

c - 将绕任意轴的旋转解析为绕 X、Y 和 Z 轴的旋转

java - 随机梯度下降未能在我的神经网络实现中收敛

c++ - Windows 7 上的 MS 计算器。我需要知道它是如何进行操作的

opengl - GO-OpenGL LoadMatrixd 和 GetDoublev 问题

c# - 如何加入重叠的圈子?

iOS 6 旋转 : supportedInterfaceOrientations doesn´t work?