简体   繁体   English

渲染后的OpenGL点位置(3d - > 2d)

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

I've got an OpenGL scene with some figures on it. 我有一个OpenGL场景,里面有一些数字。 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. 看看gluProject()函数。

Edit: Also found in the OpenGL FAQ : 编辑:也可以在OpenGL FAQ中找到:
9.100 How can I find the screen coordinates for a given object-space coordinate? 9.100如何找到给定对象空间坐标的屏幕坐标?
(Same answer, though.) (但答案相同。)

Do you want to know the maximum extents on your screen in pixles? 你想知道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. 如果是这样,最简单的方法是为所有顶点调用gluProject并存储最大和最小x和y位置。

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

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM