1. 从官方说明如下
https://www.opengl.org/sdk/docs/man2/xhtml/gluProject.xml
Name
gluProject — map object coordinates to window coordinatesC,匹配“物体坐标系”“Win窗口坐标系(坐标原点在左下方)”
Specification
GLint gluProject(GLdouble objX, GLdouble objY, GLdouble objZ, const GLdouble * model, const GLdouble * proj, const GLint * view, GLdouble* winX, GLdouble* winY, GLdouble* winZ);
Parameters
objX, objY, objZ
Specify the object coordinates.
model
Specifies the current modelview matrix (as from a glGetDoublev call).
proj
Specifies the current projection matrix (as from a glGetDoublev call).
view
Specifies the current viewport (as from a glGetIntegerv call).
winX, winY, winZ
Return the computed window coordinates.
Description
gluProject transforms the specified object coordinates into window coordinates using model, proj, and view. The result is stored in winX, winY, and winZ. A return value of GLU_TRUE indicates success, a return value of GLU_FALSE indicates failure.
2. 使用介绍
把空间中的一个三维坐标转换成二维坐标,用这个gluProject函数
3. 原码分析
原码的写法很好 nice, 先通过看代码,来一步一步分析它的数学原理吧!既学习代码,同时也要掌握数学原理, 在这里才是成长的关键所在!
static void transform_point(GLdouble out[4], const GLdouble m[16], const GLdouble in[4]) { #define M(row,col) m[col*4+row] out[0] = M(0, 0) * in[0] + M(0, 1) * in[1] + M(0, 2) * in[2] + M(0, 3) * in[3]; out[1] = M(1, 0) * in[0] + M(1, 1) * in[1] + M(1, 2