开发者

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

I've got an OpenGL scene with some figures on 开发者_如何学JAVAit. 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

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜