Search This Blog

Monday, March 22, 2010

gluProject source code

GLint GLAPI
gluProject(GLdouble objx, GLdouble objy, GLdouble objz,
const GLdouble modelMatrix[16],
const GLdouble projMatrix[16],
const GLint viewport[4],
GLdouble *winx, GLdouble *winy, GLdouble *winz)
{
double in[4];
double out[4];

in[0]=objx;
in[1]=objy;
in[2]=objz;
in[3]=1.0;
__gluMultMatrixVecd(modelMatrix, in, out);
__gluMultMatrixVecd(projMatrix, out, in);
if (in[3] == 0.0) return(GL_FALSE);
in[0] /= in[3];
in[1] /= in[3];
in[2] /= in[3];
/* Map x, y and z to range 0-1 */
in[0] = in[0] * 0.5 + 0.5;
in[1] = in[1] * 0.5 + 0.5;
in[2] = in[2] * 0.5 + 0.5;

/* Map x,y to viewport */
in[0] = in[0] * viewport[2] + viewport[0];
in[1] = in[1] * viewport[3] + viewport[1];

*winx=in[0];
*winy=in[1];
*winz=in[2];
return(GL_TRUE);
}

For more information: http://www.mesa3d.org/

1 comment:

Blog Archive