gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 03:26:25 30 4
gpt4 key购买 nike

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

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

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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com