Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL point position after rendering (3d -> 2d)

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!

like image 753
MattheW Avatar asked Feb 25 '23 18:02

MattheW


2 Answers

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.)

like image 127
aib Avatar answered Mar 08 '23 10:03

aib


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

}
like image 35
sum1stolemyname Avatar answered Mar 08 '23 10:03

sum1stolemyname