3D objects and 2D hud

Hi, I have a 2D Hud (using glOrtho) over a 3D scene.
What I need is to obtain the 2D choords of an object displayed in the “3D” layer. (just the object origin: 0,0,0)

In other words, I need to know the on screen x,y coordinates of a point at x1,y1,z1 in the 3D world…

thanks

Andrea Doimo

Probably going to have to get both the model view and perspective matricies from GL, and apply them both to the untransformed location of your 3d object.

Just need a simple vector * matrix function, and use glGetFloatv() calls to get the matrix data.

A potentially easier way that I have never tried is to use glFeedbackBuffer(). I beleive you can get the exact 2d coordinates of rendered objects through it.

Jon

Actually, you have a function called gluProject that will do exactly that for you… It implements what jmX described except that it also takes the viewport into account (yes, you need it !).

So, if you want to use it:

GLdouble modelMatrix[16],projMatrix[16];
GLint viewport[4];
GLdouble winx,winy,winz; // Coordinates of the projected point on the screen //
glGetDoublev(GL_MODELVIEW_MATRIX,modelMatrix);
glGetDoublev(GL_PROJECTION_MATRIX,projMatrix);
glGetIntegerv(GL_VIEWPORT,viewport);

gluProject(x1,y1,z1,modelMatrix,projMatrix,viewport,&winx,&winy,&winz);

Where x1,y1,z1 are the coordinates of the point to project…

Best regards.

Eric

Actually, you have a function called gluProject that will do exactly that for you… It implements what jmX described except that it also takes the viewport into account (yes, you need it !).

Works! Thanks a LOT!

Moreover I haven’t seen any speed drop (calculating just 5 points/frame)