View Full Version : 3D to 2D

11-08-2004, 03:05 AM

Is it possible to get the 2D coordonate on screen where un point (x,y,z) will be draw ?

Thanks ^^

11-08-2004, 08:17 AM
multiplying the point by the modelview and projection matrices should work

11-08-2004, 09:00 AM
that's a bit complicated ;)

the function is

GLdouble objX, objY, objZ;
GLdouble mm[16], pm[16];
GLint vp[4];
GLdouble winX, winY, winZ;

glGetDoublev(GL_MODELVIEW_MATRIX, mm);
glGetIntegerv(GL_VIEWPORT, vp);

gluProject(objX, objY, objZ, mm, pm, vp, &winX, &winY, &winZ);

objX/objY/objZ are the real world coordinates, model/proj/view are the current modelview/projection/viewport matrices, you get the window coordinates back in winX/winY/winZ. winZ is a normalized z-buffer value. concerning winY- for opengl, winY = 0 is at the bottom of the window, but for X11 (and i think windows as well) winY = 0 is at the top of the window. you have to consider that when you get window events.