Re: [Plib-users] How to compute screen coordinates
Brought to you by:
sjbaker
|
From: Steve B. <sjb...@ai...> - 2001-06-14 01:46:34
|
> Corto Maltese wrote:
> I want to compute the screen (pixels) coordinates in the viewport of a world 3d point.
> How to do that ?
> I know that gluProject can do that....
"Use the Source Luke".
The sources for gluProject are available from either the SGI reference implementation
of OpenGL or Mesa.
The Mesa source is:
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) * in[2] + M(1,3) * in[3];
out[2] = M(2,0) * in[0] + M(2,1) * in[1] + M(2,2) * in[2] + M(2,3) * in[3];
out[3] = M(3,0) * in[0] + M(3,1) * in[1] + M(3,2) * in[2] + M(3,3) * in[3];
#undef M
}
GLint GLAPIENTRY gluProject(GLdouble objx,GLdouble objy,GLdouble objz,
const GLdouble model[16],const GLdouble proj[16],
const GLint viewport[4],
GLdouble *winx,GLdouble *winy,GLdouble *winz)
{
/* matrice de transformation */
GLdouble in[4],out[4];
/* initilise la matrice et le vecteur a transformer */
in[0]=objx; in[1]=objy; in[2]=objz; in[3]=1.0;
transform_point(out,model,in);
transform_point(in,proj,out);
/* d'ou le resultat normalise entre -1 et 1*/
if (in[3]==0.0)
return GL_FALSE;
in[0]/=in[3]; in[1]/=in[3]; in[2]/=in[3];
/* en coordonnees ecran */
*winx = viewport[0]+(1+in[0])*viewport[2]/2;
*winy = viewport[1]+(1+in[1])*viewport[3]/2;
/* entre 0 et 1 suivant z */
*winz = (1+in[2])/2;
return GL_TRUE;
}
[Cool! Comments in French!]
> For Steve Baker : You've done a pretty great job with Plib. Bravo!
Let's hope you still feel that way after we produce 1.3.2 later today.
----------------------------- Steve Baker -------------------------------
HomeMail : <sjb...@ai...> WorkMail: <sj...@li...>
HomePage : http://web2.airmail.net/sjbaker1
Projects : http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net
http://agtoys.sf.net http://prettypoly.sf.net
http://freeglut.sf.net http://toobular.sf.net
|