# Maths behind D3DXVec3Project?

This topic is 4920 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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;}

##### Share on other sites
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...

##### Share on other sites
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]

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 31
• 16
• 11
• 10
• 11
• ### Forum Statistics

• Total Topics
634113
• Total Posts
3015592
×