C++ 获取当前 ModelView 矩阵
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/766127/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Obtaining current ModelView matrix
提问by arul
In OpenGL, how do I read the current x/y translation in the modelview matrix? I know that you have to load the current matrix into an array and read the floats from there, but I don't know precisely how to do it.
在 OpenGL 中,如何读取模型视图矩阵中的当前 x/y 平移?我知道你必须将当前矩阵加载到一个数组中并从那里读取浮点数,但我不知道如何做到这一点。
回答by arul
In order to retrieve the current modelview matrix you have to call the glGetFloatvfunction with GL_MODELVIEW_MATRIX
parameter.
为了检索当前的模型视图矩阵,您必须使用参数调用glGetFloatv函数GL_MODELVIEW_MATRIX
。
GLfloat matrix[16];
glGetFloatv (GL_MODELVIEW_MATRIX, matrix);
From the documentation:
从文档:
GL_MODELVIEW_MATRIX
params returns sixteen values: the modelview matrix on the top of the modelview matrix stack. Initially this matrix is the identity matrix.
GL_MODELVIEW_MATRIX
params 返回十六个值:模型视图矩阵堆栈顶部的模型视图矩阵。最初这个矩阵是单位矩阵。