Maths behind D3DXVec3Project?
Hello,
I am coding a game (using OpenGL), where I need to get the screen coords of one of my 3d objects (mainly to show some text over its head).
So I appreciate if someone could help me with the maths behind D3DXVec3Project,
or maybe a function like this but for OpenGL.
Thanks in advance,
Oscar
I suggest you to Download the Mesa Lib 3.0 Package. There is a source implementation of the gluProject method. So look deep into the GLU package for find how Mesa implements it. Here is a fragment of the code :
See also gluUnProject.
/* projection du point (objx,objy,obz) sur l'ecran (winx,winy,winz) */GLint APIENTRY 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;}
See also gluUnProject.
Thanks! thats the kind of info I was looking for : ).
PS: I will take a look at the Mesa Lib 3.0 Package, as you suggest me.
Muchas gracias por tu ayuda leoptimus : )
Best Regards,
Oscar
PS: I will take a look at the Mesa Lib 3.0 Package, as you suggest me.
Muchas gracias por tu ayuda leoptimus : )
Best Regards,
Oscar
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement