/ Published in: C++
This is the full sequence of commands needed to make a gluProject call to get the 2D projections of 3D points with the current scene parameters (projection, transformations, etc). Note that the coordinates are given in pixels relative to the viewport's location, not the computer screen!
If you need for further processing, you can access the viewport's dimensions by fetching viewport[0] (xOrigin, relative to the OpenGL window), viewport[1] (yOrigin), viewport[2] (width) and viewport[3] (height).
If you need for further processing, you can access the viewport's dimensions by fetching viewport[0] (xOrigin, relative to the OpenGL window), viewport[1] (yOrigin), viewport[2] (width) and viewport[3] (height).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
double modelview[16]; double projection[16]; int viewport[4]; double screenX, screenY, screenZ; glGetDoublev(GL_MODELVIEW_MATRIX, modelview); glGetDoublev(GL_PROJECTION_MATRIX, projection); glGetIntegerv(GL_VIEWPORT, viewport); //you'll probably want to put this inside a loop, to get all the model's points gluProject(modelPointX, modelPointY, modelPointZ, modelview, projection, viewport, &screenX, &screenY, &screenZ);
URL: http://www.opengl.org/sdk/docs/man/xhtml/gluProject.xml