PDA

View Full Version : 3D to 2D



lud2k
11-08-2004, 03:05 AM
Hi,

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

Thanks ^^

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

RigidBody
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);
glGetDoublev(GL_PROJECTION_MATRIX, pm);
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.