Maths behind D3DXVec3Project?

Started by
3 comments, last by ogracian 18 years, 8 months ago
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
Advertisement
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 :
/* 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.
"Technocracy Rules With Supremacy" visit: http://gimpact.sourceforge.net
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

Hablas español?
De donde eres...
"Technocracy Rules With Supremacy" visit: http://gimpact.sourceforge.net
Hola,

Si, soy de Mexico, y como vi en tu profile que eras de espana : ).

Sobre el Mesa lib, ya lo baje, y me resulto muy util!.

Gracias, y saludos desde Mexico,
Oscar

[Edited by - ogracian on August 2, 2005 7:28:02 PM]

This topic is closed to new replies.

Advertisement