Sign in to follow this  

Maths behind D3DXVec3Project?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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;
}





See also gluUnProject.

Share this post


Link to post
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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this