I've got an OpenGL scene with some figures on it. Can you tell me what I need to do to calculate figures apexes positions after "rendering"? I know I probably need to manual multiply some matrices, but I don't know which of them and how.
Thanks in advance for any help!
Take a look at the gluProject()
function.
Edit: Also found in the OpenGL FAQ:
9.100 How can I find the screen coordinates for a given object-space coordinate?
(Same answer, though.)
Do you want to know the maximum extents on your screen in pixles?
If so, the simplest way to go is to call gluProject for all your vertices and store the maximum and minimum x and y positions.
Could look like this:
GLdouble modelview[16], projection[16]
GLint viewport[4];
glGetDoublev(GL_MODELVIEW_MATRIX, *modelView);
glGetDoublev(GL_PROJECTION_MATRIX, *projection);
glGetIntegerv(GL_VIEWPORT, *viewport);
double tx, ty, tz;
for(i = 0; i < VertexCount; i++)
{
glProject(vertices[i].x, vertices[i].y, vertices[i].z,
modelview, projection, viewport,
*tx, *ty, *tz);
// now, the 2d position of the ith Vertex is stored in tx, ty, tz.
// you can now use these values to determine the 2d-extends on your screen
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With